Subversion Repositories SmartDukaan

Rev

Rev 7202 | Rev 7257 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7202 Rev 7256
Line 13... Line 13...
13
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
13
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
14
from shop2020.model.v1.catalog.impl.Convertors import to_t_item, to_t_source
14
from shop2020.model.v1.catalog.impl.Convertors import to_t_item, to_t_source
15
from shop2020.model.v1.catalog.impl.DataService import Item, ItemChangeLog, \
15
from shop2020.model.v1.catalog.impl.DataService import Item, ItemChangeLog, \
16
    Category, EntityIDGenerator, SimilarItems, ProductNotification, Source, \
16
    Category, EntityIDGenerator, SimilarItems, ProductNotification, Source, \
17
    SourceItemPricing, AuthorizationLog, VoucherItemMapping, CategoryVatMaster, \
17
    SourceItemPricing, AuthorizationLog, VoucherItemMapping, CategoryVatMaster, \
18
    OOSTracker,EntityTag,ItemInsurerMapping, Insurer, Banner, BannerMap, FreebieItem
18
    OOSTracker,EntityTag,ItemInsurerMapping, Insurer, Banner, BannerMap, FreebieItem,\
-
 
19
    StorePricing
19
from shop2020.thriftpy.model.v1.catalog.ttypes import status, ItemShippingInfo, \
20
from shop2020.thriftpy.model.v1.catalog.ttypes import status, ItemShippingInfo, \
20
    ItemType, PremiumType, FreebieItem as t_FreebieItem
21
    ItemType, PremiumType, FreebieItem as t_FreebieItem, StorePricing as tStorePricing
21
from shop2020.thriftpy.model.v1.inventory.ttypes import \
22
from shop2020.thriftpy.model.v1.inventory.ttypes import \
22
    InventoryServiceException, IgnoredInventoryUpdateItems
23
    InventoryServiceException, IgnoredInventoryUpdateItems
23
from shop2020.utils import EmailAttachmentSender
24
from shop2020.utils import EmailAttachmentSender
24
from shop2020.utils.EmailAttachmentSender import mail
25
from shop2020.utils.EmailAttachmentSender import mail
25
from shop2020.utils.Utils import to_py_date, log_risky_flag
26
from shop2020.utils.Utils import to_py_date, log_risky_flag
Line 226... Line 227...
226
    
227
    
227
    ds_item.risky = item.risky
228
    ds_item.risky = item.risky
228
    
229
    
229
    ds_item.type = ItemType._VALUES_TO_NAMES[item.type]
230
    ds_item.type = ItemType._VALUES_TO_NAMES[item.type]
230
    ds_item.hasItemNo = item.hasItemNo
231
    ds_item.hasItemNo = item.hasItemNo
231
    ds_item.clearance = item.clearance
232
    ds_item.activeOnStore = item.activeOnStore
232
    
233
    
233
    if item.expectedDelay is not None:
234
    if item.expectedDelay is not None:
234
        ds_item.expectedDelay = item.expectedDelay
235
        ds_item.expectedDelay = item.expectedDelay
235
    
236
    
236
    if item.preferredVendor:
237
    if item.preferredVendor:
Line 320... Line 321...
320
    ds_item.defaultForEntity = item.defaultForEntity
321
    ds_item.defaultForEntity = item.defaultForEntity
321
    ds_item.risky = item.risky
322
    ds_item.risky = item.risky
322
    
323
    
323
    ds_item.type = ItemType._VALUES_TO_NAMES[item.type]
324
    ds_item.type = ItemType._VALUES_TO_NAMES[item.type]
324
    ds_item.hasItemNo = item.hasItemNo
325
    ds_item.hasItemNo = item.hasItemNo
325
    ds_item.clearance = item.clearance
326
    ds_item.activeOnStore = item.activeOnStore
326
    
327
    
327
    if item.expectedDelay is not None:
328
    if item.expectedDelay is not None:
328
        ds_item.expectedDelay = item.expectedDelay
329
        ds_item.expectedDelay = item.expectedDelay
329
    else:
330
    else:
330
        ds_item.expectedDelay = 0
331
        ds_item.expectedDelay = 0
Line 755... Line 756...
755
    if item.mrp == None or item.sellingPrice == None or item.mrp == "" or item.sellingPrice == "":
756
    if item.mrp == None or item.sellingPrice == None or item.mrp == "" or item.sellingPrice == "":
756
        return
757
        return
757
    if item.mrp < item.sellingPrice:
758
    if item.mrp < item.sellingPrice:
758
        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))
759
        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))
759
        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)))
760
        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)))
-
 
761
    if minp < item.sellingPrice:
-
 
762
        print "alert to store" 
-
 
763
    if maxp > item.mrp:
-
 
764
        print "reset to mrp"
-
 
765
        print "alert to store"
760
    return
766
    return
761
    
767
    
762
def validate_vendor_prices(item, vendorPrices):
768
def validate_vendor_prices(item, vendorPrices):
763
    if item.mrp != None and item.mrp != "" and vendorPrices.mop != "" and item.mrp <  vendorPrices.mop:
769
    if item.mrp != None and item.mrp != "" and vendorPrices.mop != "" and item.mrp <  vendorPrices.mop:
764
        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))
770
        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))
