| Line 153... |
Line 153... |
| 153 |
ds_item.status = item.itemStatus
|
153 |
ds_item.status = item.itemStatus
|
| 154 |
if item.status_description:
|
154 |
if item.status_description:
|
| 155 |
ds_item.status_description = item.status_description
|
155 |
ds_item.status_description = item.status_description
|
| 156 |
|
156 |
|
| 157 |
if item.startDate:
|
157 |
if item.startDate:
|
| 158 |
ds_item.startDate = item.startDate
|
158 |
ds_item.startDate = to_py_date(item.startDate)
|
| 159 |
if item.retireDate:
|
159 |
if item.retireDate:
|
| 160 |
ds_item.retireDate = item.retireDate
|
160 |
ds_item.retireDate = to_py_date(item.retireDate)
|
| 161 |
|
161 |
|
| 162 |
if item.featureId:
|
162 |
if item.featureId:
|
| 163 |
ds_item.feature_id = item.featureId
|
163 |
ds_item.feature_id = item.featureId
|
| 164 |
if item.featureDescription:
|
164 |
if item.featureDescription:
|
| 165 |
ds_item.feature_description = item.featureDescription
|
165 |
ds_item.feature_description = item.featureDescription
|
| Line 175... |
Line 175... |
| 175 |
ds_item.updated_on = datetime.datetime.now()
|
175 |
ds_item.updated_on = datetime.datetime.now()
|
| 176 |
|
176 |
|
| 177 |
session.commit();
|
177 |
session.commit();
|
| 178 |
return ds_item.id
|
178 |
return ds_item.id
|
| 179 |
|
179 |
|
| - |
|
180 |
def check_vendor_item_mapping(product_group, brand, model_number, color, vendor_id, vendor_category):
|
| - |
|
181 |
key = product_group.strip().lower() + '|' + brand.strip().lower() + '|' + model_number.strip().lower() + '|' + color.strip().lower()
|
| - |
|
182 |
try:
|
| - |
|
183 |
vim = VendorItemMapping.query.filter_by(vendor_id=vendor_id, item_key=key, vendor_category=vendor_category).one()
|
| - |
|
184 |
return True
|
| - |
|
185 |
except:
|
| - |
|
186 |
return False
|
| - |
|
187 |
|
| 180 |
def add_item(item):
|
188 |
def add_item(item):
|
| 181 |
if not item:
|
189 |
if not item:
|
| 182 |
raise InventoryServiceException(108, "Bad item in request")
|
190 |
raise InventoryServiceException(108, "Bad item in request")
|
| 183 |
if get_item(item.id):
|
191 |
if get_item(item.id):
|
| 184 |
raise InventoryServiceException(101, "Item already exists")
|
192 |
raise InventoryServiceException(101, "Item already exists")
|
| 185 |
|
193 |
|
| 186 |
ds_item = Item()
|
194 |
ds_item = Item()
|
| 187 |
if item.id:
|
- |
|
| 188 |
ds_item.id = item.id
|
- |
|
| 189 |
if item.productGroup:
|
195 |
if item.productGroup:
|
| 190 |
ds_item.product_group = item.productGroup
|
196 |
ds_item.product_group = item.productGroup
|
| 191 |
if item.brand:
|
197 |
if item.brand:
|
| 192 |
ds_item.brand = item.brand
|
198 |
ds_item.brand = item.brand
|
| 193 |
if item.modelName:
|
199 |
if item.modelName:
|
| 194 |
ds_item.model_name = item.modelName
|
200 |
ds_item.model_name = item.modelName
|
| 195 |
if item.modelNumber:
|
201 |
if item.modelNumber:
|
| 196 |
ds_item.model_number = item.modelNumber
|
202 |
ds_item.model_number = item.modelNumber
|
| 197 |
if item.color:
|
203 |
if item.color:
|
| 198 |
ds_item.color = item.color
|
204 |
ds_item.color = item.color
|
| - |
|
205 |
if item.hotspotCategory:
|
| - |
|
206 |
ds_item.hotspotCategory = item.hotspotCategory
|
| - |
|
207 |
if item.hotspotCategory == 'Handsets':
|
| - |
|
208 |
item.preferredWarehouse = 1
|
| - |
|
209 |
else:
|
| - |
|
210 |
item.preferredWarehouse = 2
|
| - |
|
211 |
|
| 199 |
if item.category:
|
212 |
if item.category:
|
| 200 |
ds_item.category = item.category
|
213 |
ds_item.category = item.category
|
| 201 |
if item.comments:
|
214 |
if item.comments:
|
| 202 |
ds_item.comments = item.comments
|
215 |
ds_item.comments = item.comments
|
| 203 |
|
216 |
|
| 204 |
if item.catalogItemId:
|
- |
|
| 205 |
ds_item.catalog_item_id = item.catalogItemId
|
- |
|
| 206 |
if item.status_description:
|
- |
|
| 207 |
ds_item.status_description = item.status_description
|
- |
|
| 208 |
if item.itemStatus:
|
- |
|
| 209 |
ds_item.status = item.itemStatus
|
- |
|
| 210 |
else: #If new item is added without status it will have status as IN_PROCESS
|
- |
|
| 211 |
ds_item.status = status.IN_PROCESS
|
- |
|
| 212 |
ds_item.status_description = "This item is in process."
|
- |
|
| 213 |
|
- |
|
| 214 |
ds_item.addedOn = datetime.datetime.now()
|
217 |
ds_item.addedOn = datetime.datetime.now()
|
| 215 |
ds_item.updatedOn = datetime.datetime.now()
|
218 |
ds_item.updatedOn = datetime.datetime.now()
|
| - |
|
219 |
if item.startDate:
|
| - |
|
220 |
ds_item.startDate = to_py_date(item.startDate)
|
| - |
|
221 |
if item.retireDate:
|
| - |
|
222 |
ds_item.retireDate = to_py_date(item.retireDate)
|
| 216 |
|
223 |
|
| 217 |
if item.mrp:
|
224 |
if item.mrp:
|
| 218 |
ds_item.mrp = item.mrp
|
225 |
ds_item.mrp = item.mrp
|
| 219 |
if item.mop:
|
226 |
if item.mop:
|
| 220 |
ds_item.mop = item.mop
|
227 |
ds_item.mop = item.mop
|
| 221 |
if item.sellingPrice:
|
228 |
if item.sellingPrice:
|
| 222 |
ds_item.sellingPrice = item.sellingPrice
|
229 |
ds_item.sellingPrice = item.sellingPrice
|
| 223 |
if item.dealerPrice:
|
230 |
if item.dealerPrice:
|
| 224 |
ds_item.dealerPrice = item.dealerPrice
|
231 |
ds_item.dealerPrice = item.dealerPrice
|
| - |
|
232 |
if item.transferPrice:
|
| - |
|
233 |
ds_item.transfer_price = item.transferPrice
|
| 225 |
if item.weight:
|
234 |
if item.weight:
|
| 226 |
ds_item.weight = item.weight
|
235 |
ds_item.weight = item.weight
|
| 227 |
|
236 |
|
| 228 |
if item.featureId:
|
237 |
if item.featureId:
|
| 229 |
ds_item.feature_id = item.featureId
|
238 |
ds_item.feature_id = item.featureId
|
| Line 234... |
Line 243... |
| 234 |
for k,v in item.otherInfo.iteritems():
|
243 |
for k,v in item.otherInfo.iteritems():
|
| 235 |
info = ItemInfo()
|
244 |
info = ItemInfo()
|
| 236 |
info.key = k
|
245 |
info.key = k
|
| 237 |
info.value = v
|
246 |
info.value = v
|
| 238 |
ds_item.iteminfo.append(info)
|
247 |
ds_item.iteminfo.append(info)
|
| - |
|
248 |
|
| 239 |
#check if categories present. If yes, add them to system
|
249 |
#check if categories present. If yes, add them to system
|
| 240 |
|
250 |
|
| 241 |
if item.bestDealValue:
|
251 |
if item.bestDealValue:
|
| 242 |
ds_item.bestDealValue = item.bestDealValue
|
252 |
ds_item.bestDealValue = item.bestDealValue
|
| 243 |
if item.bestDealText:
|
253 |
if item.bestDealText:
|
| 244 |
ds_item.bestDealText = item.bestDealText
|
254 |
ds_item.bestDealText = item.bestDealText
|
| - |
|
255 |
if item.bestSellingRank:
|
| - |
|
256 |
ds_item.bestSellingRank = item.bestSellingRank
|
| - |
|
257 |
ds_item.defaultForEntity = item.defaultForEntity
|
| - |
|
258 |
|
| - |
|
259 |
# Check if a similar item already exists in our database
|
| - |
|
260 |
similar_item = Item.query.filter_by(product_group=item.productGroup, brand = item.brand, model_number=item.modelNumber, hotspotCategory=item.hotspotCategory).first()
|
| - |
|
261 |
print "[SIMILAR ITEM FOUND:] FOR {0} {1} {2} {3} {4}".format(item.productGroup, item.brand, item.modelNumber, item.hotspotCategory, item.color)
|
| - |
|
262 |
|
| - |
|
263 |
if similar_item is None or similar_item.catalog_item_id is None:
|
| - |
|
264 |
# If there is no similar item in the database from before,
|
| - |
|
265 |
# use the entity_id_generator
|
| - |
|
266 |
entity_id = EntityIDGenerator.query.first()
|
| - |
|
267 |
ds_item.catalog_item_id = entity_id.id + 1
|
| - |
|
268 |
ds_item.status = status.IN_PROCESS
|
| - |
|
269 |
ds_item.status_description = "This item is in process."
|
| - |
|
270 |
entity_id.id = entity_id.id + 1
|
| - |
|
271 |
else:
|
| - |
|
272 |
#If a similar item already exists for a product group, brand and model_number, set it as same.
|
| - |
|
273 |
ds_item.catalog_item_id = similar_item.catalog_item_id
|
| - |
|
274 |
ds_item.category = similar_item.category
|
| - |
|
275 |
ds_item.status = similar_item.status
|
| - |
|
276 |
ds_item.status_description = similar_item.status_description
|
| 245 |
|
277 |
|
| 246 |
session.commit();
|
278 |
session.commit();
|
| 247 |
return ds_item.id
|
279 |
return ds_item.id
|
| 248 |
|
280 |
|
| 249 |
def update_inventory(warehouse_id, timestamp, availability):
|
281 |
def update_inventory(warehouse_id, timestamp, availability):
|
| Line 353... |
Line 385... |
| 353 |
if not item_id:
|
385 |
if not item_id:
|
| 354 |
raise InventoryServiceException(101, "bad item id")
|
386 |
raise InventoryServiceException(101, "bad item id")
|
| 355 |
item = get_item(item_id)
|
387 |
item = get_item(item_id)
|
| 356 |
if not item:
|
388 |
if not item:
|
| 357 |
raise InventoryServiceException(108, "item id not present")
|
389 |
raise InventoryServiceException(108, "item id not present")
|
| 358 |
|
- |
|
| 359 |
item.status = new_status
|
- |
|
| 360 |
add_status_change_log(item, new_status)
|
390 |
add_status_change_log(item, new_status)
|
| - |
|
391 |
item.status = new_status
|
| 361 |
session.commit()
|
392 |
session.commit()
|
| 362 |
|
393 |
|
| 363 |
def get_item_availability_for_warehouse(warehouse_id, item_id):
|
394 |
def get_item_availability_for_warehouse(warehouse_id, item_id):
|
| 364 |
if not warehouse_id:
|
395 |
if not warehouse_id:
|
| 365 |
raise InventoryServiceException(101, "bad warehouse_id")
|
396 |
raise InventoryServiceException(101, "bad warehouse_id")
|
| Line 635... |
Line 666... |
| 635 |
if item is None:
|
666 |
if item is None:
|
| 636 |
raise InventoryServiceException(101, "Bad Item")
|
667 |
raise InventoryServiceException(101, "Bad Item")
|
| 637 |
item_pricing = VendorItemPricing.query.filter_by(item=item).all()
|
668 |
item_pricing = VendorItemPricing.query.filter_by(item=item).all()
|
| 638 |
return item_pricing
|
669 |
return item_pricing
|
| 639 |
|
670 |
|
| - |
|
671 |
def get_item_mappings(item_id):
|
| - |
|
672 |
item = Item.query.filter_by(id=item_id).first()
|
| - |
|
673 |
if item is None:
|
| - |
|
674 |
raise InventoryServiceException(101, "Bad Item")
|
| - |
|
675 |
item_mappings = VendorItemMapping.query.filter_by(item=item).all()
|
| - |
|
676 |
return item_mappings
|
| - |
|
677 |
|
| 640 |
def update_vendor_pricing(vendorItemPricing):
|
678 |
def add_vendor_pricing(vendorItemPricing):
|
| 641 |
if not vendorItemPricing:
|
679 |
if not vendorItemPricing:
|
| 642 |
raise InventoryServiceException(108, "Bad vendorItemPricing in request")
|
680 |
raise InventoryServiceException(108, "Bad vendorItemPricing in request")
|
| 643 |
vendorId = vendorItemPricing.vendorId
|
681 |
vendorId = vendorItemPricing.vendorId
|
| 644 |
itemId = vendorItemPricing.itemId
|
682 |
itemId = vendorItemPricing.itemId
|
| 645 |
|
683 |
|
| Line 656... |
Line 694... |
| 656 |
validate_prices(to_t_item(item), vendorItemPricing)
|
694 |
validate_prices(to_t_item(item), vendorItemPricing)
|
| 657 |
|
695 |
|
| 658 |
try:
|
696 |
try:
|
| 659 |
ds_vendorItemPricing = VendorItemPricing.query.filter(and_(VendorItemPricing.vendor==vendor, VendorItemPricing.item==item)).one()
|
697 |
ds_vendorItemPricing = VendorItemPricing.query.filter(and_(VendorItemPricing.vendor==vendor, VendorItemPricing.item==item)).one()
|
| 660 |
except:
|
698 |
except:
|
| 661 |
raise InventoryServiceException(101, "VendorItemPricing not found for vendorId " + str(vendorId) + " and itemId " + str(itemId))
|
699 |
ds_vendorItemPricing = VendorItemPricing()
|
| - |
|
700 |
ds_vendorItemPricing.vendor = vendor
|
| - |
|
701 |
ds_vendorItemPricing.item = item
|
| 662 |
|
702 |
|
| 663 |
if vendorItemPricing.mop:
|
703 |
if vendorItemPricing.mop:
|
| 664 |
ds_vendorItemPricing.mop = vendorItemPricing.mop
|
704 |
ds_vendorItemPricing.mop = vendorItemPricing.mop
|
| 665 |
if vendorItemPricing.dealerPrice:
|
705 |
if vendorItemPricing.dealerPrice:
|
| 666 |
ds_vendorItemPricing.dealerPrice = vendorItemPricing.dealerPrice
|
706 |
ds_vendorItemPricing.dealerPrice = vendorItemPricing.dealerPrice
|
| Line 668... |
Line 708... |
| 668 |
ds_vendorItemPricing.transfer_price = vendorItemPricing.transferPrice
|
708 |
ds_vendorItemPricing.transfer_price = vendorItemPricing.transferPrice
|
| 669 |
|
709 |
|
| 670 |
session.commit()
|
710 |
session.commit()
|
| 671 |
return
|
711 |
return
|
| 672 |
|
712 |
|
| - |
|
713 |
def add_vendor_item_mapping(vendorItemMapping):
|
| - |
|
714 |
if not vendorItemMapping:
|
| - |
|
715 |
raise InventoryServiceException(108, "Bad vendorItemMapping in request")
|
| - |
|
716 |
vendorId = vendorItemMapping.vendorId
|
| - |
|
717 |
itemId = vendorItemMapping.itemId
|
| - |
|
718 |
|
| - |
|
719 |
try:
|
| - |
|
720 |
vendor = Vendor.query.filter_by(id=vendorId).one()
|
| - |
|
721 |
except:
|
| - |
|
722 |
raise InventoryServiceException(101, "Vendor not found for vendorId " + str(vendorId))
|
| - |
|
723 |
|
| - |
|
724 |
try:
|
| - |
|
725 |
item = Item.query.filter_by(id=itemId).one()
|
| - |
|
726 |
except:
|
| - |
|
727 |
raise InventoryServiceException(101, "Item not found for vendorId " + str(itemId))
|
| - |
|
728 |
|
| - |
|
729 |
try:
|
| - |
|
730 |
ds_vendorItemMapping = VendorItemMapping.query.filter(and_(VendorItemMapping.vendor==vendor, VendorItemMapping.item==item, VendorItemMapping.item_key==vendorItemMapping.itemKey)).one()
|
| - |
|
731 |
except:
|
| - |
|
732 |
ds_vendorItemMapping = VendorItemMapping()
|
| - |
|
733 |
ds_vendorItemMapping.vendor = vendor
|
| - |
|
734 |
ds_vendorItemMapping.item = item
|
| - |
|
735 |
ds_vendorItemMapping.vendor_category = vendorItemMapping.vendorCategory
|
| - |
|
736 |
ds_vendorItemMapping.item_key = vendorItemMapping.itemKey
|
| - |
|
737 |
|
| - |
|
738 |
session.commit()
|
| - |
|
739 |
return
|
| - |
|
740 |
|
| 673 |
def validate_prices(item, vendorPrices = None):
|
741 |
def validate_prices(item, vendorPrices = None):
|
| 674 |
if item.mrp != "" and item.sellingPrice != "" and item.mrp < item.sellingPrice:
|
742 |
if item.mrp != "" and item.sellingPrice != "" and item.mrp < item.sellingPrice:
|
| 675 |
raise InventoryServiceException("[BAD MRP and SP:] for {0} {1} {2} {3}. MRP={4}, SP={5}".format(item.productGroup, item.brand, item.modelNumber, item.color, item.mrp, item.sellingPrice))
|
743 |
raise InventoryServiceException("[BAD MRP and SP:] for {0} {1} {2} {3}. MRP={4}, SP={5}".format(item.productGroup, item.brand, item.modelNumber, item.color, item.mrp, item.sellingPrice))
|
| 676 |
if not vendorPrices:
|
744 |
if not vendorPrices:
|
| 677 |
vendorPricesList = [to_t_vendor_item_pricing(vip) for vip in get_all_item_pricing(item.id)]
|
745 |
vendorPricesList = [to_t_vendor_item_pricing(vip) for vip in get_all_item_pricing(item.id)]
|
| Line 685... |
Line 753... |
| 685 |
return
|
753 |
return
|
| 686 |
|
754 |
|
| 687 |
def get_all_vendors():
|
755 |
def get_all_vendors():
|
| 688 |
return Vendor.query.all()
|
756 |
return Vendor.query.all()
|
| 689 |
|
757 |
|
| - |
|
758 |
def check_similar_item(product_group, brand, model_number, color):
|
| - |
|
759 |
item = Item.query.filter_by(product_group=product_group,brand=brand,model_number=model_number,color=color).first()
|
| - |
|
760 |
if item is None:
|
| - |
|
761 |
return 0
|
| - |
|
762 |
else:
|
| - |
|
763 |
return item.id
|
| - |
|
764 |
|
| 690 |
def close_session():
|
765 |
def close_session():
|
| 691 |
if session.is_active:
|
766 |
if session.is_active:
|
| 692 |
print "session is active. closing it."
|
767 |
print "session is active. closing it."
|
| 693 |
session.close()
|
768 |
session.close()
|