| Line 33... |
Line 33... |
| 33 |
import threading
|
33 |
import threading
|
| 34 |
import urllib2
|
34 |
import urllib2
|
| 35 |
import math
|
35 |
import math
|
| 36 |
|
36 |
|
| 37 |
sourceId = int(ConfigClient().get_property("sourceid"))
|
37 |
sourceId = int(ConfigClient().get_property("sourceid"))
|
| 38 |
to_addresses = ["khushal.bhatia@shop2020.in", "chandan.kumar@shop2020.in", "chaitnaya.vats@shop2020.in"]
|
38 |
to_addresses = ["kshitij.sood@shop2020.in"]
|
| 39 |
to_store_addresses = ["rajveer.singh@shop2020.in"]
|
39 |
to_store_addresses = ["kshitij.sood@shop2020.in"]
|
| 40 |
mail_user = "cnc.center@shop2020.in"
|
40 |
mail_user = "cnc.center@shop2020.in"
|
| 41 |
mail_password = "5h0p2o2o"
|
41 |
mail_password = "5h0p2o2o"
|
| 42 |
source_name = "Saholic"
|
42 |
source_name = "Saholic"
|
| 43 |
source_url = "www.saholic.com"
|
43 |
source_url = "www.saholic.com"
|
| 44 |
skippedItems = { 175 : [27, 2160, 2175, 2163, 2158, 7128, 26, 2154],
|
44 |
skippedItems = { 175 : [27, 2160, 2175, 2163, 2158, 7128, 26, 2154],
|
| 45 |
193 : [5839] }
|
45 |
193 : [5839] }
|
| 46 |
|
46 |
|
| 47 |
def initialize(dbname='catalog', db_hostname="localhost"):
|
47 |
def initialize(dbname='catalog', db_hostname="localhost"):
|
| 48 |
DataService.initialize(dbname, db_hostname)
|
48 |
DataService.initialize(dbname, db_hostname)
|
| 49 |
|
49 |
|
| 50 |
def get_all_items_by_status(status, offset=0, limit=None):
|
50 |
def get_all_items_by_status(status, offset=0, limit=None):
|
| 51 |
query = Item.query
|
51 |
query = Item.query
|
| 52 |
if status is not None:
|
52 |
if status is not None:
|
| 53 |
query = query.filter_by(status=status)
|
53 |
query = query.filter_by(status=status)
|
| 54 |
query = query.order_by(Item.product_group, Item.brand, Item.model_number, Item.model_name).offset(offset)
|
54 |
query = query.order_by(Item.product_group, Item.brand, Item.model_number, Item.model_name).offset(offset)
|
| Line 147... |
Line 147... |
| 147 |
return item.status_description
|
147 |
return item.status_description
|
| 148 |
|
148 |
|
| 149 |
def update_item(item):
|
149 |
def update_item(item):
|
| 150 |
if not item:
|
150 |
if not item:
|
| 151 |
raise InventoryServiceException(108, "Bad item in request")
|
151 |
raise InventoryServiceException(108, "Bad item in request")
|
| 152 |
|
152 |
|
| 153 |
if not item.id:
|
153 |
if not item.id:
|
| 154 |
raise InventoryServiceException(101, "Missing id for update")
|
154 |
raise InventoryServiceException(101, "Missing id for update")
|
| 155 |
|
155 |
|
| 156 |
validate_item_prices(item)
|
156 |
validate_item_prices(item)
|
| 157 |
|
157 |
|
| 158 |
ds_item = get_item(item.id)
|
158 |
ds_item = get_item(item.id)
|
| 159 |
message = ""
|
159 |
message = ""
|
| 160 |
store_message = ""
|
160 |
store_message = ""
|
| 161 |
if not ds_item:
|
161 |
if not ds_item:
|
| 162 |
raise InventoryServiceException(101, "Item missing in our database")
|
162 |
raise InventoryServiceException(101, "Item missing in our database")
|
| 163 |
|
163 |
|
| 164 |
if item.productGroup:
|
164 |
if item.productGroup:
|
| 165 |
ds_item.product_group = item.productGroup
|
165 |
ds_item.product_group = item.productGroup
|
| 166 |
if item.brand:
|
166 |
if item.brand:
|
| 167 |
ds_item.brand = item.brand
|
167 |
ds_item.brand = item.brand
|
| 168 |
if item.modelNumber:
|
168 |
if item.modelNumber:
|
| 169 |
ds_item.model_number = item.modelNumber
|
169 |
ds_item.model_number = item.modelNumber
|
| 170 |
ds_item.color = item.color
|
170 |
ds_item.color = item.color
|
| 171 |
ds_item.model_name = item.modelName
|
171 |
ds_item.model_name = item.modelName
|
| 172 |
ds_item.category = item.category
|
172 |
ds_item.category = item.category
|
| 173 |
if item.category in [10001, 10002, 10003, 10004, 10005]:
|
173 |
if item.category in [10001, 10002, 10003, 10004, 10005]:
|
| 174 |
ds_item.preferredInsurer = 1
|
174 |
ds_item.preferredInsurer = 1
|
| 175 |
|
175 |
|
| 176 |
ds_item.comments = item.comments
|
176 |
ds_item.comments = item.comments
|
| 177 |
|
177 |
|
| 178 |
ds_item.catalog_item_id = item.catalogItemId
|
178 |
ds_item.catalog_item_id = item.catalogItemId
|
| 179 |
|
179 |
|
| 180 |
if ds_item.activeOnStore and ds_item.mrp and item.mrp and ds_item.mrp != item.mrp:
|
180 |
if ds_item.activeOnStore and ds_item.mrp and item.mrp and ds_item.mrp != item.mrp:
|
| 181 |
sp = get_store_pricing(item.id)
|
181 |
sp = get_store_pricing(item.id)
|
| 182 |
if sp.maxPrice > item.mrp:
|
182 |
if sp.maxPrice > item.mrp:
|
| 183 |
sp.maxPrice = item.mrp
|
183 |
sp.maxPrice = item.mrp
|
| 184 |
store_message += "MRP is changed from {0} to {1}.\n".format(sp.maxPrice, item.mrp)
|
184 |
store_message += "MRP is changed from {0} to {1}.\n".format(sp.maxPrice, item.mrp)
|
| 185 |
|
185 |
|
| 186 |
|
186 |
|
| 187 |
if ds_item.activeOnStore and ds_item.sellingPrice and item.sellingPrice and ds_item.sellingPrice != item.sellingPrice:
|
187 |
if ds_item.activeOnStore and ds_item.sellingPrice and item.sellingPrice and ds_item.sellingPrice != item.sellingPrice:
|
| 188 |
sp = get_store_pricing(item.id)
|
188 |
sp = get_store_pricing(item.id)
|
| 189 |
if sp.minPrice < item.sellingPrice:
|
189 |
if sp.minPrice < item.sellingPrice:
|
| 190 |
store_message += "Saholic MOP Changed. DP {0} is less than Saholic MOP.\n".format(sp.minPrice)
|
190 |
store_message += "Saholic MOP Changed. DP {0} is less than Saholic MOP.\n".format(sp.minPrice)
|
| 191 |
|
191 |
|
| 192 |
ds_item.mrp = item.mrp
|
192 |
ds_item.mrp = item.mrp
|
| 193 |
if ds_item.sellingPrice or item.sellingPrice:
|
193 |
if ds_item.sellingPrice or item.sellingPrice:
|
| 194 |
if ds_item.sellingPrice != item.sellingPrice:
|
194 |
if ds_item.sellingPrice != item.sellingPrice:
|
| 195 |
amazonItem = get_amazon_item_details(item.id)
|
195 |
amazonItem = get_amazon_item_details(item.id)
|
| 196 |
if amazonItem is not None:
|
196 |
if amazonItem is not None:
|
| 197 |
amazonItem.fbaPrice = item.sellingPrice
|
197 |
amazonItem.fbaPrice = item.sellingPrice
|
| 198 |
amazonItem.sellingPrice=item.sellingPrice
|
198 |
amazonItem.sellingPrice=item.sellingPrice
|
| - |
|
199 |
amazonItem.mfnPriceLastUpdatedOn = datetime.datetime.now()
|
| - |
|
200 |
amazonItem.fbaPriceLastUpdatedOn = datetime.datetime.now()
|
| 199 |
message += "Selling Price is changed from {0} to {1}.\n".format(ds_item.sellingPrice, item.sellingPrice)
|
201 |
message += "Selling Price is changed from {0} to {1}.\n".format(ds_item.sellingPrice, item.sellingPrice)
|
| 200 |
|
202 |
|
| 201 |
ds_item.sellingPrice = item.sellingPrice
|
203 |
ds_item.sellingPrice = item.sellingPrice
|
| - |
|
204 |
item_temp = get_item(item.id)
|
| - |
|
205 |
print "temp",item_temp.sellingPrice
|
| - |
|
206 |
print "object",item.sellingPrice
|
| - |
|
207 |
if (item_temp.sellingPrice != item.sellingPrice):
|
| - |
|
208 |
amazonItem = get_amazon_item_details(item.id)
|
| - |
|
209 |
if amazonItem is not None:
|
| - |
|
210 |
amazonItem.fbaPrice = item.sellingPrice
|
| - |
|
211 |
amazonItem.sellingPrice=item.sellingPrice
|
| - |
|
212 |
amazonItem.mfnPriceLastUpdatedOn = datetime.datetime.now()
|
| - |
|
213 |
amazonItem.fbaPriceLastUpdatedOn = datetime.datetime.now()
|
| 202 |
|
214 |
|
| 203 |
ds_item.weight = item.weight
|
215 |
ds_item.weight = item.weight
|
| 204 |
ds_item.showSellingPrice = item.showSellingPrice
|
216 |
ds_item.showSellingPrice = item.showSellingPrice
|
| 205 |
|
217 |
|
| 206 |
if item.asin:
|
218 |
if item.asin:
|
| 207 |
ds_item.asin = item.asin
|
219 |
ds_item.asin = item.asin
|
| 208 |
ds_item.holdInventory = item.holdInventory
|
220 |
ds_item.holdInventory = item.holdInventory
|
| 209 |
ds_item.defaultInventory = item.defaultInventory
|
221 |
ds_item.defaultInventory = item.defaultInventory
|
| 210 |
|
222 |
|
| 211 |
if item.startDate:
|
223 |
if item.startDate:
|
| 212 |
ds_item.startDate = to_py_date(item.startDate)
|
224 |
ds_item.startDate = to_py_date(item.startDate)
|
| 213 |
ds_item.startDate = ds_item.startDate.replace(hour=0,second=0,minute=0)
|
225 |
ds_item.startDate = ds_item.startDate.replace(hour=0,second=0,minute=0)
|
| 214 |
if item.itemStatus == status.COMING_SOON and ds_item.startDate < datetime.datetime.now() :
|
226 |
if item.itemStatus == status.COMING_SOON and ds_item.startDate < datetime.datetime.now() :
|
| 215 |
item.itemStatus = status.ACTIVE
|
227 |
item.itemStatus = status.ACTIVE
|
| Line 222... |
Line 234... |
| 222 |
if item.itemStatus == status.PHASED_OUT:
|
234 |
if item.itemStatus == status.PHASED_OUT:
|
| 223 |
message += "Item is phased out."
|
235 |
message += "Item is phased out."
|
| 224 |
ds_item.status = item.itemStatus
|
236 |
ds_item.status = item.itemStatus
|
| 225 |
if item.status_description:
|
237 |
if item.status_description:
|
| 226 |
ds_item.status_description = item.status_description
|
238 |
ds_item.status_description = item.status_description
|
| 227 |
|
239 |
|
| 228 |
if item.retireDate:
|
240 |
if item.retireDate:
|
| 229 |
ds_item.retireDate = to_py_date(item.retireDate)
|
241 |
ds_item.retireDate = to_py_date(item.retireDate)
|
| 230 |
else:
|
242 |
else:
|
| 231 |
ds_item.retireDate = None
|
243 |
ds_item.retireDate = None
|
| 232 |
|
244 |
|
| 233 |
if item.expectedArrivalDate:
|
245 |
if item.expectedArrivalDate:
|
| 234 |
ds_item.expectedArrivalDate = to_py_date(item.expectedArrivalDate)
|
246 |
ds_item.expectedArrivalDate = to_py_date(item.expectedArrivalDate)
|
| 235 |
else:
|
247 |
else:
|
| 236 |
ds_item.expectedArrivalDate = None
|
248 |
ds_item.expectedArrivalDate = None
|
| 237 |
|
249 |
|
| 238 |
if item.comingSoonStartDate:
|
250 |
if item.comingSoonStartDate:
|
| 239 |
ds_item.comingSoonStartDate = to_py_date(item.comingSoonStartDate)
|
251 |
ds_item.comingSoonStartDate = to_py_date(item.comingSoonStartDate)
|
| 240 |
ds_item.comingSoonStartDate = ds_item.comingSoonStartDate.replace(hour=0,second=0,minute=0)
|
252 |
ds_item.comingSoonStartDate = ds_item.comingSoonStartDate.replace(hour=0,second=0,minute=0)
|
| 241 |
else:
|
253 |
else:
|
| 242 |
ds_item.comingSoonStartDate = None
|
254 |
ds_item.comingSoonStartDate = None
|
| 243 |
|
255 |
|
| 244 |
|
256 |
|
| 245 |
ds_item.feature_id = item.featureId
|
257 |
ds_item.feature_id = item.featureId
|
| 246 |
ds_item.feature_description = item.featureDescription
|
258 |
ds_item.feature_description = item.featureDescription
|
| 247 |
|
259 |
|
| 248 |
if ds_item.bestDealText or item.bestDealText:
|
260 |
if ds_item.bestDealText or item.bestDealText:
|
| 249 |
if item.bestDealText != ds_item.bestDealText:
|
261 |
if item.bestDealText != ds_item.bestDealText:
|
| 250 |
message += "Promotion text is changed from '{0}' to '{1}'.\n".format(ds_item.bestDealText, item.bestDealText)
|
262 |
message += "Promotion text is changed from '{0}' to '{1}'.\n".format(ds_item.bestDealText, item.bestDealText)
|
| 251 |
ds_item.bestDealText = item.bestDealText
|
263 |
ds_item.bestDealText = item.bestDealText
|
| 252 |
ds_item.bestDealValue = item.bestDealValue
|
264 |
ds_item.bestDealValue = item.bestDealValue
|
| 253 |
ds_item.bestSellingRank = item.bestSellingRank
|
265 |
ds_item.bestSellingRank = item.bestSellingRank
|
| 254 |
|
266 |
|
| 255 |
if ds_item.bestDealsDetailsText or item.bestDealsDetailsText:
|
267 |
if ds_item.bestDealsDetailsText or item.bestDealsDetailsText:
|
| 256 |
if item.bestDealsDetailsText != ds_item.bestDealsDetailsText:
|
268 |
if item.bestDealsDetailsText != ds_item.bestDealsDetailsText:
|
| 257 |
message += "Best deals details text is changed from '{0}' to '{1}'.\n".format(ds_item.bestDealsDetailsText, item.bestDealsDetailsText)
|
269 |
message += "Best deals details text is changed from '{0}' to '{1}'.\n".format(ds_item.bestDealsDetailsText, item.bestDealsDetailsText)
|
| 258 |
ds_item.bestDealsDetailsText = item.bestDealsDetailsText
|
270 |
ds_item.bestDealsDetailsText = item.bestDealsDetailsText
|
| 259 |
|
271 |
|
| 260 |
if ds_item.bestDealsDetailsLink or item.bestDealsDetailsLink:
|
272 |
if ds_item.bestDealsDetailsLink or item.bestDealsDetailsLink:
|
| 261 |
if item.bestDealsDetailsLink != ds_item.bestDealsDetailsLink:
|
273 |
if item.bestDealsDetailsLink != ds_item.bestDealsDetailsLink:
|
| 262 |
message += "Best deals details link is changed from '{0}' to '{1}'.\n".format(ds_item.bestDealsDetailsLink, item.bestDealsDetailsLink)
|
274 |
message += "Best deals details link is changed from '{0}' to '{1}'.\n".format(ds_item.bestDealsDetailsLink, item.bestDealsDetailsLink)
|
| 263 |
ds_item.bestDealsDetailsLink = item.bestDealsDetailsLink
|
275 |
ds_item.bestDealsDetailsLink = item.bestDealsDetailsLink
|
| 264 |
|
276 |
|
| 265 |
|
277 |
|
| 266 |
ds_item.defaultForEntity = item.defaultForEntity
|
278 |
ds_item.defaultForEntity = item.defaultForEntity
|
| 267 |
|
279 |
|
| 268 |
if ds_item.risky or item.risky:
|
280 |
if ds_item.risky or item.risky:
|
| 269 |
if ds_item.risky != item.risky:
|
281 |
if ds_item.risky != item.risky:
|
| 270 |
message += "Risky flag is changed to '{0}'.\n".format(set)
|
282 |
message += "Risky flag is changed to '{0}'.\n".format(set)
|
| 271 |
|
283 |
|
| 272 |
ds_item.risky = item.risky
|
284 |
ds_item.risky = item.risky
|
| 273 |
|
285 |
|
| 274 |
ds_item.type = ItemType._VALUES_TO_NAMES[item.type]
|
286 |
ds_item.type = ItemType._VALUES_TO_NAMES[item.type]
|
| 275 |
ds_item.hasItemNo = item.hasItemNo
|
287 |
ds_item.hasItemNo = item.hasItemNo
|
| 276 |
|
288 |
|
| 277 |
if item.expectedDelay is not None:
|
289 |
if item.expectedDelay is not None:
|
| 278 |
ds_item.expectedDelay = item.expectedDelay
|
290 |
ds_item.expectedDelay = item.expectedDelay
|
| 279 |
|
291 |
|
| 280 |
if item.preferredVendor:
|
292 |
if item.preferredVendor:
|
| 281 |
if item.preferredVendor != ds_item.preferredVendor:
|
293 |
if item.preferredVendor != ds_item.preferredVendor:
|
| 282 |
inventoryClient = InventoryClient().get_client()
|
294 |
inventoryClient = InventoryClient().get_client()
|
| 283 |
newPreferredVendorName = inventoryClient.getVendor(item.preferredVendor).name
|
295 |
newPreferredVendorName = inventoryClient.getVendor(item.preferredVendor).name
|
| 284 |
oldPreferredVendorName = 'None'
|
296 |
oldPreferredVendorName = 'None'
|
| 285 |
if ds_item.preferredVendor:
|
297 |
if ds_item.preferredVendor:
|
| 286 |
oldPreferredVendorName = inventoryClient.getVendor(ds_item.preferredVendor).name
|
298 |
oldPreferredVendorName = inventoryClient.getVendor(ds_item.preferredVendor).name
|
| 287 |
message += "Preferred vendor is changed from '{0}' to '{1}'.\n".format(oldPreferredVendorName, newPreferredVendorName)
|
299 |
message += "Preferred vendor is changed from '{0}' to '{1}'.\n".format(oldPreferredVendorName, newPreferredVendorName)
|
| 288 |
ds_item.preferredVendor = item.preferredVendor
|
300 |
ds_item.preferredVendor = item.preferredVendor
|
| 289 |
|
301 |
|
| 290 |
if item.isWarehousePreferenceSticky != ds_item.isWarehousePreferenceSticky:
|
302 |
if item.isWarehousePreferenceSticky != ds_item.isWarehousePreferenceSticky:
|
| 291 |
flag = "ON" if item.isWarehousePreferenceSticky else "OFF"
|
303 |
flag = "ON" if item.isWarehousePreferenceSticky else "OFF"
|
| 292 |
message += "Warehouse preference sticky is {0}.\n".format(flag)
|
304 |
message += "Warehouse preference sticky is {0}.\n".format(flag)
|
| 293 |
|
305 |
|
| 294 |
ds_item.isWarehousePreferenceSticky = item.isWarehousePreferenceSticky
|
306 |
ds_item.isWarehousePreferenceSticky = item.isWarehousePreferenceSticky
|
| 295 |
|
307 |
|
| 296 |
ds_item.updatedOn = datetime.datetime.now()
|
308 |
ds_item.updatedOn = datetime.datetime.now()
|
| 297 |
|
309 |
|
| 298 |
|
310 |
|
| 299 |
ds_item.activeOnStore = item.activeOnStore
|
311 |
ds_item.activeOnStore = item.activeOnStore
|
| 300 |
|
312 |
|
| 301 |
|
313 |
|
| 302 |
session.commit();
|
314 |
session.commit();
|
| 303 |
subject = "Item '{0}' is updated in Catalog. Id is {1}".format(__get_product_name(ds_item),ds_item.id)
|
315 |
subject = "Item '{0}' is updated in Catalog. Id is {1}".format(__get_product_name(ds_item),ds_item.id)
|
| 304 |
if message:
|
316 |
if message:
|
| 305 |
__send_mail(subject, message)
|
317 |
__send_mail(subject, message)
|
| 306 |
if store_message:
|
318 |
if store_message:
|
| Line 310... |
Line 322... |
| 310 |
def add_item(item):
|
322 |
def add_item(item):
|
| 311 |
if not item:
|
323 |
if not item:
|
| 312 |
raise InventoryServiceException(108, "Bad item in request")
|
324 |
raise InventoryServiceException(108, "Bad item in request")
|
| 313 |
if get_item(item.id):
|
325 |
if get_item(item.id):
|
| 314 |
raise InventoryServiceException(101, "Item already exists")
|
326 |
raise InventoryServiceException(101, "Item already exists")
|
| 315 |
|
327 |
|
| 316 |
validate_item_prices(item)
|
328 |
validate_item_prices(item)
|
| 317 |
|
329 |
|
| 318 |
ds_item = Item()
|
330 |
ds_item = Item()
|
| 319 |
if item.productGroup:
|
331 |
if item.productGroup:
|
| 320 |
ds_item.product_group = item.productGroup
|
332 |
ds_item.product_group = item.productGroup
|
| 321 |
if item.brand:
|
333 |
if item.brand:
|
| 322 |
ds_item.brand = item.brand
|
334 |
ds_item.brand = item.brand
|
| Line 331... |
Line 343... |
| 331 |
if item.comments:
|
343 |
if item.comments:
|
| 332 |
ds_item.comments = item.comments
|
344 |
ds_item.comments = item.comments
|
| 333 |
if item.asin:
|
345 |
if item.asin:
|
| 334 |
ds_item.asin = item.asin
|
346 |
ds_item.asin = item.asin
|
| 335 |
ds_item.holdInventory = item.holdInventory
|
347 |
ds_item.holdInventory = item.holdInventory
|
| 336 |
ds_item.defaultInventory = item.defaultInventory
|
348 |
ds_item.defaultInventory = item.defaultInventory
|
| 337 |
ds_item.addedOn = datetime.datetime.now()
|
349 |
ds_item.addedOn = datetime.datetime.now()
|
| 338 |
ds_item.updatedOn = datetime.datetime.now()
|
350 |
ds_item.updatedOn = datetime.datetime.now()
|
| 339 |
if item.startDate:
|
351 |
if item.startDate:
|
| 340 |
ds_item.startDate = to_py_date(item.startDate)
|
352 |
ds_item.startDate = to_py_date(item.startDate)
|
| 341 |
ds_item.startDate = ds_item.startDate.replace(hour=0,second=0,minute=0)
|
353 |
ds_item.startDate = ds_item.startDate.replace(hour=0,second=0,minute=0)
|
| 342 |
if item.retireDate:
|
354 |
if item.retireDate:
|
| 343 |
ds_item.retireDate = to_py_date(item.retireDate)
|
355 |
ds_item.retireDate = to_py_date(item.retireDate)
|
| 344 |
if item.comingSoonStartDate:
|
356 |
if item.comingSoonStartDate:
|
| 345 |
ds_item.comingSoonStartDate = to_py_date(item.comingSoonStartDate)
|
357 |
ds_item.comingSoonStartDate = to_py_date(item.comingSoonStartDate)
|
| 346 |
if item.expectedArrivalDate:
|
358 |
if item.expectedArrivalDate:
|
| 347 |
ds_item.expectedArrivalDate = to_py_date(item.expectedArrivalDate)
|
359 |
ds_item.expectedArrivalDate = to_py_date(item.expectedArrivalDate)
|
| 348 |
if item.mrp:
|
360 |
if item.mrp:
|
| 349 |
ds_item.mrp = item.mrp
|
361 |
ds_item.mrp = item.mrp
|
| 350 |
if item.sellingPrice:
|
362 |
if item.sellingPrice:
|
| 351 |
ds_item.sellingPrice = item.sellingPrice
|
363 |
ds_item.sellingPrice = item.sellingPrice
|
| 352 |
if item.weight:
|
364 |
if item.weight:
|
| 353 |
ds_item.weight = item.weight
|
365 |
ds_item.weight = item.weight
|
| 354 |
|
366 |
|
| 355 |
if item.featureId:
|
367 |
if item.featureId:
|
| 356 |
ds_item.feature_id = item.featureId
|
368 |
ds_item.feature_id = item.featureId
|
| 357 |
if item.featureDescription:
|
369 |
if item.featureDescription:
|
| 358 |
ds_item.feature_description = item.featureDescription
|
370 |
ds_item.feature_description = item.featureDescription
|
| 359 |
|
371 |
|
| 360 |
|
372 |
|
| 361 |
#check if categories present. If yes, add them to system
|
373 |
#check if categories present. If yes, add them to system
|
| 362 |
|
374 |
|
| 363 |
if item.bestDealValue:
|
375 |
if item.bestDealValue:
|
| 364 |
ds_item.bestDealValue = item.bestDealValue
|
376 |
ds_item.bestDealValue = item.bestDealValue
|
| 365 |
if item.bestDealText:
|
377 |
if item.bestDealText:
|
| 366 |
ds_item.bestDealText = item.bestDealText
|
378 |
ds_item.bestDealText = item.bestDealText
|
| 367 |
if item.bestDealsDetailsText:
|
379 |
if item.bestDealsDetailsText:
|
| 368 |
ds_item.bestDealsDetailsText = item.bestDealsDetailsText
|
380 |
ds_item.bestDealsDetailsText = item.bestDealsDetailsText
|
| 369 |
if item.bestDealsDetailsLink:
|
381 |
if item.bestDealsDetailsLink:
|
| 370 |
ds_item.bestDealsDetailsLink = item.bestDealsDetailsLink
|
382 |
ds_item.bestDealsDetailsLink = item.bestDealsDetailsLink
|
| 371 |
if item.bestSellingRank:
|
383 |
if item.bestSellingRank:
|
| 372 |
ds_item.bestSellingRank = item.bestSellingRank
|
384 |
ds_item.bestSellingRank = item.bestSellingRank
|
| 373 |
ds_item.defaultForEntity = item.defaultForEntity
|
385 |
ds_item.defaultForEntity = item.defaultForEntity
|
| 374 |
ds_item.risky = item.risky
|
386 |
ds_item.risky = item.risky
|
| 375 |
|
387 |
|
| 376 |
ds_item.type = ItemType._VALUES_TO_NAMES[item.type]
|
388 |
ds_item.type = ItemType._VALUES_TO_NAMES[item.type]
|
| 377 |
ds_item.hasItemNo = item.hasItemNo
|
389 |
ds_item.hasItemNo = item.hasItemNo
|
| 378 |
ds_item.activeOnStore = item.activeOnStore
|
390 |
ds_item.activeOnStore = item.activeOnStore
|
| 379 |
|
391 |
|
| 380 |
if item.expectedDelay is not None:
|
392 |
if item.expectedDelay is not None:
|
| 381 |
ds_item.expectedDelay = item.expectedDelay
|
393 |
ds_item.expectedDelay = item.expectedDelay
|
| 382 |
else:
|
394 |
else:
|
| 383 |
ds_item.expectedDelay = 0
|
395 |
ds_item.expectedDelay = 0
|
| 384 |
|
396 |
|
| 385 |
preferredVendorName = "None"
|
397 |
preferredVendorName = "None"
|
| 386 |
if item.preferredVendor:
|
398 |
if item.preferredVendor:
|
| 387 |
ds_item.preferredVendor = item.preferredVendor
|
399 |
ds_item.preferredVendor = item.preferredVendor
|
| 388 |
inventoryClient = InventoryClient().get_client()
|
400 |
inventoryClient = InventoryClient().get_client()
|
| 389 |
preferredVendorName = inventoryClient.getVendor(item.preferredVendor).name
|
401 |
preferredVendorName = inventoryClient.getVendor(item.preferredVendor).name
|
| 390 |
|
402 |
|
| 391 |
if item.preferredInsurer is not None:
|
403 |
if item.preferredInsurer is not None:
|
| 392 |
ds_item.preferredInsurer = item.preferredInsurer
|
404 |
ds_item.preferredInsurer = item.preferredInsurer
|
| 393 |
|
405 |
|
| 394 |
if item.catalogItemId:
|
406 |
if item.catalogItemId:
|
| 395 |
catalog_client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
407 |
catalog_client = CatalogClient("catalog_service_server_host_master", "catalog_service_server_port").get_client()
|
| 396 |
master_items = catalog_client.getItemsByCatalogId(item.catalogItemId)
|
408 |
master_items = catalog_client.getItemsByCatalogId(item.catalogItemId)
|
| 397 |
itemStatus = status.IN_PROCESS
|
409 |
itemStatus = status.IN_PROCESS
|
| 398 |
for masterItem in master_items:
|
410 |
for masterItem in master_items:
|
| Line 405... |
Line 417... |
| 405 |
ds_item.status_description = "This item is in process."
|
417 |
ds_item.status_description = "This item is in process."
|
| 406 |
else:
|
418 |
else:
|
| 407 |
# Check if a similar item already exists in our database
|
419 |
# Check if a similar item already exists in our database
|
| 408 |
similar_item = Item.query.filter_by(brand=item.brand, model_number=item.modelNumber, model_name=item.modelName).first()
|
420 |
similar_item = Item.query.filter_by(brand=item.brand, model_number=item.modelNumber, model_name=item.modelName).first()
|
| 409 |
print "[SIMILAR ITEM FOUND:] FOR {0} {1} {2}".format(item.brand, item.modelNumber, item.modelName)
|
421 |
print "[SIMILAR ITEM FOUND:] FOR {0} {1} {2}".format(item.brand, item.modelNumber, item.modelName)
|
| 410 |
|
422 |
|
| 411 |
if similar_item is None or similar_item.catalog_item_id is None:
|
423 |
if similar_item is None or similar_item.catalog_item_id is None:
|
| 412 |
# If there is no similar item in the database from before,
|
424 |
# If there is no similar item in the database from before,
|
| 413 |
# use the entity_id_generator
|
425 |
# use the entity_id_generator
|
| 414 |
entity_id = EntityIDGenerator.query.first()
|
426 |
entity_id = EntityIDGenerator.query.first()
|
| 415 |
ds_item.catalog_item_id = entity_id.id + 1
|
427 |
ds_item.catalog_item_id = entity_id.id + 1
|
| Line 423... |
Line 435... |
| 423 |
ds_item.catalog_item_id = similar_item.catalog_item_id
|
435 |
ds_item.catalog_item_id = similar_item.catalog_item_id
|
| 424 |
ds_item.category = similar_item.category
|
436 |
ds_item.category = similar_item.category
|
| 425 |
ds_item.product_group = similar_item.product_group
|
437 |
ds_item.product_group = similar_item.product_group
|
| 426 |
ds_item.status = similar_item.status
|
438 |
ds_item.status = similar_item.status
|
| 427 |
ds_item.status_description = similar_item.status_description
|
439 |
ds_item.status_description = similar_item.status_description
|
| 428 |
|
440 |
|
| 429 |
session.commit();
|
441 |
session.commit();
|
| 430 |
subject = "New item is added. Id is {0}".format(str(ds_item.id))
|
442 |
subject = "New item is added. Id is {0}".format(str(ds_item.id))
|
| 431 |
message = "Category : {6}, Brand : {0}, Model : {1}, Model Number : {2}\nColor : {3}, Selling Price : {4}, Mrp : {5}, \nPromotion Text : {7}, Preferred Vendor: {8}".format(item.brand, item.modelNumber, item.modelName, item.color, item.sellingPrice, item.mrp, item.category, item.bestDealText,item.bestDealsDetailsText,item.bestDealsDetailsLink, preferredVendorName)
|
443 |
message = "Category : {6}, Brand : {0}, Model : {1}, Model Number : {2}\nColor : {3}, Selling Price : {4}, Mrp : {5}, \nPromotion Text : {7}, Preferred Vendor: {8}".format(item.brand, item.modelNumber, item.modelName, item.color, item.sellingPrice, item.mrp, item.category, item.bestDealText,item.bestDealsDetailsText,item.bestDealsDetailsLink, preferredVendorName)
|
| 432 |
__send_mail(subject, message)
|
444 |
__send_mail(subject, message)
|
| 433 |
return ds_item.id
|
445 |
return ds_item.id
|
| Line 439... |
Line 451... |
| 439 |
if not item:
|
451 |
if not item:
|
| 440 |
raise InventoryServiceException(108, "item id not present")
|
452 |
raise InventoryServiceException(108, "item id not present")
|
| 441 |
item.status = status.PHASED_OUT
|
453 |
item.status = status.PHASED_OUT
|
| 442 |
item.retireDate = datetime.datetime.now()
|
454 |
item.retireDate = datetime.datetime.now()
|
| 443 |
session.commit()
|
455 |
session.commit()
|
| 444 |
|
456 |
|
| 445 |
#need to implement threads based solution here
|
457 |
#need to implement threads based solution here
|
| 446 |
def start_item_on(item_id, timestamp):
|
458 |
def start_item_on(item_id, timestamp):
|
| 447 |
if not item_id:
|
459 |
if not item_id:
|
| 448 |
raise InventoryServiceException(101, "bad item id")
|
460 |
raise InventoryServiceException(101, "bad item id")
|
| 449 |
item = get_item(item_id)
|
461 |
item = get_item(item_id)
|
| 450 |
if not item:
|
462 |
if not item:
|
| 451 |
raise InventoryServiceException(108, "item id not present")
|
463 |
raise InventoryServiceException(108, "item id not present")
|
| 452 |
|
464 |
|
| 453 |
item.status = status.ACTIVE
|
465 |
item.status = status.ACTIVE
|
| 454 |
item.startDate = datetime.datetime.fromtimestamp(to_py_date(timestamp))
|
466 |
item.startDate = datetime.datetime.fromtimestamp(to_py_date(timestamp))
|
| 455 |
add_status_change_log(item, status.ACTIVE)
|
467 |
add_status_change_log(item, status.ACTIVE)
|
| 456 |
session.commit()
|
468 |
session.commit()
|
| 457 |
|
469 |
|
| 458 |
#need to implement threads here
|
470 |
#need to implement threads here
|
| 459 |
def retire_item_on(item_id, timestamp):
|
471 |
def retire_item_on(item_id, timestamp):
|
| 460 |
if not item_id:
|
472 |
if not item_id:
|
| 461 |
raise InventoryServiceException(101, "bad item id")
|
473 |
raise InventoryServiceException(101, "bad item id")
|
| 462 |
item = get_item(item_id)
|
474 |
item = get_item(item_id)
|
| 463 |
if not item:
|
475 |
if not item:
|
| 464 |
raise InventoryServiceException(108, "item id not present")
|
476 |
raise InventoryServiceException(108, "item id not present")
|
| 465 |
|
477 |
|
| 466 |
item.status = status.PHASED_OUT
|
478 |
item.status = status.PHASED_OUT
|
| 467 |
item.retireDate = datetime.datetime.fromtimestamp(to_py_date(timestamp))
|
479 |
item.retireDate = datetime.datetime.fromtimestamp(to_py_date(timestamp))
|
| 468 |
add_status_change_log(item, status.PHASED_OUT)
|
480 |
add_status_change_log(item, status.PHASED_OUT)
|
| 469 |
session.commit()
|
481 |
session.commit()
|
| 470 |
|
482 |
|
| 471 |
def add_status_change_log(item, new_status):
|
483 |
def add_status_change_log(item, new_status):
|
| 472 |
item_change_log = ItemChangeLog()
|
484 |
item_change_log = ItemChangeLog()
|
| 473 |
item_change_log.new_status = new_status
|
485 |
item_change_log.new_status = new_status
|
| 474 |
item_change_log.old_status = item.status
|
486 |
item_change_log.old_status = item.status
|
| 475 |
item_change_log.timestamp = datetime.datetime.now()
|
487 |
item_change_log.timestamp = datetime.datetime.now()
|
| 476 |
item_change_log.item = item
|
488 |
item_change_log.item = item
|
| 477 |
session.commit()
|
489 |
session.commit()
|
| 478 |
|
490 |
|
| 479 |
def change_item_status(item_id, new_status):
|
491 |
def change_item_status(item_id, new_status):
|
| 480 |
if not item_id:
|
492 |
if not item_id:
|
| 481 |
raise InventoryServiceException(101, "bad item id")
|
493 |
raise InventoryServiceException(101, "bad item id")
|
| 482 |
item = get_item(item_id)
|
494 |
item = get_item(item_id)
|
| 483 |
if not item:
|
495 |
if not item:
|
| Line 488... |
Line 500... |
| 488 |
item.status_description = "This item has been phased out"
|
500 |
item.status_description = "This item has been phased out"
|
| 489 |
__send_mail("Item '{0}' is Phased-Out. Item id is {1}".format(__get_product_name(item), item_id), "")
|
501 |
__send_mail("Item '{0}' is Phased-Out. Item id is {1}".format(__get_product_name(item), item_id), "")
|
| 490 |
elif item.status == status.DELETED:
|
502 |
elif item.status == status.DELETED:
|
| 491 |
item.status_description = "This item has been deleted"
|
503 |
item.status_description = "This item has been deleted"
|
| 492 |
elif item.status == status.PAUSED:
|
504 |
elif item.status == status.PAUSED:
|
| 493 |
item.status_description = "This item is currently out of stock"
|
505 |
item.status_description = "This item is currently out of stock"
|
| 494 |
elif item.status == status.PAUSED_BY_RISK:
|
506 |
elif item.status == status.PAUSED_BY_RISK:
|
| 495 |
item.status_description = "This item is currently out of stock"
|
507 |
item.status_description = "This item is currently out of stock"
|
| 496 |
#This will clear cache from tomcat
|
508 |
#This will clear cache from tomcat
|
| 497 |
__clear_homepage_cache()
|
509 |
__clear_homepage_cache()
|
| 498 |
elif item.status == status.ACTIVE:
|
510 |
elif item.status == status.ACTIVE:
|
| 499 |
item.status_description = "This item is active"
|
511 |
item.status_description = "This item is active"
|
| 500 |
elif item.status == status.IN_PROCESS:
|
512 |
elif item.status == status.IN_PROCESS:
|
| 501 |
item.status_description = "This item is in process"
|
513 |
item.status_description = "This item is in process"
|
| 502 |
elif item.status == status.CONTENT_COMPLETE:
|
514 |
elif item.status == status.CONTENT_COMPLETE:
|
| 503 |
item.status_description = "This item is in process"
|
515 |
item.status_description = "This item is in process"
|
| 504 |
session.commit()
|
516 |
session.commit()
|
| 505 |
|
517 |
|
| 506 |
def check_risky_item(item_id):
|
518 |
def check_risky_item(item_id):
|
| 507 |
item = get_item(item_id)
|
519 |
item = get_item(item_id)
|
| 508 |
if not item.risky:
|
520 |
if not item.risky:
|
| 509 |
return
|
521 |
return
|
| 510 |
client = InventoryClient().get_client()
|
522 |
client = InventoryClient().get_client()
|
| 511 |
itemInfo = client.getItemAvailabilityAtLocation(item.id, sourceId)
|
523 |
itemInfo = client.getItemAvailabilityAtLocation(item.id, sourceId)
|
| 512 |
warehouse_id = itemInfo[0]
|
524 |
warehouse_id = itemInfo[0]
|
| 513 |
availability = client.getItemAvailibilityAtWarehouse(warehouse_id, item.id)
|
525 |
availability = client.getItemAvailibilityAtWarehouse(warehouse_id, item.id)
|
| 514 |
if availability <= 0:
|
526 |
if availability <= 0:
|
| 515 |
if item.status == status.ACTIVE:
|
527 |
if item.status == status.ACTIVE:
|
| 516 |
change_item_status(item.id, status.PAUSED_BY_RISK)
|
528 |
change_item_status(item.id, status.PAUSED_BY_RISK)
|
| Line 518... |
Line 530... |
| 518 |
else:
|
530 |
else:
|
| 519 |
if item.status == status.PAUSED_BY_RISK:
|
531 |
if item.status == status.PAUSED_BY_RISK:
|
| 520 |
change_item_status(item.id, status.ACTIVE)
|
532 |
change_item_status(item.id, status.ACTIVE)
|
| 521 |
__send_mail_for_active_item(item.id, "Item '{0}' is Active. Item id is {1}".format(__get_product_name(item), item_id), "")
|
533 |
__send_mail_for_active_item(item.id, "Item '{0}' is Active. Item id is {1}".format(__get_product_name(item), item_id), "")
|
| 522 |
session.commit()
|
534 |
session.commit()
|
| 523 |
|
535 |
|
| 524 |
def mark_item_as_content_complete(entity_id, category, brand, modelName, modelNumber):
|
536 |
def mark_item_as_content_complete(entity_id, category, brand, modelName, modelNumber):
|
| 525 |
'''
|
537 |
'''
|
| 526 |
Get all the items for this entityID and update category, brand, modelName and modelNumber for all.
|
538 |
Get all the items for this entityID and update category, brand, modelName and modelNumber for all.
|
| 527 |
Update Status for only IN_PROCESS items to CONTENT_COMPLETE
|
539 |
Update Status for only IN_PROCESS items to CONTENT_COMPLETE
|
| 528 |
'''
|
540 |
'''
|
| Line 535... |
Line 547... |
| 535 |
item_change_log = ItemChangeLog()
|
547 |
item_change_log = ItemChangeLog()
|
| 536 |
item_change_log.old_status = item.status
|
548 |
item_change_log.old_status = item.status
|
| 537 |
item_change_log.new_status = content_complete_status
|
549 |
item_change_log.new_status = content_complete_status
|
| 538 |
item_change_log.timestamp = current_timestamp
|
550 |
item_change_log.timestamp = current_timestamp
|
| 539 |
item_change_log.item = item
|
551 |
item_change_log.item = item
|
| 540 |
|
552 |
|
| 541 |
category_object = get_category(category)
|
553 |
category_object = get_category(category)
|
| 542 |
if category_object is not None:
|
554 |
if category_object is not None:
|
| 543 |
item.category = category
|
555 |
item.category = category
|
| 544 |
item.product_group = category_object.display_name
|
556 |
item.product_group = category_object.display_name
|
| 545 |
item.brand = brand
|
557 |
item.brand = brand
|
| Line 572... |
Line 584... |
| 572 |
return count
|
584 |
return count
|
| 573 |
|
585 |
|
| 574 |
def get_best_sellers_catalog_ids(start_index, stop_index, brand, category=-1):
|
586 |
def get_best_sellers_catalog_ids(start_index, stop_index, brand, category=-1):
|
| 575 |
'''
|
587 |
'''
|
| 576 |
Returns the Best sellers for the given brand and category between the start and the stop index.
|
588 |
Returns the Best sellers for the given brand and category between the start and the stop index.
|
| 577 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
589 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
| 578 |
'''
|
590 |
'''
|
| 579 |
query = get_best_sellers_query(category, brand)
|
591 |
query = get_best_sellers_query(category, brand)
|
| 580 |
best_sellers = query.all()[start_index:stop_index]
|
592 |
best_sellers = query.all()[start_index:stop_index]
|
| 581 |
return [item.catalog_item_id for item in best_sellers]
|
593 |
return [item.catalog_item_id for item in best_sellers]
|
| 582 |
|
594 |
|
| 583 |
def get_best_sellers_query(category, brand):
|
595 |
def get_best_sellers_query(category, brand):
|
| 584 |
'''
|
596 |
'''
|
| 585 |
Returns the query to be used for getting Best Sellers.
|
597 |
Returns the query to be used for getting Best Sellers.
|
| 586 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
598 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
| 587 |
'''
|
599 |
'''
|
| 588 |
query = Item.query.filter_by(status=status.ACTIVE).filter(Item.bestSellingRank != None)
|
600 |
query = Item.query.filter_by(status=status.ACTIVE).filter(Item.bestSellingRank != None)
|
| 589 |
if category != -1:
|
601 |
if category != -1:
|
| 590 |
all_categories = [category]
|
602 |
all_categories = [category]
|
| 591 |
child_categories = get_child_categories(category)
|
603 |
child_categories = get_child_categories(category)
|
| 592 |
if child_categories is not None:
|
604 |
if child_categories is not None:
|
| 593 |
all_categories = all_categories + child_categories
|
605 |
all_categories = all_categories + child_categories
|
| 594 |
query = query.filter(Item.category.in_(all_categories))
|
606 |
query = query.filter(Item.category.in_(all_categories))
|
| 595 |
if brand is not None:
|
607 |
if brand is not None:
|
| 596 |
query = query.filter_by(brand=brand)
|
608 |
query = query.filter_by(brand=brand)
|
| 597 |
query = query.group_by(Item.catalog_item_id).order_by(asc(Item.bestSellingRank))
|
609 |
query = query.group_by(Item.catalog_item_id).order_by(asc(Item.bestSellingRank))
|
| 598 |
return query
|
610 |
return query
|
| Line 612... |
Line 624... |
| 612 |
'''
|
624 |
'''
|
| 613 |
count = get_best_deals_counting_query(func.count(distinct(Item.catalog_item_id)), category, None).scalar()
|
625 |
count = get_best_deals_counting_query(func.count(distinct(Item.catalog_item_id)), category, None).scalar()
|
| 614 |
if count is None:
|
626 |
if count is None:
|
| 615 |
count = 0
|
627 |
count = 0
|
| 616 |
return count
|
628 |
return count
|
| 617 |
|
629 |
|
| 618 |
def get_best_deals_catalog_ids(start_index, stop_index, brand, category=-1):
|
630 |
def get_best_deals_catalog_ids(start_index, stop_index, brand, category=-1):
|
| 619 |
'''
|
631 |
'''
|
| 620 |
Returns the catalog_item_ids of best deal items for the given brand and category.
|
632 |
Returns the catalog_item_ids of best deal items for the given brand and category.
|
| 621 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
633 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
| 622 |
'''
|
634 |
'''
|
| Line 625... |
Line 637... |
| 625 |
return [item.catalog_item_id for item in best_deal_items]
|
637 |
return [item.catalog_item_id for item in best_deal_items]
|
| 626 |
|
638 |
|
| 627 |
def get_best_deals_counting_query(obj, category, brand):
|
639 |
def get_best_deals_counting_query(obj, category, brand):
|
| 628 |
'''
|
640 |
'''
|
| 629 |
Returns the query to be used to select the best deals in the given brand and category.
|
641 |
Returns the query to be used to select the best deals in the given brand and category.
|
| 630 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
642 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
| 631 |
'''
|
643 |
'''
|
| 632 |
query = session.query(obj).filter_by(status=status.ACTIVE).filter(Item.bestDealValue != None)
|
644 |
query = session.query(obj).filter_by(status=status.ACTIVE).filter(Item.bestDealValue != None)
|
| 633 |
if category != -1:
|
645 |
if category != -1:
|
| 634 |
all_categories = [category]
|
646 |
all_categories = [category]
|
| 635 |
child_categories = get_child_categories(category)
|
647 |
child_categories = get_child_categories(category)
|
| 636 |
if child_categories is not None:
|
648 |
if child_categories is not None:
|
| 637 |
all_categories = all_categories + child_categories
|
649 |
all_categories = all_categories + child_categories
|
| 638 |
query = query.filter(Item.category.in_(all_categories))
|
650 |
query = query.filter(Item.category.in_(all_categories))
|
| 639 |
if brand is not None:
|
651 |
if brand is not None:
|
| 640 |
query = query.filter_by(brand=brand)
|
652 |
query = query.filter_by(brand=brand)
|
| 641 |
return query
|
653 |
return query
|
| 642 |
|
654 |
|
| Line 677... |
Line 689... |
| 677 |
return [item.catalog_item_id for item in coming_soon_items]
|
689 |
return [item.catalog_item_id for item in coming_soon_items]
|
| 678 |
|
690 |
|
| 679 |
def get_coming_soon_counting_query(obj, category, brand):
|
691 |
def get_coming_soon_counting_query(obj, category, brand):
|
| 680 |
'''
|
692 |
'''
|
| 681 |
Returns the query to be used to select the coming soon product in the given brand and category.
|
693 |
Returns the query to be used to select the coming soon product in the given brand and category.
|
| 682 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
694 |
Ignores the category if it's passed as -1 and the brand if it's passed as None.
|
| 683 |
'''
|
695 |
'''
|
| 684 |
query = session.query(obj).filter_by(status=status.COMING_SOON)
|
696 |
query = session.query(obj).filter_by(status=status.COMING_SOON)
|
| 685 |
if category != -1:
|
697 |
if category != -1:
|
| 686 |
all_categories = [category]
|
698 |
all_categories = [category]
|
| 687 |
child_categories = get_child_categories(category)
|
699 |
child_categories = get_child_categories(category)
|
| 688 |
if child_categories is not None:
|
700 |
if child_categories is not None:
|
| 689 |
all_categories = all_categories + child_categories
|
701 |
all_categories = all_categories + child_categories
|
| 690 |
query = query.filter(Item.category.in_(all_categories))
|
702 |
query = query.filter(Item.category.in_(all_categories))
|
| 691 |
if brand is not None:
|
703 |
if brand is not None:
|
| 692 |
query = query.filter_by(brand=brand)
|
704 |
query = query.filter_by(brand=brand)
|
| 693 |
return query
|
705 |
return query
|
| 694 |
|
706 |
|
| Line 709... |
Line 721... |
| 709 |
if category != -1:
|
721 |
if category != -1:
|
| 710 |
categories = [category]
|
722 |
categories = [category]
|
| 711 |
query = get_latest_arrivals_query(Item, categories, None)
|
723 |
query = get_latest_arrivals_query(Item, categories, None)
|
| 712 |
items = query.all()[0:limit]
|
724 |
items = query.all()[0:limit]
|
| 713 |
return get_thrift_item_list(items)
|
725 |
return get_thrift_item_list(items)
|
| 714 |
|
726 |
|
| 715 |
def get_latest_arrivals_count(limit, category=-1):
|
727 |
def get_latest_arrivals_count(limit, category=-1):
|
| 716 |
'''
|
728 |
'''
|
| 717 |
Returns the number of latest arrivals which will be displayed on the website.
|
729 |
Returns the number of latest arrivals which will be displayed on the website.
|
| 718 |
To ignore the categories, pass the list as empty. To ignore brand, pass it as null.
|
730 |
To ignore the categories, pass the list as empty. To ignore brand, pass it as null.
|
| 719 |
'''
|
731 |
'''
|
| Line 723... |
Line 735... |
| 723 |
count = get_latest_arrivals_counting_query(func.count(distinct(Item.catalog_item_id)), categories, None).scalar()
|
735 |
count = get_latest_arrivals_counting_query(func.count(distinct(Item.catalog_item_id)), categories, None).scalar()
|
| 724 |
if count is None:
|
736 |
if count is None:
|
| 725 |
count = 0
|
737 |
count = 0
|
| 726 |
count = min(count, limit)
|
738 |
count = min(count, limit)
|
| 727 |
return count
|
739 |
return count
|
| 728 |
|
740 |
|
| 729 |
def get_latest_arrivals_catalog_ids(start_index, stop_index, brand, categories=[]):
|
741 |
def get_latest_arrivals_catalog_ids(start_index, stop_index, brand, categories=[]):
|
| 730 |
'''
|
742 |
'''
|
| 731 |
Returns the catalog_item_ids of the latest arrivals between the start and the stop index
|
743 |
Returns the catalog_item_ids of the latest arrivals between the start and the stop index
|
| 732 |
To ignore the categories, pass the list as empty. To ignore brand, pass it as null.
|
744 |
To ignore the categories, pass the list as empty. To ignore brand, pass it as null.
|
| 733 |
'''
|
745 |
'''
|
| Line 739... |
Line 751... |
| 739 |
'''
|
751 |
'''
|
| 740 |
Returns the query to be used to count Latest arrivals.
|
752 |
Returns the query to be used to count Latest arrivals.
|
| 741 |
To ignore the categories, pass the list as empty. To ignore brand, pass it as null.
|
753 |
To ignore the categories, pass the list as empty. To ignore brand, pass it as null.
|
| 742 |
'''
|
754 |
'''
|
| 743 |
query = session.query(obj).filter_by(status=status.ACTIVE)
|
755 |
query = session.query(obj).filter_by(status=status.ACTIVE)
|
| 744 |
|
756 |
|
| 745 |
all_categories = []
|
757 |
all_categories = []
|
| 746 |
for category in categories:
|
758 |
for category in categories:
|
| 747 |
all_categories.append(category)
|
759 |
all_categories.append(category)
|
| 748 |
child_categories = get_child_categories(category)
|
760 |
child_categories = get_child_categories(category)
|
| 749 |
if child_categories:
|
761 |
if child_categories:
|
| 750 |
all_categories = all_categories + child_categories
|
762 |
all_categories = all_categories + child_categories
|
| 751 |
if all_categories:
|
763 |
if all_categories:
|
| 752 |
query = query.filter(Item.category.in_(all_categories))
|
764 |
query = query.filter(Item.category.in_(all_categories))
|
| 753 |
|
765 |
|
| 754 |
if brand is not None:
|
766 |
if brand is not None:
|
| 755 |
query = query.filter_by(brand=brand)
|
767 |
query = query.filter_by(brand=brand)
|
| 756 |
return query
|
768 |
return query
|
| 757 |
|
769 |
|
| 758 |
def get_latest_arrivals_query(obj, categories, brand):
|
770 |
def get_latest_arrivals_query(obj, categories, brand):
|
| Line 776... |
Line 788... |
| 776 |
|
788 |
|
| 777 |
def put_category_object(object):
|
789 |
def put_category_object(object):
|
| 778 |
category = Category.get_by(id=1)
|
790 |
category = Category.get_by(id=1)
|
| 779 |
if category is None:
|
791 |
if category is None:
|
| 780 |
category = Category()
|
792 |
category = Category()
|
| 781 |
category.object = object
|
793 |
category.object = object
|
| 782 |
session.commit()
|
794 |
session.commit()
|
| 783 |
return True
|
795 |
return True
|
| 784 |
|
796 |
|
| 785 |
def get_category_object():
|
797 |
def get_category_object():
|
| 786 |
object = Category.get_by(id=1).object
|
798 |
object = Category.get_by(id=1).object
|
| Line 788... |
Line 800... |
| 788 |
|
800 |
|
| 789 |
def add_category(t_category):
|
801 |
def add_category(t_category):
|
| 790 |
category = Category.get_by(id=t_category.id)
|
802 |
category = Category.get_by(id=t_category.id)
|
| 791 |
if category is None:
|
803 |
if category is None:
|
| 792 |
category = Category()
|
804 |
category = Category()
|
| 793 |
category.id = t_category.id
|
805 |
category.id = t_category.id
|
| 794 |
category.label = t_category.label
|
806 |
category.label = t_category.label
|
| 795 |
category.description = t_category.description
|
807 |
category.description = t_category.description
|
| 796 |
category.display_name = t_category.display_name
|
808 |
category.display_name = t_category.display_name
|
| 797 |
category.parent_category_id = t_category.parent_category_id
|
809 |
category.parent_category_id = t_category.parent_category_id
|
| 798 |
session.commit()
|
810 |
session.commit()
|
| 799 |
return True
|
811 |
return True
|
| 800 |
|
812 |
|
| 801 |
def get_category(id):
|
813 |
def get_category(id):
|
| 802 |
return Category.query.filter_by(id=id).first()
|
814 |
return Category.query.filter_by(id=id).first()
|
| Line 809... |
Line 821... |
| 809 |
return
|
821 |
return
|
| 810 |
if item.mrp < item.sellingPrice:
|
822 |
if item.mrp < item.sellingPrice:
|
| 811 |
print "[BAD MRP and SP:] for {0} {1} {2} {3}. MRP={4}, SP={5}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(item.sellingPrice))
|
823 |
print "[BAD MRP and SP:] for {0} {1} {2} {3}. MRP={4}, SP={5}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(item.sellingPrice))
|
| 812 |
raise InventoryServiceException(101, "[BAD MRP and SP:] for {0} {1} {2} {3}. MRP={4}, SP={5}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(item.sellingPrice)))
|
824 |
raise InventoryServiceException(101, "[BAD MRP and SP:] for {0} {1} {2} {3}. MRP={4}, SP={5}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(item.sellingPrice)))
|
| 813 |
return
|
825 |
return
|
| 814 |
|
826 |
|
| 815 |
def validate_vendor_prices(item, vendorPrices):
|
827 |
def validate_vendor_prices(item, vendorPrices):
|
| 816 |
if item.mrp != None and item.mrp != "" and vendorPrices.mop != "" and item.mrp < vendorPrices.mop:
|
828 |
if item.mrp != None and item.mrp != "" and vendorPrices.mop != "" and item.mrp < vendorPrices.mop:
|
| 817 |
print "[BAD MRP and MOP:] for {0} {1} {2} {3}. MRP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(vendorPrices.mop), str(vendorPrices.vendorId))
|
829 |
print "[BAD MRP and MOP:] for {0} {1} {2} {3}. MRP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(vendorPrices.mop), str(vendorPrices.vendorId))
|
| 818 |
raise InventoryServiceException(101, "[BAD MRP and MOP:] for {0} {1} {2} {3}. MRP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(vendorPrices.mop), str(vendorPrices.vendorId)))
|
830 |
raise InventoryServiceException(101, "[BAD MRP and MOP:] for {0} {1} {2} {3}. MRP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(item.mrp), str(vendorPrices.mop), str(vendorPrices.vendorId)))
|
| 819 |
if vendorPrices.mop != "" and vendorPrices.transferPrice != "" and vendorPrices.transferPrice > vendorPrices.mop:
|
831 |
if vendorPrices.mop != "" and vendorPrices.transferPrice != "" and vendorPrices.transferPrice > vendorPrices.mop:
|
| Line 838... |
Line 850... |
| 838 |
# Check if a similar item already exists in our database
|
850 |
# Check if a similar item already exists in our database
|
| 839 |
for old_item in similar_items:
|
851 |
for old_item in similar_items:
|
| 840 |
if old_item.color != None and old_item.color.strip().lower() == color.strip().lower():
|
852 |
if old_item.color != None and old_item.color.strip().lower() == color.strip().lower():
|
| 841 |
item = old_item
|
853 |
item = old_item
|
| 842 |
break
|
854 |
break
|
| 843 |
|
855 |
|
| 844 |
# Check if a similar item already exists in our database with out valid color if similar item with same color is not found
|
856 |
# Check if a similar item already exists in our database with out valid color if similar item with same color is not found
|
| 845 |
if item is None:
|
857 |
if item is None:
|
| 846 |
for old_item in similar_items:
|
858 |
for old_item in similar_items:
|
| 847 |
if not check_color_valid(old_item.color):
|
859 |
if not check_color_valid(old_item.color):
|
| 848 |
item = old_item
|
860 |
item = old_item
|
| Line 859... |
Line 871... |
| 859 |
i = i + 1
|
871 |
i = i + 1
|
| 860 |
# get a similar item already existing in our database if similar item with valid color is not found
|
872 |
# get a similar item already existing in our database if similar item with valid color is not found
|
| 861 |
if i == len(similar_items):
|
873 |
if i == len(similar_items):
|
| 862 |
similar_item = old_item
|
874 |
similar_item = old_item
|
| 863 |
color_of_similar_item = similar_item.color
|
875 |
color_of_similar_item = similar_item.color
|
| 864 |
|
876 |
|
| 865 |
# Check if a similar item that is obtained above is having a valid color
|
877 |
# Check if a similar item that is obtained above is having a valid color
|
| 866 |
if check_color_valid(color_of_similar_item):
|
878 |
if check_color_valid(color_of_similar_item):
|
| 867 |
# if a similar item that is obtained above is having a valid color and new item is about to be created with out valid color it is not done.
|
879 |
# if a similar item that is obtained above is having a valid color and new item is about to be created with out valid color it is not done.
|
| 868 |
# since for example if their is a item with red color in our database and we are creating a new item with no color for the same product which is wrong.
|
880 |
# since for example if their is a item with red color in our database and we are creating a new item with no color for the same product which is wrong.
|
| 869 |
if item is None and not check_color_valid(color):
|
881 |
if item is None and not check_color_valid(color):
|
| 870 |
return similar_item.id
|
882 |
return similar_item.id
|
| 871 |
|
883 |
|
| 872 |
if item is None:
|
884 |
if item is None:
|
| 873 |
return 0
|
885 |
return 0
|
| 874 |
else:
|
886 |
else:
|
| 875 |
return item.id
|
887 |
return item.id
|
| 876 |
|
888 |
|
| 877 |
def change_risky_flag(item_id, risky):
|
889 |
def change_risky_flag(item_id, risky):
|
| 878 |
item = get_item(item_id)
|
890 |
item = get_item(item_id)
|
| 879 |
if not item:
|
891 |
if not item:
|
| 880 |
raise InventoryServiceException(101, "Item missing in our database")
|
892 |
raise InventoryServiceException(101, "Item missing in our database")
|
| 881 |
try:
|
893 |
try:
|
| Line 888... |
Line 900... |
| 888 |
__send_mail_for_active_item(item.id, "Item '{0}' is Active. Item id is {1}".format(__get_product_name(item), item_id), "")
|
900 |
__send_mail_for_active_item(item.id, "Item '{0}' is Active. Item id is {1}".format(__get_product_name(item), item_id), "")
|
| 889 |
session.commit()
|
901 |
session.commit()
|
| 890 |
flag = "ON" if risky else "OFF"
|
902 |
flag = "ON" if risky else "OFF"
|
| 891 |
subject = "Risky flag is {0} for Item {1}.".format(flag, __get_product_name(item))
|
903 |
subject = "Risky flag is {0} for Item {1}.".format(flag, __get_product_name(item))
|
| 892 |
__send_mail(subject,"")
|
904 |
__send_mail(subject,"")
|
| 893 |
|
905 |
|
| 894 |
def get_items_for_mastersheet(categoryName, brand):
|
906 |
def get_items_for_mastersheet(categoryName, brand):
|
| 895 |
if not categoryName or not brand:
|
907 |
if not categoryName or not brand:
|
| 896 |
raise InventoryServiceException(101, "Invalid category or brand in request")
|
908 |
raise InventoryServiceException(101, "Invalid category or brand in request")
|
| 897 |
|
909 |
|
| 898 |
categories = ["Handsets", "Tablets", "Laptops"]
|
910 |
categories = ["Handsets", "Tablets", "Laptops"]
|
| 899 |
query = Item.query.filter(Item.status != status.PHASED_OUT)
|
911 |
query = Item.query.filter(Item.status != status.PHASED_OUT)
|
| 900 |
if categoryName == "ALL":
|
912 |
if categoryName == "ALL":
|
| 901 |
pass
|
913 |
pass
|
| 902 |
elif categoryName == "ALL Accessories":
|
914 |
elif categoryName == "ALL Accessories":
|
| Line 913... |
Line 925... |
| 913 |
if child_categories is not None:
|
925 |
if child_categories is not None:
|
| 914 |
child_categories.append(0)
|
926 |
child_categories.append(0)
|
| 915 |
query = query.filter(Item.category.in_(child_categories))
|
927 |
query = query.filter(Item.category.in_(child_categories))
|
| 916 |
else:
|
928 |
else:
|
| 917 |
query = query.filter(Item.product_group == categoryName)
|
929 |
query = query.filter(Item.product_group == categoryName)
|
| 918 |
|
930 |
|
| 919 |
if brand == "ALL":
|
931 |
if brand == "ALL":
|
| 920 |
pass
|
932 |
pass
|
| 921 |
else:
|
933 |
else:
|
| 922 |
query = query.filter(Item.brand == brand)
|
934 |
query = query.filter(Item.brand == brand)
|
| 923 |
items = query.all()
|
935 |
items = query.all()
|
| Line 949... |
Line 961... |
| 949 |
return_list = []
|
961 |
return_list = []
|
| 950 |
for similar_item in similar_items:
|
962 |
for similar_item in similar_items:
|
| 951 |
item_query = Item.query.filter_by(catalog_item_id=similar_item.catalog_item_id).limit(1)
|
963 |
item_query = Item.query.filter_by(catalog_item_id=similar_item.catalog_item_id).limit(1)
|
| 952 |
item = item_query.one()
|
964 |
item = item_query.one()
|
| 953 |
return_list.append(item)
|
965 |
return_list.append(item)
|
| 954 |
|
966 |
|
| 955 |
return get_thrift_item_list(return_list)
|
967 |
return get_thrift_item_list(return_list)
|
| 956 |
|
968 |
|
| 957 |
def add_similar_item_catalog_id(itemId, catalog_item_id):
|
969 |
def add_similar_item_catalog_id(itemId, catalog_item_id):
|
| 958 |
if not itemId or not catalog_item_id:
|
970 |
if not itemId or not catalog_item_id:
|
| 959 |
raise InventoryServiceException(101, "Bad itemId or catalogItemId in request")
|
971 |
raise InventoryServiceException(101, "Bad itemId or catalogItemId in request")
|
| 960 |
items_for_entity = get_items_by_catalog_id(catalog_item_id)
|
972 |
items_for_entity = get_items_by_catalog_id(catalog_item_id)
|
| 961 |
if not len(items_for_entity):
|
973 |
if not len(items_for_entity):
|
| 962 |
raise InventoryServiceException(101, "catalogItemId does not exists in database")
|
974 |
raise InventoryServiceException(101, "catalogItemId does not exists in database")
|
| 963 |
|
975 |
|
| 964 |
s_items = SimilarItems.query.filter_by(item_id=itemId, catalog_item_id=catalog_item_id).all()
|
976 |
s_items = SimilarItems.query.filter_by(item_id=itemId, catalog_item_id=catalog_item_id).all()
|
| 965 |
if not len(s_items):
|
977 |
if not len(s_items):
|
| 966 |
s_item = SimilarItems()
|
978 |
s_item = SimilarItems()
|
| 967 |
s_item.item_id=itemId
|
979 |
s_item.item_id=itemId
|
| 968 |
s_item.catalog_item_id=catalog_item_id
|
980 |
s_item.catalog_item_id=catalog_item_id
|
| 969 |
session.commit()
|
981 |
session.commit()
|
| 970 |
return items_for_entity[0]
|
982 |
return items_for_entity[0]
|
| 971 |
else:
|
983 |
else:
|
| 972 |
raise InventoryServiceException(101, "Already exists")
|
984 |
raise InventoryServiceException(101, "Already exists")
|
| 973 |
|
985 |
|
| 974 |
def delete_similar_item_catalog_id(itemId, catalog_item_id):
|
986 |
def delete_similar_item_catalog_id(itemId, catalog_item_id):
|
| 975 |
if not itemId or not catalog_item_id:
|
987 |
if not itemId or not catalog_item_id:
|
| 976 |
raise InventoryServiceException(101, "Bad itemId or catalogItemId in request")
|
988 |
raise InventoryServiceException(101, "Bad itemId or catalogItemId in request")
|
| 977 |
|
989 |
|
| 978 |
similar_item = SimilarItems.query.filter_by(item_id=itemId, catalog_item_id=catalog_item_id).all()
|
990 |
similar_item = SimilarItems.query.filter_by(item_id=itemId, catalog_item_id=catalog_item_id).all()
|
| 979 |
if len(similar_item):
|
991 |
if len(similar_item):
|
| 980 |
similar_item[0].delete()
|
992 |
similar_item[0].delete()
|
| 981 |
session.commit()
|
993 |
session.commit()
|
| 982 |
return True
|
994 |
return True
|
| Line 993... |
Line 1005... |
| 993 |
return 0
|
1005 |
return 0
|
| 994 |
|
1006 |
|
| 995 |
def add_update_voucher_for_item(catalog_item_id, voucher_type, voucher_amount):
|
1007 |
def add_update_voucher_for_item(catalog_item_id, voucher_type, voucher_amount):
|
| 996 |
if not catalog_item_id or not voucher_type or not voucher_amount:
|
1008 |
if not catalog_item_id or not voucher_type or not voucher_amount:
|
| 997 |
raise InventoryServiceException(101, "Bad catalogItemId or voucherType or voucherAmount in request")
|
1009 |
raise InventoryServiceException(101, "Bad catalogItemId or voucherType or voucherAmount in request")
|
| 998 |
|
1010 |
|
| 999 |
items_for_entity = get_items_by_catalog_id(catalog_item_id)
|
1011 |
items_for_entity = get_items_by_catalog_id(catalog_item_id)
|
| 1000 |
if not len(items_for_entity):
|
1012 |
if not len(items_for_entity):
|
| 1001 |
raise InventoryServiceException(101, "catalogItemId does not exists in database")
|
1013 |
raise InventoryServiceException(101, "catalogItemId does not exists in database")
|
| 1002 |
|
1014 |
|
| 1003 |
for item in items_for_entity:
|
1015 |
for item in items_for_entity:
|
| 1004 |
itemId = item.id
|
1016 |
itemId = item.id
|
| 1005 |
voucher = VoucherItemMapping.query.filter_by(item_id=itemId, voucherType=voucher_type).all()
|
1017 |
voucher = VoucherItemMapping.query.filter_by(item_id=itemId, voucherType=voucher_type).all()
|
| 1006 |
if not len(voucher):
|
1018 |
if not len(voucher):
|
| 1007 |
voucher = VoucherItemMapping()
|
1019 |
voucher = VoucherItemMapping()
|
| Line 1010... |
Line 1022... |
| 1010 |
voucher.amount=voucher_amount
|
1022 |
voucher.amount=voucher_amount
|
| 1011 |
else:
|
1023 |
else:
|
| 1012 |
voucher[0].amount=voucher_amount
|
1024 |
voucher[0].amount=voucher_amount
|
| 1013 |
session.commit()
|
1025 |
session.commit()
|
| 1014 |
return True
|
1026 |
return True
|
| 1015 |
|
1027 |
|
| 1016 |
def delete_voucher_for_item(catalog_item_id, voucher_type):
|
1028 |
def delete_voucher_for_item(catalog_item_id, voucher_type):
|
| 1017 |
if not catalog_item_id or not voucher_type:
|
1029 |
if not catalog_item_id or not voucher_type:
|
| 1018 |
raise InventoryServiceException(101, "Bad catalogItemId or voucherType in request")
|
1030 |
raise InventoryServiceException(101, "Bad catalogItemId or voucherType in request")
|
| 1019 |
|
1031 |
|
| 1020 |
items_for_entity = get_items_by_catalog_id(catalog_item_id)
|
1032 |
items_for_entity = get_items_by_catalog_id(catalog_item_id)
|
| 1021 |
if not len(items_for_entity):
|
1033 |
if not len(items_for_entity):
|
| 1022 |
raise InventoryServiceException(101, "catalogItemId does not exists in database")
|
1034 |
raise InventoryServiceException(101, "catalogItemId does not exists in database")
|
| 1023 |
|
1035 |
|
| 1024 |
for item in items_for_entity:
|
1036 |
for item in items_for_entity:
|
| 1025 |
itemId = item.id
|
1037 |
itemId = item.id
|
| 1026 |
voucher = VoucherItemMapping.query.filter_by(item_id=itemId, voucherType=voucher_type).all()
|
1038 |
voucher = VoucherItemMapping.query.filter_by(item_id=itemId, voucherType=voucher_type).all()
|
| 1027 |
if len(voucher):
|
1039 |
if len(voucher):
|
| 1028 |
voucher[0].delete()
|
1040 |
voucher[0].delete()
|
| Line 1053... |
Line 1065... |
| 1053 |
if itemcountmap.has_key(item.id):
|
1065 |
if itemcountmap.has_key(item.id):
|
| 1054 |
itemcountmap[item.id] = itemcountmap.get(item.id) + 1
|
1066 |
itemcountmap[item.id] = itemcountmap.get(item.id) + 1
|
| 1055 |
else:
|
1067 |
else:
|
| 1056 |
client = InventoryClient().get_client()
|
1068 |
client = InventoryClient().get_client()
|
| 1057 |
availability = client.getItemAvailabilityAtLocation(item.id, sourceId)[4]
|
1069 |
availability = client.getItemAvailabilityAtLocation(item.id, sourceId)[4]
|
| 1058 |
if item.status == status.ACTIVE and (not item.risky or availability > 0):
|
1070 |
if item.status == status.ACTIVE and (not item.risky or availability > 0):
|
| 1059 |
itemstatusmap[item.id] = True
|
1071 |
itemstatusmap[item.id] = True
|
| 1060 |
else:
|
1072 |
else:
|
| 1061 |
itemstatusmap[item.id] = False
|
1073 |
itemstatusmap[item.id] = False
|
| 1062 |
itemcountmap[item.id] = 1
|
1074 |
itemcountmap[item.id] = 1
|
| 1063 |
if itemcountmap[item.id] > 1000:
|
1075 |
if itemcountmap[item.id] > 1000:
|
| 1064 |
continue
|
1076 |
continue
|
| 1065 |
|
1077 |
|
| 1066 |
if itemstatusmap[item.id]:
|
1078 |
if itemstatusmap[item.id]:
|
| 1067 |
__enque_product_notification_email(product_notification.email, __get_product_name(item) , product_notification.addedOn, __get_product_url(item), item.id)
|
1079 |
__enque_product_notification_email(product_notification.email, __get_product_name(item) , product_notification.addedOn, __get_product_url(item), item.id)
|
| 1068 |
product_notification.delete()
|
1080 |
product_notification.delete()
|
| 1069 |
session.commit()
|
1081 |
session.commit()
|
| 1070 |
return True
|
1082 |
return True
|
| 1071 |
|
1083 |
|
| 1072 |
def __get_product_name(item):
|
1084 |
def __get_product_name(item):
|
| 1073 |
product_name = item.brand + " " + item.model_name + " " + item.model_number
|
1085 |
product_name = item.brand + " " + item.model_name + " " + item.model_number
|
| 1074 |
color = item.color
|
1086 |
color = item.color
|
| 1075 |
if color is not None and color != 'NA':
|
1087 |
if color is not None and color != 'NA':
|
| 1076 |
product_name = product_name + " (" + color + ")"
|
1088 |
product_name = product_name + " (" + color + ")"
|
| Line 1086... |
Line 1098... |
| 1086 |
|
1098 |
|
| 1087 |
def get_all_brands_by_category(category_id):
|
1099 |
def get_all_brands_by_category(category_id):
|
| 1088 |
catm = CategoryManager()
|
1100 |
catm = CategoryManager()
|
| 1089 |
child_categories = catm.getCategory(category_id).children_category_ids
|
1101 |
child_categories = catm.getCategory(category_id).children_category_ids
|
| 1090 |
brands = session.query(distinct(Item.brand)).filter(Item.category.in_(child_categories)).all()
|
1102 |
brands = session.query(distinct(Item.brand)).filter(Item.category.in_(child_categories)).all()
|
| 1091 |
|
1103 |
|
| 1092 |
return [brand[0] for brand in brands]
|
1104 |
return [brand[0] for brand in brands]
|
| 1093 |
|
1105 |
|
| 1094 |
def get_all_brands():
|
1106 |
def get_all_brands():
|
| 1095 |
brands = session.query(distinct(Item.brand)).order_by(Item.brand).all()
|
1107 |
brands = session.query(distinct(Item.brand)).order_by(Item.brand).all()
|
| 1096 |
|
1108 |
|
| 1097 |
return [brand[0] for brand in brands]
|
1109 |
return [brand[0] for brand in brands]
|
| 1098 |
|
1110 |
|
| 1099 |
def __enque_product_notification_email(email, product, date, url, itemId):
|
1111 |
def __enque_product_notification_email(email, product, date, url, itemId):
|
| 1100 |
|
1112 |
|
| 1101 |
html = """
|
1113 |
html = """
|
| 1102 |
<html>
|
1114 |
<html>
|
| 1103 |
<body>
|
1115 |
<body>
|
| 1104 |
<div>
|
1116 |
<div>
|
| 1105 |
<p>
|
1117 |
<p>
|
| 1106 |
Hi,<br /><br />
|
1118 |
Hi,<br /><br />
|
| 1107 |
The product requested by you on $date is now available on $source_url.
|
1119 |
The product requested by you on $date is now available on $source_url.
|
| 1108 |
<br />
|
1120 |
<br />
|
| 1109 |
We have limited stocks of this model at this moment. If you don't want to miss out, please place your order as soon as possible.
|
1121 |
We have limited stocks of this model at this moment. If you don't want to miss out, please place your order as soon as possible.
|
| 1110 |
</p>
|
1122 |
</p>
|
| 1111 |
|
1123 |
|
| 1112 |
<p>
|
1124 |
<p>
|
| 1113 |
<strong>Product: $product </strong>
|
1125 |
<strong>Product: $product </strong>
|
| 1114 |
</p>
|
1126 |
</p>
|
| 1115 |
|
1127 |
|
| 1116 |
<p>
|
1128 |
<p>
|
| 1117 |
Click the link below to visit the product:
|
1129 |
Click the link below to visit the product:
|
| 1118 |
<br/>
|
1130 |
<br/>
|
| 1119 |
$url
|
1131 |
$url
|
| 1120 |
</p>
|
1132 |
</p>
|
| 1121 |
<p>
|
1133 |
<p>
|
| 1122 |
Regards,<br/>
|
1134 |
Regards,<br/>
|
| Line 1128... |
Line 1140... |
| 1128 |
</body>
|
1140 |
</body>
|
| 1129 |
</html>
|
1141 |
</html>
|
| 1130 |
"""
|
1142 |
"""
|
| 1131 |
|
1143 |
|
| 1132 |
html = Template(html).substitute(dict(product=product,date=date,url=url,source_url=source_url,source_name=source_name))
|
1144 |
html = Template(html).substitute(dict(product=product,date=date,url=url,source_url=source_url,source_name=source_name))
|
| 1133 |
|
1145 |
|
| 1134 |
try:
|
1146 |
try:
|
| 1135 |
helper_client = HelperClient().get_client()
|
1147 |
helper_client = HelperClient().get_client()
|
| 1136 |
helper_client.saveUserEmailForSending([email], "", "Product requested by you is available now.", html, str(itemId), "ProductNotification", [], [])
|
1148 |
helper_client.saveUserEmailForSending([email], "", "Product requested by you is available now.", html, str(itemId), "ProductNotification", [], [])
|
| 1137 |
except Exception as e:
|
1149 |
except Exception as e:
|
| 1138 |
print e
|
1150 |
print e
|
| Line 1143... |
Line 1155... |
| 1143 |
|
1155 |
|
| 1144 |
def get_item_pricing_by_source(itemId, sourceId):
|
1156 |
def get_item_pricing_by_source(itemId, sourceId):
|
| 1145 |
item = Item.query.filter_by(id=itemId).first()
|
1157 |
item = Item.query.filter_by(id=itemId).first()
|
| 1146 |
if item is None:
|
1158 |
if item is None:
|
| 1147 |
raise InventoryServiceException(101, "Bad Item")
|
1159 |
raise InventoryServiceException(101, "Bad Item")
|
| 1148 |
|
1160 |
|
| 1149 |
source = Source.query.filter_by(id=sourceId).first()
|
1161 |
source = Source.query.filter_by(id=sourceId).first()
|
| 1150 |
if source is None:
|
1162 |
if source is None:
|
| 1151 |
raise InventoryServiceException(101, "Source not found for sourceId " + str(sourceId))
|
1163 |
raise InventoryServiceException(101, "Source not found for sourceId " + str(sourceId))
|
| 1152 |
|
1164 |
|
| 1153 |
item_pricing = SourceItemPricing.query.filter_by(source=source, item=item).first()
|
1165 |
item_pricing = SourceItemPricing.query.filter_by(source=source, item=item).first()
|
| 1154 |
if item_pricing is None:
|
1166 |
if item_pricing is None:
|
| 1155 |
raise InventoryServiceException(101, "Pricing information not found for sourceId " + str(sourceId))
|
1167 |
raise InventoryServiceException(101, "Pricing information not found for sourceId " + str(sourceId))
|
| 1156 |
return item_pricing
|
1168 |
return item_pricing
|
| 1157 |
|
1169 |
|
| 1158 |
def add_source_item_pricing(sourceItemPricing):
|
1170 |
def add_source_item_pricing(sourceItemPricing):
|
| 1159 |
if not sourceItemPricing:
|
1171 |
if not sourceItemPricing:
|
| 1160 |
raise InventoryServiceException(108, "Bad sourceItemPricing in request")
|
1172 |
raise InventoryServiceException(108, "Bad sourceItemPricing in request")
|
| 1161 |
|
1173 |
|
| 1162 |
if not sourceItemPricing.sellingPrice:
|
1174 |
if not sourceItemPricing.sellingPrice:
|
| 1163 |
raise InventoryServiceException(101, "Selling Price is not defined for sourceId " + str(sourceItemPricing.sourceId))
|
1175 |
raise InventoryServiceException(101, "Selling Price is not defined for sourceId " + str(sourceItemPricing.sourceId))
|
| 1164 |
|
1176 |
|
| 1165 |
sourceId = sourceItemPricing.sourceId
|
1177 |
sourceId = sourceItemPricing.sourceId
|
| 1166 |
itemId = sourceItemPricing.itemId
|
1178 |
itemId = sourceItemPricing.itemId
|
| 1167 |
|
1179 |
|
| 1168 |
item = Item.query.filter_by(id=itemId).first()
|
1180 |
item = Item.query.filter_by(id=itemId).first()
|
| 1169 |
if item is None:
|
1181 |
if item is None:
|
| 1170 |
raise InventoryServiceException(101, "Bad Item")
|
1182 |
raise InventoryServiceException(101, "Bad Item")
|
| 1171 |
|
1183 |
|
| 1172 |
source = Source.query.filter_by(id=sourceId).first()
|
1184 |
source = Source.query.filter_by(id=sourceId).first()
|
| 1173 |
if source is None:
|
1185 |
if source is None:
|
| 1174 |
raise InventoryServiceException(101, "Source not found for sourceId " + str(sourceId))
|
1186 |
raise InventoryServiceException(101, "Source not found for sourceId " + str(sourceId))
|
| 1175 |
|
1187 |
|
| 1176 |
ds_sourceItemPricing = SourceItemPricing.get_by(source=source, item=item)
|
1188 |
ds_sourceItemPricing = SourceItemPricing.get_by(source=source, item=item)
|
| 1177 |
if ds_sourceItemPricing is None:
|
1189 |
if ds_sourceItemPricing is None:
|
| 1178 |
ds_sourceItemPricing = SourceItemPricing()
|
1190 |
ds_sourceItemPricing = SourceItemPricing()
|
| 1179 |
ds_sourceItemPricing.source = source
|
1191 |
ds_sourceItemPricing.source = source
|
| 1180 |
ds_sourceItemPricing.item = item
|
1192 |
ds_sourceItemPricing.item = item
|
| 1181 |
|
1193 |
|
| 1182 |
if sourceItemPricing.mrp:
|
1194 |
if sourceItemPricing.mrp:
|
| 1183 |
ds_sourceItemPricing.mrp = sourceItemPricing.mrp
|
1195 |
ds_sourceItemPricing.mrp = sourceItemPricing.mrp
|
| 1184 |
ds_sourceItemPricing.sellingPrice = sourceItemPricing.sellingPrice
|
1196 |
ds_sourceItemPricing.sellingPrice = sourceItemPricing.sellingPrice
|
| 1185 |
|
1197 |
|
| 1186 |
session.commit()
|
1198 |
session.commit()
|
| Line 1190... |
Line 1202... |
| 1190 |
item = Item.query.filter_by(id=itemId).first()
|
1202 |
item = Item.query.filter_by(id=itemId).first()
|
| 1191 |
if item is None:
|
1203 |
if item is None:
|
| 1192 |
raise InventoryServiceException(101, "Bad Item")
|
1204 |
raise InventoryServiceException(101, "Bad Item")
|
| 1193 |
source_pricing = SourceItemPricing.query.filter_by(item=item).all()
|
1205 |
source_pricing = SourceItemPricing.query.filter_by(item=item).all()
|
| 1194 |
return source_pricing
|
1206 |
return source_pricing
|
| 1195 |
|
1207 |
|
| 1196 |
|
1208 |
|
| 1197 |
def get_item_for_source(item_id, sourceId):
|
1209 |
def get_item_for_source(item_id, sourceId):
|
| 1198 |
item = get_item(item_id)
|
1210 |
item = get_item(item_id)
|
| 1199 |
if sourceId == -1:
|
1211 |
if sourceId == -1:
|
| 1200 |
return item
|
1212 |
return item
|
| Line 1207... |
Line 1219... |
| 1207 |
print "No source pricing"
|
1219 |
print "No source pricing"
|
| 1208 |
return item
|
1220 |
return item
|
| 1209 |
|
1221 |
|
| 1210 |
def search_items(search_terms, offset, limit):
|
1222 |
def search_items(search_terms, offset, limit):
|
| 1211 |
query = Item.query
|
1223 |
query = Item.query
|
| 1212 |
|
1224 |
|
| 1213 |
search_terms = ['%' + search_term + '%' for search_term in search_terms]
|
1225 |
search_terms = ['%' + search_term + '%' for search_term in search_terms]
|
| 1214 |
|
1226 |
|
| 1215 |
for search_term in search_terms:
|
1227 |
for search_term in search_terms:
|
| 1216 |
query_clause = []
|
1228 |
query_clause = []
|
| 1217 |
query_clause.append(Item.brand.like(search_term))
|
1229 |
query_clause.append(Item.brand.like(search_term))
|
| 1218 |
query_clause.append(Item.model_number.like(search_term))
|
1230 |
query_clause.append(Item.model_number.like(search_term))
|
| 1219 |
query_clause.append(Item.model_name.like(search_term))
|
1231 |
query_clause.append(Item.model_name.like(search_term))
|
| 1220 |
query = query.filter(or_(*query_clause))
|
1232 |
query = query.filter(or_(*query_clause))
|
| 1221 |
|
1233 |
|
| 1222 |
query = query.order_by(Item.product_group, Item.brand, Item.model_number, Item.model_name).offset(offset)
|
1234 |
query = query.order_by(Item.product_group, Item.brand, Item.model_number, Item.model_name).offset(offset)
|
| 1223 |
if limit:
|
1235 |
if limit:
|
| 1224 |
query = query.limit(limit)
|
1236 |
query = query.limit(limit)
|
| 1225 |
items = query.all()
|
1237 |
items = query.all()
|
| 1226 |
return items
|
1238 |
return items
|
| 1227 |
|
1239 |
|
| 1228 |
def get_search_result_count(search_terms):
|
1240 |
def get_search_result_count(search_terms):
|
| 1229 |
query = Item.query
|
1241 |
query = Item.query
|
| 1230 |
|
1242 |
|
| 1231 |
search_terms = ['%' + search_term + '%' for search_term in search_terms]
|
1243 |
search_terms = ['%' + search_term + '%' for search_term in search_terms]
|
| 1232 |
|
1244 |
|
| 1233 |
for search_term in search_terms:
|
1245 |
for search_term in search_terms:
|
| 1234 |
query_clause = []
|
1246 |
query_clause = []
|
| 1235 |
query_clause.append(Item.brand.like(search_term))
|
1247 |
query_clause.append(Item.brand.like(search_term))
|
| 1236 |
query_clause.append(Item.model_number.like(search_term))
|
1248 |
query_clause.append(Item.model_number.like(search_term))
|
| 1237 |
query_clause.append(Item.model_name.like(search_term))
|
1249 |
query_clause.append(Item.model_name.like(search_term))
|
| 1238 |
query = query.filter(or_(*query_clause))
|
1250 |
query = query.filter(or_(*query_clause))
|
| 1239 |
|
1251 |
|
| 1240 |
return query.count()
|
1252 |
return query.count()
|
| 1241 |
|
1253 |
|
| 1242 |
def __clear_homepage_cache():
|
1254 |
def __clear_homepage_cache():
|
| 1243 |
try:
|
1255 |
try:
|
| 1244 |
# create a password manager
|
1256 |
# create a password manager
|
| 1245 |
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
1257 |
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
| 1246 |
# Add the username and password.
|
1258 |
# Add the username and password.
|
| 1247 |
configclient = ConfigClient()
|
1259 |
configclient = ConfigClient()
|
| 1248 |
ips = configclient.get_property("production_servers_private_ips");
|
1260 |
ips = configclient.get_property("production_servers_private_ips");
|
| 1249 |
ips = ips.split(" ")
|
1261 |
ips = ips.split(" ")
|
| 1250 |
|
1262 |
|
| 1251 |
for ip in ips:
|
1263 |
for ip in ips:
|
| 1252 |
try:
|
1264 |
try:
|
| 1253 |
top_level_url = "http://" + ip + ":8080/"
|
1265 |
top_level_url = "http://" + ip + ":8080/"
|
| 1254 |
password_mgr.add_password(None, top_level_url, "saholic", "shop2020")
|
1266 |
password_mgr.add_password(None, top_level_url, "saholic", "shop2020")
|
| 1255 |
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
|
1267 |
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
|
| 1256 |
|
1268 |
|
| 1257 |
opener = urllib2.build_opener(handler)
|
1269 |
opener = urllib2.build_opener(handler)
|
| 1258 |
|
1270 |
|
| 1259 |
# use the opener to fetch a URL
|
1271 |
# use the opener to fetch a URL
|
| 1260 |
res = opener.open(top_level_url + "cache-admin/HomePageSnippets?_method=delete")
|
1272 |
res = opener.open(top_level_url + "cache-admin/HomePageSnippets?_method=delete")
|
| 1261 |
print "Successfully cleared home page cache" + res.read()
|
1273 |
print "Successfully cleared home page cache" + res.read()
|
| 1262 |
except:
|
1274 |
except:
|
| 1263 |
print "Unable to clear home page cache" + res.read()
|
1275 |
print "Unable to clear home page cache" + res.read()
|
| 1264 |
except:
|
1276 |
except:
|
| 1265 |
print "Unable to clear cache, still should continue with other operations"
|
1277 |
print "Unable to clear cache, still should continue with other operations"
|
| 1266 |
|
1278 |
|
| 1267 |
def get_product_notifications(start_datetime):
|
1279 |
def get_product_notifications(start_datetime):
|
| 1268 |
'''
|
1280 |
'''
|
| 1269 |
Returns a list of Product Notification objects each representing user requests for notification
|
1281 |
Returns a list of Product Notification objects each representing user requests for notification
|
| 1270 |
'''
|
1282 |
'''
|
| 1271 |
query = ProductNotification.query
|
1283 |
query = ProductNotification.query
|
| 1272 |
|
1284 |
|
| 1273 |
if start_datetime:
|
1285 |
if start_datetime:
|
| 1274 |
query = query.filter(ProductNotification.addedOn > start_datetime)
|
1286 |
query = query.filter(ProductNotification.addedOn > start_datetime)
|
| 1275 |
|
1287 |
|
| 1276 |
notifications = query.order_by(desc('addedOn')).all()
|
1288 |
notifications = query.order_by(desc('addedOn')).all()
|
| 1277 |
return notifications
|
1289 |
return notifications
|
| 1278 |
|
1290 |
|
| 1279 |
def get_product_notification_request_count(start_datetime):
|
1291 |
def get_product_notification_request_count(start_datetime):
|
| 1280 |
'''
|
1292 |
'''
|
| 1281 |
Returns list of items and the counts of product notification requests
|
1293 |
Returns list of items and the counts of product notification requests
|
| 1282 |
'''
|
1294 |
'''
|
| 1283 |
print start_datetime
|
1295 |
print start_datetime
|
| 1284 |
query = session.query(ProductNotification, func.count(ProductNotification.email).label('count'))
|
1296 |
query = session.query(ProductNotification, func.count(ProductNotification.email).label('count'))
|
| 1285 |
|
1297 |
|
| 1286 |
if start_datetime:
|
1298 |
if start_datetime:
|
| 1287 |
query = query.filter(ProductNotification.addedOn > start_datetime)
|
1299 |
query = query.filter(ProductNotification.addedOn > start_datetime)
|
| 1288 |
|
1300 |
|
| 1289 |
counts = query.group_by(ProductNotification.item_id).order_by(desc('count')).all()
|
1301 |
counts = query.group_by(ProductNotification.item_id).order_by(desc('count')).all()
|
| 1290 |
return counts
|
1302 |
return counts
|
| 1291 |
|
1303 |
|
| 1292 |
def close_session():
|
1304 |
def close_session():
|
| 1293 |
if session.is_active:
|
1305 |
if session.is_active:
|
| Line 1332... |
Line 1344... |
| 1332 |
def __send_mail(subject, message, send_to = to_addresses):
|
1344 |
def __send_mail(subject, message, send_to = to_addresses):
|
| 1333 |
try:
|
1345 |
try:
|
| 1334 |
thread = threading.Thread(target=partial(mail, mail_user, mail_password, send_to, subject, message))
|
1346 |
thread = threading.Thread(target=partial(mail, mail_user, mail_password, send_to, subject, message))
|
| 1335 |
thread.start()
|
1347 |
thread.start()
|
| 1336 |
except Exception as ex:
|
1348 |
except Exception as ex:
|
| 1337 |
print ex
|
1349 |
print ex
|
| 1338 |
|
1350 |
|
| 1339 |
def get_vat_amount_for_item(itemId, price):
|
1351 |
def get_vat_amount_for_item(itemId, price):
|
| 1340 |
item = Item.query.filter_by(id=itemId).first()
|
1352 |
item = Item.query.filter_by(id=itemId).first()
|
| 1341 |
vatPercentage = item.vatPercentage
|
1353 |
vatPercentage = item.vatPercentage
|
| 1342 |
if vatPercentage is None:
|
1354 |
if vatPercentage is None:
|
| 1343 |
vatMaster = CategoryVatMaster.query.filter(and_(CategoryVatMaster.categoryId==item.category, CategoryVatMaster.minVal<=price, CategoryVatMaster.maxVal>=price)).first()
|
1355 |
vatMaster = CategoryVatMaster.query.filter(and_(CategoryVatMaster.categoryId==item.category, CategoryVatMaster.minVal<=price, CategoryVatMaster.maxVal>=price)).first()
|
| 1344 |
vatPercentage = vatMaster.vatPercent
|
1356 |
vatPercentage = vatMaster.vatPercent
|
| 1345 |
if vatPercentage is None:
|
1357 |
if vatPercentage is None:
|
| 1346 |
vatPercentage = 0
|
1358 |
vatPercentage = 0
|
| 1347 |
return (price*vatPercentage)/100
|
1359 |
return (price*vatPercentage)/100
|
| 1348 |
|
1360 |
|
| 1349 |
def get_vat_percentage_for_item(itemId, stateId, price):
|
1361 |
def get_vat_percentage_for_item(itemId, stateId, price):
|
| 1350 |
itemVatMaster = ItemVatMaster.query.filter(and_(ItemVatMaster.itemId==itemId, ItemVatMaster.stateId==stateId)).first()
|
1362 |
itemVatMaster = ItemVatMaster.query.filter(and_(ItemVatMaster.itemId==itemId, ItemVatMaster.stateId==stateId)).first()
|
| 1351 |
if itemVatMaster is None:
|
1363 |
if itemVatMaster is None:
|
| 1352 |
item = Item.query.filter_by(id=itemId).first()
|
1364 |
item = Item.query.filter_by(id=itemId).first()
|
| 1353 |
if item is None:
|
1365 |
if item is None:
|
| Line 1370... |
Line 1382... |
| 1370 |
return result
|
1382 |
return result
|
| 1371 |
|
1383 |
|
| 1372 |
|
1384 |
|
| 1373 |
def add_tag (displayName, catalogId):
|
1385 |
def add_tag (displayName, catalogId):
|
| 1374 |
ent_tag = None
|
1386 |
ent_tag = None
|
| 1375 |
if catalogId is None or (not is_valid_catalog_id(catalogId)):
|
1387 |
if catalogId is None or (not is_valid_catalog_id(catalogId)):
|
| 1376 |
raise InventoryServiceException(id, "Invalid CatalogId")
|
1388 |
raise InventoryServiceException(id, "Invalid CatalogId")
|
| 1377 |
else:
|
1389 |
else:
|
| 1378 |
ent_tag = EntityTag()
|
1390 |
ent_tag = EntityTag()
|
| 1379 |
ent_tag.entityId = catalogId
|
1391 |
ent_tag.entityId = catalogId
|
| 1380 |
if displayName is None:
|
1392 |
if displayName is None:
|
| 1381 |
raise InventoryServiceException(id, "Tag should not be empty")
|
1393 |
raise InventoryServiceException(id, "Tag should not be empty")
|
| 1382 |
else:
|
1394 |
else:
|
| 1383 |
ent_tag.tag = displayName
|
1395 |
ent_tag.tag = displayName
|
| 1384 |
session.commit()
|
1396 |
session.commit()
|
| 1385 |
return True
|
1397 |
return True
|
| 1386 |
|
1398 |
|
| 1387 |
def add_banner(bannerName, imageName,link, priority, isActive, hasMap):
|
1399 |
def add_banner(bannerName, imageName,link, priority, isActive, hasMap):
|
| Line 1403... |
Line 1415... |
| 1403 |
session.commit()
|
1415 |
session.commit()
|
| 1404 |
return True
|
1416 |
return True
|
| 1405 |
|
1417 |
|
| 1406 |
def get_banner_details(name):
|
1418 |
def get_banner_details(name):
|
| 1407 |
banner = Banner.get_by(bannerName=name)
|
1419 |
banner = Banner.get_by(bannerName=name)
|
| 1408 |
return banner
|
1420 |
return banner
|
| 1409 |
|
1421 |
|
| 1410 |
def get_active_banners():
|
1422 |
def get_active_banners():
|
| 1411 |
print "Data accessor"
|
1423 |
print "Data accessor"
|
| 1412 |
query= session.query(Banner)
|
1424 |
query= session.query(Banner)
|
| 1413 |
banner= query.filter_by(isActive =True).order_by(desc(Banner.priority)).all()
|
1425 |
banner= query.filter_by(isActive =True).order_by(desc(Banner.priority)).all()
|
| Line 1433... |
Line 1445... |
| 1433 |
query= session.query(BannerMap)
|
1445 |
query= session.query(BannerMap)
|
| 1434 |
bannermap= query.filter_by(bannerName=name).all()
|
1446 |
bannermap= query.filter_by(bannerName=name).all()
|
| 1435 |
print "Banner is",
|
1447 |
print "Banner is",
|
| 1436 |
print bannermap
|
1448 |
print bannermap
|
| 1437 |
return bannermap
|
1449 |
return bannermap
|
| 1438 |
|
1450 |
|
| 1439 |
def get_all_tags ():
|
1451 |
def get_all_tags ():
|
| 1440 |
return [tuple[0] for tuple in session.query(EntityTag.tag).distinct().all()]
|
1452 |
return [tuple[0] for tuple in session.query(EntityTag.tag).distinct().all()]
|
| 1441 |
|
1453 |
|
| 1442 |
def get_all_entities_by_tag_name(displayName):
|
1454 |
def get_all_entities_by_tag_name(displayName):
|
| 1443 |
return [tuple[0] for tuple in session.query(EntityTag.entityId).filter_by(tag=displayName).all()]
|
1455 |
return [tuple[0] for tuple in session.query(EntityTag.entityId).filter_by(tag=displayName).all()]
|
| 1444 |
|
1456 |
|
| 1445 |
def delete_tag(displayName):
|
1457 |
def delete_tag(displayName):
|
| 1446 |
session.query(EntityTag.entityId).filter_by(tag=displayName).delete()
|
1458 |
session.query(EntityTag.entityId).filter_by(tag=displayName).delete()
|
| 1447 |
session.commit()
|
1459 |
session.commit()
|
| 1448 |
return True
|
1460 |
return True
|
| 1449 |
|
1461 |
|
| Line 1460... |
Line 1472... |
| 1460 |
insuranceAmount = 0.0
|
1472 |
insuranceAmount = 0.0
|
| 1461 |
if itemInsurerMapping.premiumType == PremiumType._NAMES_TO_VALUES.get("PERCENT"):
|
1473 |
if itemInsurerMapping.premiumType == PremiumType._NAMES_TO_VALUES.get("PERCENT"):
|
| 1462 |
insuranceAmount = price * (itemInsurerMapping.premiumAmount/100) * quantity
|
1474 |
insuranceAmount = price * (itemInsurerMapping.premiumAmount/100) * quantity
|
| 1463 |
else :
|
1475 |
else :
|
| 1464 |
insuranceAmount = itemInsurerMapping.premiumAmount * quantity
|
1476 |
insuranceAmount = itemInsurerMapping.premiumAmount * quantity
|
| 1465 |
|
1477 |
|
| 1466 |
return insuranceAmount
|
1478 |
return insuranceAmount
|
| 1467 |
|
1479 |
|
| 1468 |
def get_insurer(insurerId):
|
1480 |
def get_insurer(insurerId):
|
| 1469 |
return Insurer.get_by(id = insurerId)
|
1481 |
return Insurer.get_by(id = insurerId)
|
| 1470 |
|
1482 |
|
| 1471 |
def get_all_entity_tags():
|
1483 |
def get_all_entity_tags():
|
| 1472 |
entitiesTag = EntityTag.query.all()
|
1484 |
entitiesTag = EntityTag.query.all()
|
| 1473 |
entityMap = {}
|
1485 |
entityMap = {}
|
| 1474 |
for e in entitiesTag:
|
1486 |
for e in entitiesTag:
|
| 1475 |
if not entityMap.has_key(e.entityId):
|
1487 |
if not entityMap.has_key(e.entityId):
|
| 1476 |
entityMap[e.entityId] = []
|
1488 |
entityMap[e.entityId] = []
|
| 1477 |
entityMap[e.entityId].append(e.tag)
|
1489 |
entityMap[e.entityId].append(e.tag)
|
| 1478 |
return entityMap
|
1490 |
return entityMap
|
| 1479 |
|
1491 |
|
| 1480 |
|
1492 |
|
| 1481 |
def get_all_insurers():
|
1493 |
def get_all_insurers():
|
| 1482 |
print session.query(Insurer).all()
|
1494 |
print session.query(Insurer).all()
|
| 1483 |
return session.query(Insurer).all()
|
1495 |
return session.query(Insurer).all()
|
| 1484 |
|
1496 |
|
| 1485 |
def update_insurance_declared_amount(insurerId, amount):
|
1497 |
def update_insurance_declared_amount(insurerId, amount):
|
| 1486 |
insurer = Insurer.get_by(id = insurerId)
|
1498 |
insurer = Insurer.get_by(id = insurerId)
|
| 1487 |
insurer.declaredAmount += amount
|
1499 |
insurer.declaredAmount += amount
|
| 1488 |
session.commit()
|
1500 |
session.commit()
|
| 1489 |
if insurer.declaredAmount > 0.9*insurer.creditedAmount:
|
1501 |
if insurer.declaredAmount > 0.9*insurer.creditedAmount:
|
| 1490 |
__send_mail("CRITICAL: Declared Insurance Amount is critical (Declared Amount - " + str(insurer.declaredAmount) + " and Credited Amount - " + str(insurer.creditedAmount) +")", "Please top up credited amount")
|
1502 |
__send_mail("CRITICAL: Declared Insurance Amount is critical (Declared Amount - " + str(insurer.declaredAmount) + " and Credited Amount - " + str(insurer.creditedAmount) +")", "Please top up credited amount")
|
| 1491 |
elif insurer.declaredAmount > 0.8*insurer.creditedAmount:
|
1503 |
elif insurer.declaredAmount > 0.8*insurer.creditedAmount:
|
| 1492 |
__send_mail("WARNING: Declared Insurance Amount is warning (Declared Amount - " + str(insurer.declaredAmount) + " and Credited Amount - " + str(insurer.creditedAmount) +")", "Please top up credited amount")
|
1504 |
__send_mail("WARNING: Declared Insurance Amount is warning (Declared Amount - " + str(insurer.declaredAmount) + " and Credited Amount - " + str(insurer.creditedAmount) +")", "Please top up credited amount")
|
| 1493 |
|
1505 |
|
| 1494 |
def get_freebie_for_item(itemId):
|
1506 |
def get_freebie_for_item(itemId):
|
| 1495 |
freebie = FreebieItem.get_by(itemId = itemId)
|
1507 |
freebie = FreebieItem.get_by(itemId = itemId)
|
| 1496 |
if freebie is None:
|
1508 |
if freebie is None:
|
| 1497 |
return 0
|
1509 |
return 0
|
| 1498 |
else:
|
1510 |
else:
|
| 1499 |
return freebie.freebieItemId
|
1511 |
return freebie.freebieItemId
|
| 1500 |
|
1512 |
|
| 1501 |
def add_or_update_freebie_for_item(freebieItem):
|
1513 |
def add_or_update_freebie_for_item(freebieItem):
|
| 1502 |
freebie = FreebieItem.get_by(itemId = freebieItem.itemId)
|
1514 |
freebie = FreebieItem.get_by(itemId = freebieItem.itemId)
|
| 1503 |
if freebie is None:
|
1515 |
if freebie is None:
|
| 1504 |
freebie = FreebieItem()
|
1516 |
freebie = FreebieItem()
|
| 1505 |
freebie.itemId = freebieItem.itemId
|
1517 |
freebie.itemId = freebieItem.itemId
|
| Line 1512... |
Line 1524... |
| 1512 |
if brandinfo is None:
|
1524 |
if brandinfo is None:
|
| 1513 |
brandinfo = BrandInfo()
|
1525 |
brandinfo = BrandInfo()
|
| 1514 |
brandinfo.itemId = brandInfo.itemId
|
1526 |
brandinfo.itemId = brandInfo.itemId
|
| 1515 |
brandinfo.freebieItemId = brandInfo.freebieItemId
|
1527 |
brandinfo.freebieItemId = brandInfo.freebieItemId
|
| 1516 |
session.commit()
|
1528 |
session.commit()
|
| 1517 |
|
1529 |
|
| 1518 |
def get_brand_info():
|
1530 |
def get_brand_info():
|
| 1519 |
brandInfoMap = dict()
|
1531 |
brandInfoMap = dict()
|
| 1520 |
brandInfoList = FreebieItem.query.all()
|
1532 |
brandInfoList = FreebieItem.query.all()
|
| 1521 |
for brandInfo in brandInfoList:
|
1533 |
for brandInfo in brandInfoList:
|
| 1522 |
brandInfoMap[brandInfo.name] = to_t_brand_info(brandInfo)
|
1534 |
brandInfoMap[brandInfo.name] = to_t_brand_info(brandInfo)
|
| Line 1542... |
Line 1554... |
| 1542 |
sp.item_id = item.id
|
1554 |
sp.item_id = item.id
|
| 1543 |
sp.freebieItemId = tsp.freebieItemId
|
1555 |
sp.freebieItemId = tsp.freebieItemId
|
| 1544 |
sp.bestDealText = tsp.bestDealText
|
1556 |
sp.bestDealText = tsp.bestDealText
|
| 1545 |
sp.absoluteMinPrice = tsp.absoluteMinPrice
|
1557 |
sp.absoluteMinPrice = tsp.absoluteMinPrice
|
| 1546 |
session.commit()
|
1558 |
session.commit()
|
| 1547 |
|
1559 |
|
| 1548 |
|
1560 |
|
| 1549 |
def validate_store_pricing(tsp):
|
1561 |
def validate_store_pricing(tsp):
|
| 1550 |
if tsp.minPrice > tsp.maxPrice:
|
1562 |
if tsp.minPrice > tsp.maxPrice:
|
| 1551 |
raise InventoryServiceException(101, "DP is more than MRP")
|
1563 |
raise InventoryServiceException(101, "DP is more than MRP")
|
| 1552 |
|
1564 |
|
| 1553 |
item = get_item(tsp.itemId)
|
1565 |
item = get_item(tsp.itemId)
|
| 1554 |
|
1566 |
|
| 1555 |
if item.mrp and tsp.maxPrice > item.mrp:
|
1567 |
if item.mrp and tsp.maxPrice > item.mrp:
|
| 1556 |
raise InventoryServiceException(101, "MRP is more than Saholic MRP")
|
1568 |
raise InventoryServiceException(101, "MRP is more than Saholic MRP")
|
| 1557 |
|
- |
|
| 1558 |
if tsp.recommendedPrice < item.sellingPrice:
|
- |
|
| 1559 |
raise InventoryServiceException(101, "MOP is less than Saholic MOP.")
|
- |
|
| 1560 |
|
1569 |
|
| - |
|
1570 |
if tsp.recommendedPrice < item.sellingPrice:
|
| - |
|
1571 |
raise InventoryServiceException(101, "MOP is less than Saholic MOP.")
|
| - |
|
1572 |
|
| 1561 |
if tsp.recommendedPrice < tsp.minPrice or tsp.recommendedPrice > tsp.maxPrice:
|
1573 |
if tsp.recommendedPrice < tsp.minPrice or tsp.recommendedPrice > tsp.maxPrice:
|
| 1562 |
raise InventoryServiceException(101, "MOP price must be in the range")
|
1574 |
raise InventoryServiceException(101, "MOP price must be in the range")
|
| 1563 |
|
1575 |
|
| 1564 |
if tsp.minPrice < item.sellingPrice:
|
1576 |
if tsp.minPrice < item.sellingPrice:
|
| 1565 |
store_message = "Saholic MOP Changed. DP {0} is less than Saholic MOP.\n".format(tsp.minPrice)
|
1577 |
store_message = "Saholic MOP Changed. DP {0} is less than Saholic MOP.\n".format(tsp.minPrice)
|
| 1566 |
subject = "Item '{0}' is updated in Catalog. Id is {1}".format(__get_product_name(item),item.id)
|
1578 |
subject = "Item '{0}' is updated in Catalog. Id is {1}".format(__get_product_name(item),item.id)
|
| 1567 |
__send_mail(subject, store_message, to_store_addresses)
|
1579 |
__send_mail(subject, store_message, to_store_addresses)
|
| 1568 |
|
1580 |
|
| 1569 |
return True
|
1581 |
return True
|
| 1570 |
|
1582 |
|
| 1571 |
|
1583 |
|
| 1572 |
|
1584 |
|
| 1573 |
def get_defalut_store_pricing(itemId):
|
1585 |
def get_defalut_store_pricing(itemId):
|
| 1574 |
inventoryClient = InventoryClient().get_client()
|
1586 |
inventoryClient = InventoryClient().get_client()
|
| 1575 |
pricings = inventoryClient.getAllItemPricing(itemId)
|
1587 |
pricings = inventoryClient.getAllItemPricing(itemId)
|
| 1576 |
item = get_item(itemId)
|
1588 |
item = get_item(itemId)
|
| 1577 |
maxp = item.sellingPrice
|
1589 |
maxp = item.sellingPrice
|
| 1578 |
if item.mrp:
|
1590 |
if item.mrp:
|
| 1579 |
maxp = item.mrp
|
1591 |
maxp = item.mrp
|
| 1580 |
|
1592 |
|
| 1581 |
minp = 0
|
1593 |
minp = 0
|
| 1582 |
rp = item.sellingPrice
|
1594 |
rp = item.sellingPrice
|
| 1583 |
for pricing in pricings:
|
1595 |
for pricing in pricings:
|
| 1584 |
if not minp or minp > pricing.dealerPrice:
|
1596 |
if not minp or minp > pricing.dealerPrice:
|
| 1585 |
minp = pricing.dealerPrice
|
1597 |
minp = pricing.dealerPrice
|
| 1586 |
|
- |
|
| 1587 |
|
1598 |
|
| - |
|
1599 |
|
| 1588 |
minap = math.ceil(min(max(500, rp*0.1),rp))
|
1600 |
minap = math.ceil(min(max(500, rp*0.1),rp))
|
| 1589 |
|
1601 |
|
| 1590 |
if minp > rp:
|
1602 |
if minp > rp:
|
| 1591 |
minp = rp
|
1603 |
minp = rp
|
| 1592 |
sp = tStorePricing()
|
1604 |
sp = tStorePricing()
|
| Line 1597... |
Line 1609... |
| 1597 |
sp.minAdvancePrice = minap
|
1609 |
sp.minAdvancePrice = minap
|
| 1598 |
sp.maxPrice = maxp
|
1610 |
sp.maxPrice = maxp
|
| 1599 |
sp.freebieItemId = 0
|
1611 |
sp.freebieItemId = 0
|
| 1600 |
sp.bestDealText = ""
|
1612 |
sp.bestDealText = ""
|
| 1601 |
return sp
|
1613 |
return sp
|
| 1602 |
|
1614 |
|
| 1603 |
|
1615 |
|
| 1604 |
def get_store_pricing(itemId):
|
1616 |
def get_store_pricing(itemId):
|
| 1605 |
store = StorePricing.get_by(item_id = itemId)
|
1617 |
store = StorePricing.get_by(item_id = itemId)
|
| 1606 |
if store is None:
|
1618 |
if store is None:
|
| 1607 |
return get_defalut_store_pricing(itemId)
|
1619 |
return get_defalut_store_pricing(itemId)
|
| 1608 |
|
1620 |
|
| 1609 |
sp = tStorePricing()
|
1621 |
sp = tStorePricing()
|
| 1610 |
sp.itemId = itemId
|
1622 |
sp.itemId = itemId
|
| 1611 |
sp.recommendedPrice = store.recommendedPrice
|
1623 |
sp.recommendedPrice = store.recommendedPrice
|
| 1612 |
sp.minPrice = store.minPrice
|
1624 |
sp.minPrice = store.minPrice
|
| 1613 |
sp.minAdvancePrice = store.minAdvancePrice
|
1625 |
sp.minAdvancePrice = store.minAdvancePrice
|
| 1614 |
sp.maxPrice = store.maxPrice
|
1626 |
sp.maxPrice = store.maxPrice
|
| 1615 |
sp.absoluteMinPrice = store.absoluteMinPrice
|
1627 |
sp.absoluteMinPrice = store.absoluteMinPrice
|
| Line 1624... |
Line 1636... |
| 1624 |
amazonlisted = Amazonlisted.get_by(itemId=amazonItemId)
|
1636 |
amazonlisted = Amazonlisted.get_by(itemId=amazonItemId)
|
| 1625 |
return amazonlisted
|
1637 |
return amazonlisted
|
| 1626 |
|
1638 |
|
| 1627 |
def update_amazon_item_details(amazonItemId,fbaPrice,sellingPrice,isFba,isNonFba,isInventoryOverride,handlingTime,isCustomTime):
|
1639 |
def update_amazon_item_details(amazonItemId,fbaPrice,sellingPrice,isFba,isNonFba,isInventoryOverride,handlingTime,isCustomTime):
|
| 1628 |
amazonlisted = Amazonlisted.get_by(itemId = amazonItemId)
|
1640 |
amazonlisted = Amazonlisted.get_by(itemId = amazonItemId)
|
| 1629 |
amazonlisted.fbaPrice=fbaPrice
|
- |
|
| 1630 |
amazonlisted.sellingPrice=sellingPrice
|
- |
|
| 1631 |
amazonlisted.isFba=isFba
|
1641 |
amazonlisted.isFba=isFba
|
| 1632 |
amazonlisted.isNonFba=isNonFba
|
1642 |
amazonlisted.isNonFba=isNonFba
|
| 1633 |
amazonlisted.isInventoryOverride=isInventoryOverride
|
1643 |
amazonlisted.isInventoryOverride=isInventoryOverride
|
| 1634 |
amazonlisted.handlingTime=handlingTime
|
1644 |
amazonlisted.handlingTime=handlingTime
|
| 1635 |
amazonlisted.isCustomTime=isCustomTime
|
1645 |
amazonlisted.isCustomTime=isCustomTime
|
| - |
|
1646 |
if amazonlisted.sellingPrice != sellingPrice:
|
| - |
|
1647 |
amazonlisted.mfnPriceLastUpdatedOn = datetime.datetime.now()
|
| - |
|
1648 |
amazonlisted.sellingPrice=sellingPrice
|
| - |
|
1649 |
if amazonlisted.fbaPrice != fbaPrice:
|
| - |
|
1650 |
amazonlisted.fbaPriceLastUpdatedOn = datetime.datetime.now()
|
| - |
|
1651 |
amazonlisted.fbaPrice=fbaPrice
|
| 1636 |
session.commit()
|
1652 |
session.commit()
|
| 1637 |
|
1653 |
|
| 1638 |
def add_amazon_item(amazonlisted):
|
1654 |
def add_amazon_item(amazonlisted):
|
| 1639 |
if (not amazonlisted) or (not amazonlisted.itemid) or (not amazonlisted.asin):
|
1655 |
if (not amazonlisted) or (not amazonlisted.itemid) or (not amazonlisted.asin):
|
| 1640 |
return
|
1656 |
return
|
| 1641 |
amazonItem = Amazonlisted.get_by(itemId=amazonlisted.itemid)
|
1657 |
amazonItem = Amazonlisted.get_by(itemId=amazonlisted.itemid)
|
| 1642 |
if amazonItem is None:
|
1658 |
if amazonItem is None:
|
| Line 1671... |
Line 1687... |
| 1671 |
amazon_item.ean=''
|
1687 |
amazon_item.ean=''
|
| 1672 |
if amazonlisted.upc:
|
1688 |
if amazonlisted.upc:
|
| 1673 |
amazon_item.upc=amazonlisted.upc
|
1689 |
amazon_item.upc=amazonlisted.upc
|
| 1674 |
else:
|
1690 |
else:
|
| 1675 |
amazon_item.upc=''
|
1691 |
amazon_item.upc=''
|
| 1676 |
if amazonlisted.sellingPrice:
|
- |
|
| 1677 |
amazon_item.sellingPrice=amazonlisted.sellingPrice
|
- |
|
| 1678 |
if amazonlisted.fbaPrice:
|
1692 |
if amazonlisted.fbaPrice:
|
| 1679 |
amazon_item.fbaPrice=amazonlisted.fbaPrice
|
1693 |
amazon_item.fbaPrice=amazonlisted.fbaPrice
|
| - |
|
1694 |
amazon_item.fbaPriceLastUpdatedOn = datetime.datetime.now()
|
| - |
|
1695 |
if amazonlisted.sellingPrice:
|
| - |
|
1696 |
amazon_item.sellingPrice=amazonlisted.sellingPrice
|
| - |
|
1697 |
amazon_item.mfnPriceLastUpdatedOn = datetime.datetime.now()
|
| 1680 |
if amazonlisted.isFba:
|
1698 |
if amazonlisted.isFba:
|
| 1681 |
amazon_item.isFba=amazonlisted.isFba
|
1699 |
amazon_item.isFba=amazonlisted.isFba
|
| 1682 |
if amazonlisted.isNonFba:
|
1700 |
if amazonlisted.isNonFba:
|
| 1683 |
amazon_item.isNonFba=amazonlisted.isNonFba
|
1701 |
amazon_item.isNonFba=amazonlisted.isNonFba
|
| 1684 |
if amazonlisted.isInventoryOverride:
|
1702 |
if amazonlisted.isInventoryOverride:
|
| Line 1721... |
Line 1739... |
| 1721 |
if amazonlisted.upc:
|
1739 |
if amazonlisted.upc:
|
| 1722 |
amazonItem.upc=amazonlisted.upc
|
1740 |
amazonItem.upc=amazonlisted.upc
|
| 1723 |
else:
|
1741 |
else:
|
| 1724 |
amazonItem.upc=''
|
1742 |
amazonItem.upc=''
|
| 1725 |
if amazonlisted.sellingPrice:
|
1743 |
if amazonlisted.sellingPrice:
|
| 1726 |
amazonItem.sellingPrice=amazonlisted.sellingPrice
|
1744 |
amazon_item.sellingPrice=amazonlisted.sellingPrice
|
| - |
|
1745 |
amazonlisted.mfnPriceLastUpdatedOnSc = datetime.datetime.now()
|
| - |
|
1746 |
amazonlisted.mfnPriceLastUpdatedOn = datetime.datetime.now()
|
| 1727 |
if amazonlisted.fbaPrice:
|
1747 |
if amazonlisted.fbaPrice:
|
| 1728 |
amazonItem.fbaPrice=amazonlisted.fbaPrice
|
1748 |
amazon_item.fbaPrice=amazonlisted.fbaPrice
|
| - |
|
1749 |
amazonlisted.fbaPriceLastUpdatedOnSc = datetime.datetime.now()
|
| - |
|
1750 |
amazonlisted.fbaPriceLastUpdatedOn = datetime.datetime.now()
|
| 1729 |
if amazonlisted.isFba:
|
1751 |
if amazonlisted.isFba:
|
| 1730 |
amazonItem.isFba=amazonlisted.isFba
|
1752 |
amazonItem.isFba=amazonlisted.isFba
|
| 1731 |
if amazonlisted.isNonFba:
|
1753 |
if amazonlisted.isNonFba:
|
| 1732 |
amazonItem.isNonFba=amazonlisted.isNonFba
|
1754 |
amazonItem.isNonFba=amazonlisted.isNonFba
|
| 1733 |
if amazonlisted.isInventoryOverride:
|
1755 |
if amazonlisted.isInventoryOverride:
|
| Line 1741... |
Line 1763... |
| 1741 |
else:
|
1763 |
else:
|
| 1742 |
amazonItem.color=''
|
1764 |
amazonItem.color=''
|
| 1743 |
else:
|
1765 |
else:
|
| 1744 |
return
|
1766 |
return
|
| 1745 |
session.commit()
|
1767 |
session.commit()
|
| 1746 |
|
1768 |
|
| 1747 |
def get_asin_items():
|
1769 |
def get_asin_items():
|
| 1748 |
from_date=datetime.datetime.now() - datetime.timedelta(days=10)
|
1770 |
from_date=datetime.datetime.now() - datetime.timedelta(days=10)
|
| 1749 |
return Item.query.filter(Item.updatedOn > from_date).all()
|
1771 |
return Item.query.filter(Item.updatedOn > from_date).all()
|
| 1750 |
|
1772 |
|
| 1751 |
def get_all_fba_listed_items():
|
1773 |
def get_all_fba_listed_items():
|
| 1752 |
return Amazonlisted.query.filter(Amazonlisted.isFba==True).all()
|
1774 |
return Amazonlisted.query.filter(Amazonlisted.isFba==True).all()
|
| 1753 |
|
1775 |
|
| 1754 |
def get_all_nonfba_listed_items():
|
1776 |
def get_all_nonfba_listed_items():
|
| 1755 |
return Amazonlisted.query.filter(Amazonlisted.isNonFba==True).all()
|
1777 |
return Amazonlisted.query.filter(Amazonlisted.isNonFba==True).all()
|
| 1756 |
|
1778 |
|
| 1757 |
def update_item_inventory(itemId,holdInventory,defaultInventory):
|
1779 |
def update_item_inventory(itemId,holdInventory,defaultInventory):
|
| 1758 |
item = get_item(itemId)
|
1780 |
item = get_item(itemId)
|
| 1759 |
item.holdInventory = holdInventory
|
1781 |
item.holdInventory = holdInventory
|
| 1760 |
item.defaultInventory = defaultInventory
|
1782 |
item.defaultInventory = defaultInventory
|
| 1761 |
session.commit()
|
1783 |
session.commit()
|
| - |
|
1784 |
|
| - |
|
1785 |
def update_timestamp_for_amazon_feeds(feedType,skuList,timestamp):
|
| - |
|
1786 |
#amazonListed = get_all_amazon_listed_items()
|
| - |
|
1787 |
fbaItems = []
|
| - |
|
1788 |
mfnItems = []
|
| - |
|
1789 |
if feedType == 'NonFbaPricing':
|
| - |
|
1790 |
items = Amazonlisted.query.filter(Amazonlisted.isNonFba==True).filter(Amazonlisted.mfnPriceLastUpdatedOn > Amazonlisted.mfnPriceLastUpdatedOnSc).all()
|
| - |
|
1791 |
for item in items:
|
| - |
|
1792 |
mfnItems.append(item.itemId)
|
| - |
|
1793 |
listToUpdate = list(set(mfnItems)-set(skuList))
|
| - |
|
1794 |
for sku in listToUpdate:
|
| - |
|
1795 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
| - |
|
1796 |
amazonItem.mfnPriceLastUpdatedOnSc = to_py_date(timestamp)
|
| - |
|
1797 |
session.commit()
|
| - |
|
1798 |
return True
|
| - |
|
1799 |
elif feedType == 'FbaPricing':
|
| - |
|
1800 |
items = Amazonlisted.query.filter(Amazonlisted.isFba==True).filter(Amazonlisted.fbaPriceLastUpdatedOn > Amazonlisted.fbaPriceLastUpdatedOnSc).all()
|
| - |
|
1801 |
for item in items:
|
| - |
|
1802 |
fbaItems.append(item.itemId)
|
| - |
|
1803 |
listToUpdate = list(set(fbaItems)-set(skuList))
|
| - |
|
1804 |
for sku in listToUpdate:
|
| - |
|
1805 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
| - |
|
1806 |
amazonItem.fbaPriceLastUpdatedOnSc = to_py_date(timestamp)
|
| - |
|
1807 |
session.commit()
|
| - |
|
1808 |
return True
|
| - |
|
1809 |
elif feedType== 'FullFbaPricing':
|
| - |
|
1810 |
items = Amazonlisted.query.filter(Amazonlisted.isFba==True).all()
|
| - |
|
1811 |
for item in items:
|
| - |
|
1812 |
fbaItems.append(item.itemId)
|
| - |
|
1813 |
listToUpdate = list(set(fbaItems)-set(skuList))
|
| - |
|
1814 |
for sku in listToUpdate:
|
| - |
|
1815 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
| - |
|
1816 |
amazonItem.fbaPriceLastUpdatedOnSc = to_py_date(timestamp)
|
| - |
|
1817 |
session.commit()
|
| - |
|
1818 |
return True
|
| - |
|
1819 |
elif feedType== 'FullNonFbaPricing':
|
| - |
|
1820 |
items = Amazonlisted.query.filter(Amazonlisted.isNonFba==True).all()
|
| - |
|
1821 |
for item in items:
|
| - |
|
1822 |
mfnItems.append(item.itemId)
|
| - |
|
1823 |
listToUpdate = list(set(mfnItems)-set(skuList))
|
| - |
|
1824 |
for sku in listToUpdate:
|
| - |
|
1825 |
amazonItem = Amazonlisted.get_by(itemId=sku)
|
| - |
|
1826 |
amazonItem.mfnPriceLastUpdatedOnSc = to_py_date(timestamp)
|
| - |
|
1827 |
session.commit()
|
| - |
|
1828 |
else:
|
| - |
|
1829 |
return False
|
| - |
|
1830 |
|
| - |
|
1831 |
|
| - |
|
1832 |
|
| - |
|
1833 |
|
| - |
|
1834 |
|
| 1762 |
|
1835 |
|
| 1763 |
|
1836 |
|
| 1764 |
|
1837 |
|