765
        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)))
771
        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)))
766
    if vendorPrices.mop != "" and vendorPrices.transferPrice != "" and vendorPrices.transferPrice > vendorPrices.mop:
772
    if vendorPrices.mop != "" and vendorPrices.transferPrice != "" and vendorPrices.transferPrice > vendorPrices.mop:
767
        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))
773
        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))
768
        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)))
774
        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)))
-
 
775
    if change in dp:
-
 
776
        print "alert to store" 
-
 
777
 
769
    return
778
    return
770
 
779
 
771
def check_color_valid(color):
780
def check_color_valid(color):
772
    if color is not None:
781
    if color is not None:
773
        color = color.strip().lower()
782
        color = color.strip().lower()
Line 1281... Line 1290...
1281
        thread = threading.Thread(target=partial(mail, mail_user, mail_password, to_addresses, subject, message))
1290
        thread = threading.Thread(target=partial(mail, mail_user, mail_password, to_addresses, subject, message))
1282
        thread.start()
1291
        thread.start()
1283
    except Exception as ex:
1292
    except Exception as ex:
1284
        print ex    
1293
        print ex    
1285
 
1294
 
1286
def get_clearance_sale_catalog_ids():
-
 
1287
    all_status = [status.ACTIVE, status.PAUSED, status.PAUSED_BY_RISK]
-
 
1288
    query = Item.query.filter_by(clearance=True)
-
 
1289
    query = query.filter(Item.status.in_(all_status))
-
 
1290
    query = query.group_by(Item.catalog_item_id).order_by(desc(Item.startDate)).order_by(Item.catalog_item_id)
-
 
1291
    clearance_sales = query.all()
-
 
1292
    return [item.catalog_item_id for item in clearance_sales]
-
 
1293
 
-
 
1294
def get_vat_amount_for_item(itemId, price):
1295
def get_vat_amount_for_item(itemId, price):
1295
    item = Item.query.filter_by(id=itemId).first()
1296
    item = Item.query.filter_by(id=itemId).first()
1296
    vatPercentage = item.vatPercentage
1297
    vatPercentage = item.vatPercentage
1297
    if vatPercentage is None:
1298
    if vatPercentage is None:
1298
        vatMaster = CategoryVatMaster.query.filter(and_(CategoryVatMaster.categoryId==item.category, CategoryVatMaster.minVal<=price,  CategoryVatMaster.maxVal>=price)).first()
1299
        vatMaster = CategoryVatMaster.query.filter(and_(CategoryVatMaster.categoryId==item.category, CategoryVatMaster.minVal<=price,  CategoryVatMaster.maxVal>=price)).first()
Line 1454... Line 1455...
1454
    freebie = FreebieItem.get_by(itemId = freebieItem.itemId)
1455
    freebie = FreebieItem.get_by(itemId = freebieItem.itemId)
1455
    if freebie is None:
1456
    if freebie is None:
1456
        freebie = FreebieItem()
1457
        freebie = FreebieItem()
1457
        freebie.itemId = freebieItem.itemId
1458
        freebie.itemId = freebieItem.itemId
1458
    freebie.freebieItemId = freebieItem.freebieItemId
1459
    freebie.freebieItemId = freebieItem.freebieItemId
1459
    session.commit()
-
 
1460
1460
    session.commit()
-
 
1461
 
-
 
1462
def add_store_pricing(item, rp):
-
 
1463
    inventoryClient = InventoryClient().get_client()
-
 
1464
    pricings = inventoryClient.getAllItemPricing(item.id)
-
 
1465
    
-
 
1466
    minp = 0
-
 
1467
    maxp = item.mrp
-
 
1468
          
-
 
1469
    for pricing in pricings:
-
 
1470
        if not minp or minp > pricing.dealerPrice: 
-
 
1471
            minp = pricing.dealerPrice
-
 
1472
    
-
 
1473
    if minp < item.sellingPrice:
-
 
1474
        print "Alert to store"        
-
 
1475
    
-
 
1476
    if maxp < minp:
-
 
1477
        print "Alert to store"
-
 
1478
        
-
 
1479
    if rp < minp or rp > maxp:
-
 
1480
        print "Alert to store" 
-
 
1481
    
-
 
1482
    minap = min(max(500, 10%rp),rp)
-
 
1483
    sp = StorePricing()
-
 
1484
    sp.recommendedPrice = rp
-
 
1485
    sp.minPrice = minp
-
 
1486
    sp.minAdvancePrice = minap
-
 
1487
    sp.maxPrice = maxp
-
 
1488
    sp.itemId = item.id
-
 
1489
    session.commit()
-
 
1490
    
-
 
1491
def get_store_pricing(itemId):
-
 
1492
    store = StorePricing.get_by(itemId = itemId)
-
 
1493
    sp = tStorePricing()
-
 
1494
    sp.itemId = itemId
-
 
1495
    if store is None:
-
 
1496
        return sp
-
 
1497
    
-
 
1498
    sp.recommendedPrice = store.recommendedPrice
-
 
1499
    sp.minPrice = store.minPrice
-
 
1500
    sp.minAdvancePrice = store.minAdvancePrice
-
 
1501
    sp.maxPrice = store.maxPrice
-
 
1502
    return sp
-
 
1503
1461
1504