Subversion Repositories SmartDukaan

Rev

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

Rev 7382 Rev 7384
Line 33... Line 33...
33
import threading
33
import threading
34
import urllib2
34
import urllib2
35
 
35
 
36
sourceId = int(ConfigClient().get_property("sourceid"))
36
sourceId = int(ConfigClient().get_property("sourceid"))
37
to_addresses = ["khushal.bhatia@shop2020.in", "chandan.kumar@shop2020.in",  "chaitnaya.vats@shop2020.in"]
37
to_addresses = ["khushal.bhatia@shop2020.in", "chandan.kumar@shop2020.in",  "chaitnaya.vats@shop2020.in"]
-
 
38
to_store_addresses = ["rajveer.singh@shop2020.in"]
38
mail_user = "cnc.center@shop2020.in"
39
mail_user = "cnc.center@shop2020.in"
39
mail_password = "5h0p2o2o"
40
mail_password = "5h0p2o2o"
40
source_name = "Saholic"
41
source_name = "Saholic"
41
source_url = "www.saholic.com"
42
source_url = "www.saholic.com"
42
skippedItems = { 175 : [27, 2160, 2175, 2163, 2158, 7128, 26, 2154],
43
skippedItems = { 175 : [27, 2160, 2175, 2163, 2158, 7128, 26, 2154],
Line 134... Line 135...
134
    
135
    
135
    validate_item_prices(item)
136
    validate_item_prices(item)
136
    
137
    
137
    ds_item = get_item(item.id)
138
    ds_item = get_item(item.id)
138
    message = ""
139
    message = ""
-
 
140
    store_message = ""
139
    if not ds_item:
141
    if not ds_item:
140
        raise InventoryServiceException(101, "Item missing in our database")
142
        raise InventoryServiceException(101, "Item missing in our database")
141
    
143
    
142
    if item.productGroup:
144
    if item.productGroup:
143
        ds_item.product_group = item.productGroup 
145
        ds_item.product_group = item.productGroup 
Line 153... Line 155...
153
                
155
                
154
    ds_item.comments = item.comments
156
    ds_item.comments = item.comments
155
    
157
    
156
    ds_item.catalog_item_id = item.catalogItemId
158
    ds_item.catalog_item_id = item.catalogItemId
157
 
159
 
-
 
160
    if ds_item.activeOnStore and ds_item.mrp and item.mrp and ds_item.mrp != item.mrp:
-
 
161
        sp = get_store_pricing(item.id)
-
 
162
        if sp.maxPrice > item.mrp:
-
 
163
            sp.maxPrice = item.mrp
-
 
164
            store_message += "MRP is changed from {0} to {1}.\n".format(sp.maxPrice, item.mrp)
-
 
165
             
-
 
166
 
-
 
167
    if ds_item.activeOnStore and ds_item.sellingPrice and item.sellingPrice and ds_item.sellingPrice != item.sellingPrice:
-
 
168
        sp = get_store_pricing(item.id)
-
 
169
        if sp.minPrice < item.sellingPrice:
-
 
170
            store_message += "Saholic MOP Changed. DP {0} is less than Saholic MOP.\n".format(sp.minPrice)
-
 
171
                    
158
    ds_item.mrp = item.mrp
172
    ds_item.mrp = item.mrp
159
    if ds_item.sellingPrice or item.sellingPrice:
173
    if ds_item.sellingPrice or item.sellingPrice:
160
        if ds_item.sellingPrice != item.sellingPrice:
174
        if ds_item.sellingPrice != item.sellingPrice:
161
            message += "Selling Price is changed from {0} to {1}.\n".format(ds_item.sellingPrice, item.sellingPrice)
175
            message += "Selling Price is changed from {0} to {1}.\n".format(ds_item.sellingPrice, item.sellingPrice)
162
        
176
        
Line 257... Line 271...
257
    
271
    
258
    ds_item.updatedOn = datetime.datetime.now()
272
    ds_item.updatedOn = datetime.datetime.now()
259
    
273
    
260
 
274
 
261
    if item.category not in [10001, 10002, 10003, 10004, 10005, 10009, 10010]:
275
    if item.category not in [10001, 10002, 10003, 10004, 10005, 10009, 10010]:
-
 
276
        try:
-
 
277
            update_store_pricing(get_store_pricing(item.id), False)
262
        ds_item.activeOnStore = True
278
            ds_item.activeOnStore = True
-
 
279
        except:
263
        update_store_pricing(get_store_pricing(item.id))
280
            print "Unable to update store pricing"
264
    else:
281
    else:
265
        ds_item.activeOnStore = item.activeOnStore
282
        ds_item.activeOnStore = item.activeOnStore
266
    
283
    
267
    session.commit();
284
    session.commit();
268
    subject = "Item '{0}' is updated in Catalog. Id is {1}".format(__get_product_name(ds_item),ds_item.id)
285
    subject = "Item '{0}' is updated in Catalog. Id is {1}".format(__get_product_name(ds_item),ds_item.id)
269
    if message:
286
    if message:
270
        __send_mail(subject, message)
287
        __send_mail(subject, message)
-
 
288
    if store_message:
-
 
289
        __send_mail(subject, store_message, to_store_addresses)
271
    return ds_item.id
290
    return ds_item.id
272
 
291
 
273
def add_item(item):
292
def add_item(item):
274
    if not item:
293
    if not item:
275
        raise InventoryServiceException(108, "Bad item in request")
294
        raise InventoryServiceException(108, "Bad item in request")
Line 1290... Line 1309...
1290
    if oos is not None:
1309
    if oos is not None:
1291
        oos.delete()
1310
        oos.delete()
1292
        session.commit()
1311
        session.commit()
1293
    __send_mail(subject, message)
1312
    __send_mail(subject, message)
1294
 
1313
 
1295
def __send_mail(subject, message):
1314
def __send_mail(subject, message, send_to  = to_addresses):
1296
    try:
1315
    try:
1297
        thread = threading.Thread(target=partial(mail, mail_user, mail_password, to_addresses, subject, message))
1316
        thread = threading.Thread(target=partial(mail, mail_user, mail_password, send_to, subject, message))
1298
        thread.start()
1317
        thread.start()
1299
    except Exception as ex:
1318
    except Exception as ex:
1300
        print ex    
1319
        print ex    
1301
 
1320
 
1302
def get_vat_amount_for_item(itemId, price):
1321
def get_vat_amount_for_item(itemId, price):
Line 1507... Line 1526...
1507
    session.commit()
1526
    session.commit()
1508
    
1527
    
1509
    
1528
    
1510
def validate_store_pricing(tsp):
1529
def validate_store_pricing(tsp):
1511
    if tsp.minPrice > tsp.maxPrice:
1530
    if tsp.minPrice > tsp.maxPrice:
1512
        raise InventoryServiceException(101, "Min price is more than max price")   
1531
        raise InventoryServiceException(101, "DP is more than MRP")   
1513
    
1532
    
1514
    item = get_item(tsp.itemId)
1533
    item = get_item(tsp.itemId)
1515
    
1534
    
1516
    if tsp.maxPrice > item.mrp:
1535
    if item.mrp and tsp.maxPrice > item.mrp:
1517
        raise InventoryServiceException(101, "Min price is more than max price")
1536
        raise InventoryServiceException(101, "MRP is more than Saholic MRP")
1518
    
1537
    
1519
    if tsp.recommendedPrice < item.sellingPrice:
1538
    if tsp.recommendedPrice < item.sellingPrice:
1520
        "Alert to store"
-
 
1521
        raise InventoryServiceException(101, "Recommended price is less than saholic selling price.")   
1539
        raise InventoryServiceException(101, "MOP is less than Saholic MOP.")   
1522
   
1540
   
1523
    if tsp.recommendedPrice < tsp.minPrice or tsp.recommendedPrice >  tsp.maxPrice:
1541
    if tsp.recommendedPrice < tsp.minPrice or tsp.recommendedPrice >  tsp.maxPrice:
1524
        raise InventoryServiceException(101, "Recommended selling price must be in the range") 
1542
        raise InventoryServiceException(101, "MOP price must be in the range") 
-
 
1543
        
-
 
1544
    if tsp.minPrice < item.sellingPrice:
-
 
1545
        store_message = "Saholic MOP Changed. DP {0} is less than Saholic MOP.\n".format(tsp.minPrice)
-
 
1546
        subject = "Item '{0}' is updated in Catalog. Id is {1}".format(__get_product_name(item),item.id)
-
 
1547
        __send_mail(subject, store_message, to_store_addresses)
1525
        
1548
        
1526
    return True
1549
    return True
1527
    
1550
    
1528
    
1551
    
1529
 
1552