| Line 76... |
Line 76... |
| 76 |
self.ourSp = ourSp
|
76 |
self.ourSp = ourSp
|
| 77 |
self.secondLowestSellerTp = secondLowestSellerTp
|
77 |
self.secondLowestSellerTp = secondLowestSellerTp
|
| 78 |
self.lowestPossibleSp = lowestPossibleSp
|
78 |
self.lowestPossibleSp = lowestPossibleSp
|
| 79 |
|
79 |
|
| 80 |
def fetchItemsForAutoDecrease(time):
|
80 |
def fetchItemsForAutoDecrease(time):
|
| - |
|
81 |
autoDecrementItems = session.query(MarketPlaceHistory).join((MarketplaceItems,MarketPlaceHistory.item_id==MarketplaceItems.itemId))\
|
| - |
|
82 |
.filter(MarketPlaceHistory.timestamp==time).filter(MarketPlaceHistory.source==OrderSource.SNAPDEAL).filter(MarketPlaceHistory.competitiveCategory==CompetitionCategory.COMPETITIVE)\
|
| - |
|
83 |
.filter(MarketplaceItems.source==OrderSource.SNAPDEAL).filter(MarketplaceItems.autoDecrement==True).all()
|
| 81 |
autoDecrementItems = MarketplaceItems.query.filter(MarketplaceItems.autoDecrement==True).filter(MarketplaceItems.source==OrderSource.SNAPDEAL).all()
|
84 |
#autoDecrementItems = MarketplaceItems.query.filter(MarketplaceItems.autoDecrement==True).filter(MarketplaceItems.source==OrderSource.SNAPDEAL).all()
|
| 82 |
inventory_client = InventoryClient().get_client()
|
85 |
inventory_client = InventoryClient().get_client()
|
| 83 |
inventoryMap = inventory_client.getInventorySnapshot(0)
|
86 |
inventoryMap = inventory_client.getInventorySnapshot(0)
|
| 84 |
for autoDecrementItem in autoDecrementItems:
|
87 |
for autoDecrementItem in autoDecrementItems:
|
| 85 |
mpHistory = MarketPlaceHistory.get_by(source=OrderSource.SNAPDEAL,item_id=autoDecrementItem.itemId,timestamp=time)
|
88 |
#mpHistory = MarketPlaceHistory.get_by(source=OrderSource.SNAPDEAL,item_id=autoDecrementItem.itemId,timestamp=time)
|
| 86 |
if not mpHistory.competitiveCategory == CompetitionCategory.COMPETITIVE:
|
89 |
if not autoDecrementItem.competitiveCategory == CompetitionCategory.COMPETITIVE:
|
| 87 |
markReasonForMpItem(mpHistory,'Category is '+CompetitionCategory._VALUES_TO_NAMES.get(mpHistory.competitiveCategory),Decision.AUTO_DECREMENT_FAILED)
|
90 |
markReasonForMpItem(autoDecrementItem,'Category is '+CompetitionCategory._VALUES_TO_NAMES.get(autoDecrementItem.competitiveCategory),Decision.AUTO_DECREMENT_FAILED)
|
| 88 |
continue
|
91 |
continue
|
| 89 |
if not mpHistory.risky:
|
92 |
if not autoDecrementItem.risky:
|
| 90 |
markReasonForMpItem(mpHistory,'Item is not risky',Decision.AUTO_DECREMENT_FAILED)
|
93 |
markReasonForMpItem(autoDecrementItem,'Item is not risky',Decision.AUTO_DECREMENT_FAILED)
|
| 91 |
continue
|
94 |
continue
|
| 92 |
if mpHistory.proposedSellingPrice >= mpHistory.ourSellingPrice:
|
95 |
if autoDecrementItem.proposedSellingPrice >= autoDecrementItem.ourSellingPrice:
|
| 93 |
markReasonForMpItem(mpHistory,'Proposed SP greater than current SP',Decision.AUTO_DECREMENT_FAILED)
|
96 |
markReasonForMpItem(autoDecrementItem,'Proposed SP greater than current SP',Decision.AUTO_DECREMENT_FAILED)
|
| 94 |
continue
|
97 |
continue
|
| 95 |
if mpHistory.otherInventory < 3:
|
98 |
if autoDecrementItem.otherInventory < 3:
|
| 96 |
markReasonForMpItem(mpHistory,'Competition stock is not enough',Decision.AUTO_DECREMENT_FAILED)
|
99 |
markReasonForMpItem(autoDecrementItem,'Competition stock is not enough',Decision.AUTO_DECREMENT_FAILED)
|
| 97 |
continue
|
100 |
continue
|
| 98 |
oosStatus = inventory_client.getOosStatusesForXDaysForItem(autoDecrementItem.itemId,0,3)
|
101 |
oosStatus = inventory_client.getOosStatusesForXDaysForItem(autoDecrementItem.item_id,0,3)
|
| 99 |
count,sale,daysOfStock = 0,0,0
|
102 |
count,sale,daysOfStock = 0,0,0
|
| 100 |
for obj in oosStatus:
|
103 |
for obj in oosStatus:
|
| 101 |
if not obj.is_oos:
|
104 |
if not obj.is_oos:
|
| 102 |
count+=1
|
105 |
count+=1
|
| 103 |
sale = sale+obj.num_orders
|
106 |
sale = sale+obj.num_orders
|
| 104 |
avgSalePerDay=0 if count==0 else (float(sale)/count)
|
107 |
avgSalePerDay=0 if count==0 else (float(sale)/count)
|
| 105 |
totalAvailability, totalReserved = 0,0
|
108 |
totalAvailability, totalReserved = 0,0
|
| 106 |
if (not inventoryMap.has_key(autoDecrementItem.itemId)):
|
109 |
if (not inventoryMap.has_key(autoDecrementItem.item_id)):
|
| 107 |
markReasonForMpItem(mpHistory,'Average sale per day is zero',Decision.AUTO_DECREMENT_FAILED)
|
110 |
markReasonForMpItem(autoDecrementItem,'Average sale per day is zero',Decision.AUTO_DECREMENT_FAILED)
|
| 108 |
continue
|
111 |
continue
|
| 109 |
itemInventory=inventoryMap[autoDecrementItem.itemId]
|
112 |
itemInventory=inventoryMap[autoDecrementItem.item_id]
|
| 110 |
availableMap = itemInventory.availability
|
113 |
availableMap = itemInventory.availability
|
| 111 |
reserveMap = itemInventory.reserved
|
114 |
reserveMap = itemInventory.reserved
|
| 112 |
for warehouse,availability in availableMap.iteritems():
|
115 |
for warehouse,availability in availableMap.iteritems():
|
| 113 |
if warehouse==16:
|
116 |
if warehouse==16:
|
| 114 |
continue
|
117 |
continue
|
| Line 116... |
Line 119... |
| 116 |
for warehouse,reserve in reserveMap.iteritems():
|
119 |
for warehouse,reserve in reserveMap.iteritems():
|
| 117 |
if warehouse==16:
|
120 |
if warehouse==16:
|
| 118 |
continue
|
121 |
continue
|
| 119 |
totalReserved = totalReserved+reserve
|
122 |
totalReserved = totalReserved+reserve
|
| 120 |
if (totalAvailability-totalReserved)<=0:
|
123 |
if (totalAvailability-totalReserved)<=0:
|
| 121 |
markReasonForMpItem(mpHistory,'Our stock is not enough',Decision.AUTO_DECREMENT_FAILED)
|
124 |
markReasonForMpItem(autoDecrementItem,'Our stock is not enough',Decision.AUTO_DECREMENT_FAILED)
|
| 122 |
continue
|
125 |
continue
|
| 123 |
if (avgSalePerDay==0):
|
126 |
if (avgSalePerDay==0):
|
| 124 |
markReasonForMpItem(mpHistory,'Average sale per day is zero',Decision.AUTO_DECREMENT_FAILED)
|
127 |
markReasonForMpItem(autoDecrementItem,'Average sale per day is zero',Decision.AUTO_DECREMENT_FAILED)
|
| 125 |
continue
|
128 |
continue
|
| 126 |
daysOfStock = (float(totalAvailability-totalReserved))/avgSalePerDay
|
129 |
daysOfStock = (float(totalAvailability-totalReserved))/avgSalePerDay
|
| 127 |
if daysOfStock<2:
|
130 |
if daysOfStock<2:
|
| 128 |
markReasonForMpItem(mpHistory,'Our stock is not enough',Decision.AUTO_DECREMENT_FAILED)
|
131 |
markReasonForMpItem(autoDecrementItem,'Our stock is not enough',Decision.AUTO_DECREMENT_FAILED)
|
| 129 |
continue
|
132 |
continue
|
| 130 |
|
133 |
|
| 131 |
mpHistory.competitorEnoughStock = True
|
134 |
autoDecrementItem.competitorEnoughStock = True
|
| 132 |
mpHistory.ourEnoughStock = True
|
135 |
autoDecrementItem.ourEnoughStock = True
|
| 133 |
mpHistory.avgSales = avgSalePerDay
|
136 |
autoDecrementItem.avgSales = avgSalePerDay
|
| 134 |
mpHistory.decision = Decision.AUTO_DECREMENT_SUCCESS
|
137 |
autoDecrementItem.decision = Decision.AUTO_DECREMENT_SUCCESS
|
| 135 |
mpHistory.reason = 'All conditions for auto decrement true'
|
138 |
autoDecrementItem.reason = 'All conditions for auto decrement true'
|
| 136 |
lgr.info("Auto decrement success for itemId "+str(autoDecrementItem.itemId)+" Days of stock "+str(daysOfStock)+" avg sales "+str(avgSalePerDay))
|
139 |
lgr.info("Auto decrement success for itemId "+str(autoDecrementItem.item_id)+" Days of stock "+str(daysOfStock)+" avg sales "+str(avgSalePerDay))
|
| 137 |
session.commit()
|
140 |
session.commit()
|
| 138 |
|
141 |
|
| 139 |
def fetchItemsForAutoIncrease(time):
|
142 |
def fetchItemsForAutoIncrease(time):
|
| - |
|
143 |
autoIncrementItems = session.query(MarketPlaceHistory).join((MarketplaceItems,MarketPlaceHistory.item_id==MarketplaceItems.itemId))\
|
| - |
|
144 |
.filter(MarketPlaceHistory.timestamp==time).filter(MarketPlaceHistory.source==OrderSource.SNAPDEAL).filter(MarketPlaceHistory.competitiveCategory==CompetitionCategory.BUY_BOX)\
|
| - |
|
145 |
.filter(MarketplaceItems.source==OrderSource.SNAPDEAL).filter(MarketplaceItems.autoIncrement==True).all()
|
| 140 |
autoIncrementItems = MarketplaceItems.query.filter(MarketplaceItems.autoIncrement==True).filter(MarketplaceItems.source==OrderSource.SNAPDEAL).all()
|
146 |
#autoIncrementItems = MarketplaceItems.query.filter(MarketplaceItems.autoIncrement==True).filter(MarketplaceItems.source==OrderSource.SNAPDEAL).all()
|
| 141 |
inventory_client = InventoryClient().get_client()
|
147 |
inventory_client = InventoryClient().get_client()
|
| 142 |
inventoryMap = inventory_client.getInventorySnapshot(0)
|
148 |
inventoryMap = inventory_client.getInventorySnapshot(0)
|
| 143 |
for autoIncrementItem in autoIncrementItems:
|
149 |
for autoIncrementItem in autoIncrementItems:
|
| 144 |
mpHistory = MarketPlaceHistory.get_by(source=OrderSource.SNAPDEAL,item_id=autoIncrementItem.itemId,timestamp=time)
|
150 |
#mpHistory = MarketPlaceHistory.get_by(source=OrderSource.SNAPDEAL,item_id=autoIncrementItem.itemId,timestamp=time)
|
| 145 |
if not mpHistory.competitiveCategory == CompetitionCategory.BUY_BOX:
|
151 |
if not autoIncrementItem.competitiveCategory == CompetitionCategory.BUY_BOX:
|
| 146 |
markReasonForMpItem(mpHistory,'Category is '+CompetitionCategory._VALUES_TO_NAMES.get(mpHistory.competitiveCategory),Decision.AUTO_DECREMENT_FAILED)
|
152 |
markReasonForMpItem(autoIncrementItem,'Category is '+CompetitionCategory._VALUES_TO_NAMES.get(autoIncrementItem.competitiveCategory),Decision.AUTO_INCREMENT_FAILED)
|
| 147 |
continue
|
153 |
continue
|
| 148 |
if mpHistory.totalSeller==1 and mpHistory.ourRank==1:
|
154 |
if autoIncrementItem.totalSeller==1 and autoIncrementItem.ourRank==1:
|
| 149 |
markReasonForMpItem(mpHistory,'We are the only seller',Decision.AUTO_INCREMENT_FAILED)
|
155 |
markReasonForMpItem(autoIncrementItem,'We are the only seller',Decision.AUTO_INCREMENT_FAILED)
|
| 150 |
continue
|
156 |
continue
|
| 151 |
if mpHistory.proposedSellingPrice <= mpHistory.ourSellingPrice:
|
157 |
if autoIncrementItem.proposedSellingPrice <= autoIncrementItem.ourSellingPrice:
|
| 152 |
markReasonForMpItem(mpHistory,'Proposed SP less than current SP',Decision.AUTO_INCREMENT_FAILED)
|
158 |
markReasonForMpItem(autoIncrementItem,'Proposed SP less than current SP',Decision.AUTO_INCREMENT_FAILED)
|
| 153 |
continue
|
159 |
continue
|
| 154 |
oosStatus = inventory_client.getOosStatusesForXDaysForItem(autoIncrementItem.itemId,0,3)
|
160 |
oosStatus = inventory_client.getOosStatusesForXDaysForItem(autoIncrementItem.item_id,0,3)
|
| 155 |
count,sale,daysOfStock = 0,0,0
|
161 |
count,sale,daysOfStock = 0,0,0
|
| 156 |
for obj in oosStatus:
|
162 |
for obj in oosStatus:
|
| 157 |
if not obj.is_oos:
|
163 |
if not obj.is_oos:
|
| 158 |
count+=1
|
164 |
count+=1
|
| 159 |
sale = sale+obj.num_orders
|
165 |
sale = sale+obj.num_orders
|
| 160 |
avgSalePerDay=0 if count==0 else (float(sale)/count)
|
166 |
avgSalePerDay=0 if count==0 else (float(sale)/count)
|
| 161 |
totalAvailability, totalReserved = 0,0
|
167 |
totalAvailability, totalReserved = 0,0
|
| 162 |
if (not inventoryMap.has_key(autoIncrementItem.itemId)):
|
168 |
if (not inventoryMap.has_key(autoIncrementItem.item_id)):
|
| 163 |
markReasonForMpItem(mpHistory,'Average sale per day is zero',Decision.AUTO_INCREMENT_FAILED)
|
169 |
markReasonForMpItem(autoIncrementItem,'Average sale per day is zero',Decision.AUTO_INCREMENT_FAILED)
|
| 164 |
continue
|
170 |
continue
|
| 165 |
itemInventory=inventoryMap[autoIncrementItem.itemId]
|
171 |
itemInventory=inventoryMap[autoIncrementItem.item_id]
|
| 166 |
availableMap = itemInventory.availability
|
172 |
availableMap = itemInventory.availability
|
| 167 |
reserveMap = itemInventory.reserved
|
173 |
reserveMap = itemInventory.reserved
|
| 168 |
for warehouse,availability in availableMap.iteritems():
|
174 |
for warehouse,availability in availableMap.iteritems():
|
| 169 |
if warehouse==16:
|
175 |
if warehouse==16:
|
| 170 |
continue
|
176 |
continue
|
| Line 172... |
Line 178... |
| 172 |
for warehouse,reserve in reserveMap.iteritems():
|
178 |
for warehouse,reserve in reserveMap.iteritems():
|
| 173 |
if warehouse==16:
|
179 |
if warehouse==16:
|
| 174 |
continue
|
180 |
continue
|
| 175 |
totalReserved = totalReserved+reserve
|
181 |
totalReserved = totalReserved+reserve
|
| 176 |
if (totalAvailability-totalReserved)<=0:
|
182 |
if (totalAvailability-totalReserved)<=0:
|
| 177 |
markReasonForMpItem(mpHistory,'Our stock is 0',Decision.AUTO_INCREMENT_FAILED)
|
183 |
markReasonForMpItem(autoIncrementItem,'Our stock is 0',Decision.AUTO_INCREMENT_FAILED)
|
| 178 |
continue
|
184 |
continue
|
| 179 |
if (avgSalePerDay==0):
|
185 |
if (avgSalePerDay==0):
|
| 180 |
markReasonForMpItem(mpHistory,'Average sale per day is zero',Decision.AUTO_INCREMENT_FAILED)
|
186 |
markReasonForMpItem(autoIncrementItem,'Average sale per day is zero',Decision.AUTO_INCREMENT_FAILED)
|
| 181 |
continue
|
187 |
continue
|
| 182 |
daysOfStock = (float(totalAvailability-totalReserved))/avgSalePerDay
|
188 |
daysOfStock = (float(totalAvailability-totalReserved))/avgSalePerDay
|
| 183 |
if daysOfStock>5:
|
189 |
if daysOfStock>5:
|
| 184 |
markReasonForMpItem(mpHistory,'Our stock is enough',Decision.AUTO_INCREMENT_FAILED)
|
190 |
markReasonForMpItem(autoIncrementItem,'Our stock is enough',Decision.AUTO_INCREMENT_FAILED)
|
| 185 |
continue
|
191 |
continue
|
| 186 |
|
192 |
|
| 187 |
mpHistory.ourEnoughStock = False
|
193 |
autoIncrementItem.ourEnoughStock = False
|
| 188 |
mpHistory.avgSales = avgSalePerDay
|
194 |
autoIncrementItem.avgSales = avgSalePerDay
|
| 189 |
mpHistory.decision = Decision.AUTO_INCREMENT_SUCCESS
|
195 |
autoIncrementItem.decision = Decision.AUTO_INCREMENT_SUCCESS
|
| 190 |
mpHistory.reason = 'All conditions for auto increment true'
|
196 |
autoIncrementItem.reason = 'All conditions for auto increment true'
|
| 191 |
lgr.info("Auto increment success for itemId "+str(autoIncrementItem.itemId)+" Days of stock "+str(daysOfStock)+" avg sales "+str(avgSalePerDay))
|
197 |
lgr.info("Auto increment success for itemId "+str(autoIncrementItem.item_id)+" Days of stock "+str(daysOfStock)+" avg sales "+str(avgSalePerDay))
|
| 192 |
session.commit()
|
198 |
session.commit()
|
| 193 |
|
199 |
|
| 194 |
|
200 |
|
| 195 |
def markReasonForMpItem(mpHistory,reason,decision):
|
201 |
def markReasonForMpItem(mpHistory,reason,decision):
|
| 196 |
mpHistory.decision = decision
|
202 |
mpHistory.decision = decision
|