| Line 9... |
Line 9... |
| 9 |
Warehouse, ItemInventoryHistory, CurrentInventorySnapshot, ItemInfo,\
|
9 |
Warehouse, ItemInventoryHistory, CurrentInventorySnapshot, ItemInfo,\
|
| 10 |
ItemChangeLog, Category, EntityIDGenerator, VendorItemPricing,\
|
10 |
ItemChangeLog, Category, EntityIDGenerator, VendorItemPricing,\
|
| 11 |
VendorItemMapping, Vendor
|
11 |
VendorItemMapping, Vendor
|
| 12 |
from shop2020.thriftpy.model.v1.catalog.ttypes import \
|
12 |
from shop2020.thriftpy.model.v1.catalog.ttypes import \
|
| 13 |
InventoryServiceException, status
|
13 |
InventoryServiceException, status
|
| 14 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item
|
14 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item,\
|
| - |
|
15 |
to_t_vendor_item_pricing
|
| 15 |
import datetime
|
16 |
import datetime
|
| 16 |
import sys
|
17 |
import sys
|
| 17 |
from shop2020.utils.Utils import log_entry, to_py_date
|
18 |
from shop2020.utils.Utils import log_entry, to_py_date
|
| 18 |
from sqlalchemy import desc, asc
|
19 |
from sqlalchemy import desc, asc
|
| 19 |
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
|
20 |
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
|
| Line 109... |
Line 110... |
| 109 |
raise InventoryServiceException(108, "Bad item in request")
|
110 |
raise InventoryServiceException(108, "Bad item in request")
|
| 110 |
|
111 |
|
| 111 |
if not item.id:
|
112 |
if not item.id:
|
| 112 |
raise InventoryServiceException(101, "Missing id for update")
|
113 |
raise InventoryServiceException(101, "Missing id for update")
|
| 113 |
|
114 |
|
| - |
|
115 |
validate_prices(item)
|
| - |
|
116 |
|
| 114 |
ds_item = get_item(item.id)
|
117 |
ds_item = get_item(item.id)
|
| 115 |
|
118 |
|
| 116 |
if not ds_item:
|
119 |
if not ds_item:
|
| 117 |
raise InventoryServiceException(101, "Item missing in our database")
|
120 |
raise InventoryServiceException(101, "Item missing in our database")
|
| 118 |
|
121 |
|
| Line 140... |
Line 143... |
| 140 |
ds_item.mop = item.mop
|
143 |
ds_item.mop = item.mop
|
| 141 |
if item.sellingPrice:
|
144 |
if item.sellingPrice:
|
| 142 |
ds_item.sellingPrice = item.sellingPrice
|
145 |
ds_item.sellingPrice = item.sellingPrice
|
| 143 |
if item.dealerPrice:
|
146 |
if item.dealerPrice:
|
| 144 |
ds_item.dealerPrice = item.dealerPrice
|
147 |
ds_item.dealerPrice = item.dealerPrice
|
| - |
|
148 |
if item.transferPrice:
|
| - |
|
149 |
ds_item.transfer_price = item.transferPrice
|
| 145 |
if item.weight:
|
150 |
if item.weight:
|
| 146 |
ds_item.weight = item.weight
|
151 |
ds_item.weight = item.weight
|
| 147 |
if item.itemStatus:
|
152 |
if item.itemStatus:
|
| 148 |
ds_item.status = item.itemStatus
|
153 |
ds_item.status = item.itemStatus
|
| 149 |
if item.status_description:
|
154 |
if item.status_description:
|
| Line 162... |
Line 167... |
| 162 |
if item.bestDealText:
|
167 |
if item.bestDealText:
|
| 163 |
ds_item.bestDealText = item.bestDealText
|
168 |
ds_item.bestDealText = item.bestDealText
|
| 164 |
if item.bestDealValue:
|
169 |
if item.bestDealValue:
|
| 165 |
ds_item.bestDealValue = item.bestDealValue
|
170 |
ds_item.bestDealValue = item.bestDealValue
|
| 166 |
|
171 |
|
| - |
|
172 |
ds_item.bestSellingRank = item.bestSellingRank
|
| - |
|
173 |
ds_item.defaultForEntity = item.defaultForEntity
|
| - |
|
174 |
|
| 167 |
ds_item.updated_on = datetime.datetime.now()
|
175 |
ds_item.updated_on = datetime.datetime.now()
|
| - |
|
176 |
|
| 168 |
session.commit();
|
177 |
session.commit();
|
| 169 |
return ds_item.id
|
178 |
return ds_item.id
|
| 170 |
|
179 |
|
| 171 |
def add_item(item):
|
180 |
def add_item(item):
|
| 172 |
if not item:
|
181 |
if not item:
|
| Line 627... |
Line 636... |
| 627 |
def update_vendor_pricing(vendorItemPricing):
|
636 |
def update_vendor_pricing(vendorItemPricing):
|
| 628 |
if not vendorItemPricing:
|
637 |
if not vendorItemPricing:
|
| 629 |
raise InventoryServiceException(108, "Bad vendorItemPricing in request")
|
638 |
raise InventoryServiceException(108, "Bad vendorItemPricing in request")
|
| 630 |
vendorId = vendorItemPricing.vendorId
|
639 |
vendorId = vendorItemPricing.vendorId
|
| 631 |
itemId = vendorItemPricing.itemId
|
640 |
itemId = vendorItemPricing.itemId
|
| 632 |
if not itemId:
|
- |
|
| 633 |
raise InventoryServiceException(101, "Missing item id for update")
|
- |
|
| 634 |
|
- |
|
| 635 |
if not vendorId:
|
- |
|
| 636 |
raise InventoryServiceException(101, "Missing vendor id for update")
|
- |
|
| 637 |
|
641 |
|
| 638 |
try:
|
642 |
try:
|
| 639 |
vendor = Vendor.query.filter_by(id=vendorId).one()
|
643 |
vendor = Vendor.query.filter_by(id=vendorId).one()
|
| 640 |
except:
|
644 |
except:
|
| 641 |
raise InventoryServiceException(101, "Vendor not found for vendorId " + str(vendorId))
|
645 |
raise InventoryServiceException(101, "Vendor not found for vendorId " + str(vendorId))
|
| Line 643... |
Line 647... |
| 643 |
try:
|
647 |
try:
|
| 644 |
item = Item.query.filter_by(id=itemId).one()
|
648 |
item = Item.query.filter_by(id=itemId).one()
|
| 645 |
except:
|
649 |
except:
|
| 646 |
raise InventoryServiceException(101, "Item not found for vendorId " + str(itemId))
|
650 |
raise InventoryServiceException(101, "Item not found for vendorId " + str(itemId))
|
| 647 |
|
651 |
|
| - |
|
652 |
validate_prices(to_t_item(item), vendorItemPricing)
|
| - |
|
653 |
|
| 648 |
try:
|
654 |
try:
|
| 649 |
ds_vendorItemPricing = VendorItemPricing.query.filter(and_(VendorItemPricing.vendor==vendor, VendorItemPricing.item==item)).one()
|
655 |
ds_vendorItemPricing = VendorItemPricing.query.filter(and_(VendorItemPricing.vendor==vendor, VendorItemPricing.item==item)).one()
|
| 650 |
except:
|
656 |
except:
|
| 651 |
raise InventoryServiceException(101, "VendorItemPricing not found for vendorId " + str(vendorId) + " and itemId " + str(itemId))
|
657 |
raise InventoryServiceException(101, "VendorItemPricing not found for vendorId " + str(vendorId) + " and itemId " + str(itemId))
|
| 652 |
|
658 |
|
| 653 |
if vendorItemPricing.mop:
|
659 |
if vendorItemPricing.mop:
|
| 654 |
ds_vendorItemPricing.mop = vendorItemPricing.mop
|
660 |
ds_vendorItemPricing.mop = vendorItemPricing.mop
|
| 655 |
if vendorItemPricing.dealerPrice:
|
661 |
if vendorItemPricing.dealerPrice:
|
| 656 |
ds_vendorItemPricing.dealerPrice = vendorItemPricing.dealerPrice
|
662 |
ds_vendorItemPricing.dealerPrice = vendorItemPricing.dealerPrice
|
| 657 |
if vendorItemPricing.transferPrice:
|
663 |
if vendorItemPricing.transferPrice:
|
| 658 |
ds_vendorItemPricing.transferPrice = vendorItemPricing.transferPrice
|
664 |
ds_vendorItemPricing.transfer_price = vendorItemPricing.transferPrice
|
| 659 |
|
665 |
|
| 660 |
session.commit()
|
666 |
session.commit()
|
| 661 |
return
|
667 |
return
|
| 662 |
|
668 |
|
| - |
|
669 |
def validate_prices(item, vendorPrices = None):
|
| - |
|
670 |
if item.mrp != "" and item.sellingPrice != "" and item.mrp < item.sellingPrice:
|
| - |
|
671 |
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))
|
| - |
|
672 |
if not vendorPrices:
|
| - |
|
673 |
vendorPricesList = [to_t_vendor_item_pricing(vip) for vip in get_all_item_pricing(item.id)]
|
| - |
|
674 |
else:
|
| - |
|
675 |
vendorPricesList = [vendorPrices]
|
| - |
|
676 |
for vp in vendorPricesList:
|
| - |
|
677 |
if item.mrp != "" and vp.mop != "" and item.mrp < vp.mop:
|
| - |
|
678 |
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))
|
| - |
|
679 |
if vp.mop != "" and vp.transferPrice != "" and vp.transferPrice > vp.mop:
|
| - |
|
680 |
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))
|
| - |
|
681 |
return
|
| - |
|
682 |
|
| - |
|
683 |
def get_all_vendors():
|
| - |
|
684 |
return Vendor.query.all()
|
| - |
|
685 |
|
| 663 |
def close_session():
|
686 |
def close_session():
|
| 664 |
if session.is_active:
|
687 |
if session.is_active:
|
| 665 |
print "session is active. closing it."
|
688 |
print "session is active. closing it."
|
| 666 |
session.close()
|
689 |
session.close()
|