| Line 110... |
Line 110... |
| 110 |
raise InventoryServiceException(108, "Bad item in request")
|
110 |
raise InventoryServiceException(108, "Bad item in request")
|
| 111 |
|
111 |
|
| 112 |
if not item.id:
|
112 |
if not item.id:
|
| 113 |
raise InventoryServiceException(101, "Missing id for update")
|
113 |
raise InventoryServiceException(101, "Missing id for update")
|
| 114 |
|
114 |
|
| 115 |
validate_prices(item)
|
115 |
validate_item_prices(item)
|
| 116 |
|
116 |
|
| 117 |
ds_item = get_item(item.id)
|
117 |
ds_item = get_item(item.id)
|
| 118 |
|
118 |
|
| 119 |
if not ds_item:
|
119 |
if not ds_item:
|
| 120 |
raise InventoryServiceException(101, "Item missing in our database")
|
120 |
raise InventoryServiceException(101, "Item missing in our database")
|
| Line 188... |
Line 188... |
| 188 |
def add_item(item):
|
188 |
def add_item(item):
|
| 189 |
if not item:
|
189 |
if not item:
|
| 190 |
raise InventoryServiceException(108, "Bad item in request")
|
190 |
raise InventoryServiceException(108, "Bad item in request")
|
| 191 |
if get_item(item.id):
|
191 |
if get_item(item.id):
|
| 192 |
raise InventoryServiceException(101, "Item already exists")
|
192 |
raise InventoryServiceException(101, "Item already exists")
|
| - |
|
193 |
|
| - |
|
194 |
validate_item_prices(item)
|
| 193 |
|
195 |
|
| 194 |
ds_item = Item()
|
196 |
ds_item = Item()
|
| 195 |
if item.productGroup:
|
197 |
if item.productGroup:
|
| 196 |
ds_item.product_group = item.productGroup
|
198 |
ds_item.product_group = item.productGroup
|
| 197 |
if item.brand:
|
199 |
if item.brand:
|
| 198 |
ds_item.brand = item.brand
|
200 |
ds_item.brand = item.brand
|
| Line 689... |
Line 691... |
| 689 |
try:
|
691 |
try:
|
| 690 |
item = Item.query.filter_by(id=itemId).one()
|
692 |
item = Item.query.filter_by(id=itemId).one()
|
| 691 |
except:
|
693 |
except:
|
| 692 |
raise InventoryServiceException(101, "Item not found for vendorId " + str(itemId))
|
694 |
raise InventoryServiceException(101, "Item not found for vendorId " + str(itemId))
|
| 693 |
|
695 |
|
| 694 |
validate_prices(to_t_item(item), vendorItemPricing)
|
696 |
validate_vendor_prices(to_t_item(item), vendorItemPricing)
|
| 695 |
|
697 |
|
| 696 |
try:
|
698 |
try:
|
| 697 |
ds_vendorItemPricing = VendorItemPricing.query.filter(and_(VendorItemPricing.vendor==vendor, VendorItemPricing.item==item)).one()
|
699 |
ds_vendorItemPricing = VendorItemPricing.query.filter(and_(VendorItemPricing.vendor==vendor, VendorItemPricing.item==item)).one()
|
| 698 |
except:
|
700 |
except:
|
| 699 |
ds_vendorItemPricing = VendorItemPricing()
|
701 |
ds_vendorItemPricing = VendorItemPricing()
|
| Line 736... |
Line 738... |
| 736 |
ds_vendorItemMapping.item_key = vendorItemMapping.itemKey
|
738 |
ds_vendorItemMapping.item_key = vendorItemMapping.itemKey
|
| 737 |
|
739 |
|
| 738 |
session.commit()
|
740 |
session.commit()
|
| 739 |
return
|
741 |
return
|
| 740 |
|
742 |
|
| 741 |
def validate_prices(item, vendorPrices = None):
|
743 |
def validate_item_prices(item):
|
| 742 |
if item.mrp != "" and item.sellingPrice != "" and item.mrp < item.sellingPrice:
|
744 |
if item.mrp != "" and item.sellingPrice != "" and item.mrp < item.sellingPrice:
|
| - |
|
745 |
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))
|
| 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))
|
746 |
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)))
|
| 744 |
if not vendorPrices:
|
747 |
return
|
| 745 |
vendorPricesList = [to_t_vendor_item_pricing(vip) for vip in get_all_item_pricing(item.id)]
|
- |
|
| 746 |
else:
|
748 |
|
| 747 |
vendorPricesList = [vendorPrices]
|
749 |
def validate_vendor_prices(item, vendorPrices):
|
| 748 |
for vp in vendorPricesList:
|
- |
|
| 749 |
if item.mrp != "" and vp.mop != "" and item.mrp < vp.mop:
|
750 |
if item.mrp != "" and vendorPrices.mop != "" and item.mrp < vendorPrices.mop:
|
| - |
|
751 |
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))
|
| 750 |
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, item.mrp, vp.mop, vp.vendorId))
|
752 |
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)))
|
| 751 |
if vp.mop != "" and vp.transferPrice != "" and vp.transferPrice > vp.mop:
|
753 |
if vendorPrices.mop != "" and vendorPrices.transferPrice != "" and vendorPrices.transferPrice > vendorPrices.mop:
|
| - |
|
754 |
print "[BAD MOP and TP:] for {0} {1} {2} {3}. TP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(vendorPrices.transferPrice), str(vendorPrices.mop), str(vendorPrices.vendorId))
|
| 752 |
raise InventoryServiceException("[BAD MOP and TP:] for {0} {1} {2} {3}. TP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, vp.transferPrice, vp.mop, vp.vendorId))
|
755 |
raise InventoryServiceException(101, "[BAD MOP and TP:] for {0} {1} {2} {3}. TP={4}. MOP={5}, Vendor={6}".format(item.productGroup, item.brand, item.modelNumber, item.color, str(vendorPrices.transferPrice), str(vendorPrices.mop), str(vendorPrices.vendorId)))
|
| 753 |
return
|
756 |
return
|
| 754 |
|
757 |
|
| 755 |
def get_all_vendors():
|
758 |
def get_all_vendors():
|
| 756 |
return Vendor.query.all()
|
759 |
return Vendor.query.all()
|
| 757 |
|
760 |
|