Subversion Repositories SmartDukaan

Rev

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

Rev 9963 Rev 9966
Line 113... Line 113...
113
            markReasonForMpItem(autoDecrementItem,'Item is not risky',Decision.AUTO_DECREMENT_FAILED)
113
            markReasonForMpItem(autoDecrementItem,'Item is not risky',Decision.AUTO_DECREMENT_FAILED)
114
            continue
114
            continue
115
        if autoDecrementItem.proposedSellingPrice >= autoDecrementItem.ourSellingPrice:
115
        if autoDecrementItem.proposedSellingPrice >= autoDecrementItem.ourSellingPrice:
116
            markReasonForMpItem(autoDecrementItem,'Proposed SP greater than current SP',Decision.AUTO_DECREMENT_FAILED)
116
            markReasonForMpItem(autoDecrementItem,'Proposed SP greater than current SP',Decision.AUTO_DECREMENT_FAILED)
117
            continue
117
            continue
-
 
118
        if autoDecrementItem.proposedSellingPrice < autoDecrementItem.lowestPossibleSp:
-
 
119
            markReasonForMpItem(autoDecrementItem,'Proposed SP less than lowest possible SP',Decision.AUTO_DECREMENT_FAILED)
-
 
120
            continue
118
        if autoDecrementItem.otherInventory < 3:
121
        if autoDecrementItem.otherInventory < 3:
119
            markReasonForMpItem(autoDecrementItem,'Competition stock is not enough',Decision.AUTO_DECREMENT_FAILED)
122
            markReasonForMpItem(autoDecrementItem,'Competition stock is not enough',Decision.AUTO_DECREMENT_FAILED)
120
            continue
123
            continue
121
        #oosStatus = inventory_client.getOosStatusesForXDaysForItem(autoDecrementItem.item_id,0,3)
124
        #oosStatus = inventory_client.getOosStatusesForXDaysForItem(autoDecrementItem.item_id,0,3)
122
        #count,sale,daysOfStock = 0,0,0
125
        #count,sale,daysOfStock = 0,0,0
Line 182... Line 185...
182
            markReasonForMpItem(autoIncrementItem,'We are the only seller',Decision.AUTO_INCREMENT_FAILED)
185
            markReasonForMpItem(autoIncrementItem,'We are the only seller',Decision.AUTO_INCREMENT_FAILED)
183
            continue
186
            continue
184
        if autoIncrementItem.proposedSellingPrice <= autoIncrementItem.ourSellingPrice:
187
        if autoIncrementItem.proposedSellingPrice <= autoIncrementItem.ourSellingPrice:
185
            markReasonForMpItem(autoIncrementItem,'Proposed SP less than current SP',Decision.AUTO_INCREMENT_FAILED)
188
            markReasonForMpItem(autoIncrementItem,'Proposed SP less than current SP',Decision.AUTO_INCREMENT_FAILED)
186
            continue
189
            continue
-
 
190
        if autoIncrementItem.proposedSellingPrice >=10000 and autoIncrementItem.ourSellingPrice<10000:
-
 
191
            markReasonForMpItem(autoIncrementItem,'Proposed SP is greater than 10,000 and current sp is less than 10,000',Decision.AUTO_INCREMENT_FAILED)
-
 
192
            continue
-
 
193
        if getLastDaySale(autoIncrementItem.item_id)<=2:
-
 
194
            markReasonForMpItem(autoIncrementItem,'Last day sale is less than 3',Decision.AUTO_INCREMENT_FAILED)
-
 
195
            continue
-
 
196
        
187
        #oosStatus = inventory_client.getOosStatusesForXDaysForItem(autoIncrementItem.item_id,0,3)
197
        #oosStatus = inventory_client.getOosStatusesForXDaysForItem(autoIncrementItem.item_id,0,3)
188
        #count,sale,daysOfStock = 0,0,0
198
        #count,sale,daysOfStock = 0,0,0
189
        #for obj in oosStatus:
199
        #for obj in oosStatus:
190
        #    if not obj.is_oos:
200
        #    if not obj.is_oos:
191
        #        count+=1
201
        #        count+=1
Line 257... Line 267...
257
            lastNdaySale += "X-"
267
            lastNdaySale += "X-"
258
        else:
268
        else:
259
            lastNdaySale += str(obj.num_orders) + "-"
269
            lastNdaySale += str(obj.num_orders) + "-"
260
    return lastNdaySale[:-1]
270
    return lastNdaySale[:-1]
261
 
271
 
-
 
272
def getLastDaySale(itemId):
-
 
273
    return (itemSaleMap.get(itemId))[4]
-
 
274
 
262
def markAutoFavourite():
275
def markAutoFavourite():
263
    previouslyAutoFav = []
276
    previouslyAutoFav = []
264
    nowAutoFav = []
277
    nowAutoFav = []
265
    marketplaceItems = session.query(MarketplaceItems).filter(MarketplaceItems.source==OrderSource.SNAPDEAL).all()
278
    marketplaceItems = session.query(MarketplaceItems).filter(MarketplaceItems.source==OrderSource.SNAPDEAL).all()
266
    fromDate = datetime.now()-timedelta(days = 3, hours=datetime.now().hour, minutes=datetime.now().minute, seconds=datetime.now().second)
279
    fromDate = datetime.now()-timedelta(days = 3, hours=datetime.now().hour, minutes=datetime.now().minute, seconds=datetime.now().second)
Line 378... Line 391...
378
        warehouse = inventory_client.getWarehouse(val.warehouseId)
391
        warehouse = inventory_client.getWarehouse(val.warehouseId)
379
        
392
        
380
        itemSaleList = []
393
        itemSaleList = []
381
        oosForAllSources = inventory_client.getOosStatusesForXDaysForItem(val.item_id, 0, 3)
394
        oosForAllSources = inventory_client.getOosStatusesForXDaysForItem(val.item_id, 0, 3)
382
        oosForSnapdeal = inventory_client.getOosStatusesForXDaysForItem(val.item_id, OrderSource.SNAPDEAL, 5)
395
        oosForSnapdeal = inventory_client.getOosStatusesForXDaysForItem(val.item_id, OrderSource.SNAPDEAL, 5)
-
 
396
        oosForSnapdealLastDay = inventory_client.getOosStatusesForXDaysForItem(val.item_id, OrderSource.SNAPDEAL, 1)
383
        itemSaleList.append(oosForAllSources)
397
        itemSaleList.append(oosForAllSources)
384
        itemSaleList.append(oosForSnapdeal)
398
        itemSaleList.append(oosForSnapdeal)
385
        itemSaleList.append(calculateAverageSale(oosForAllSources))
399
        itemSaleList.append(calculateAverageSale(oosForAllSources))
386
        itemSaleList.append(calculateAverageSale(oosForSnapdeal))
400
        itemSaleList.append(calculateAverageSale(oosForSnapdeal))
-
 
401
        itemSaleList.append(calculateAverageSale(oosForSnapdealLastDay))
387
        itemSaleMap[val.item_id]=itemSaleList
402
        itemSaleMap[val.item_id]=itemSaleList
388
        
403
        
389
        if snapdealDetails.rank==0:
404
        if snapdealDetails.rank==0:
390
            snapdealDetails.ourSp = mpItem.currentSp
405
            snapdealDetails.ourSp = mpItem.currentSp
391
            snapdealDetails.ourOfferPrice = mpItem.currentSp
406
            snapdealDetails.ourOfferPrice = mpItem.currentSp
Line 1078... Line 1093...
1078
    EmailAttachmentSender.mail("build@shop2020.in", "cafe@nes", ["rajneesh.arora@saholic.com","rajveer.singh@saholic.com","kshitij.sood@saholic.com"], " Snapdeal Auto Pricing "+runType+" " + str(timestamp), "", [get_attachment_part(filename)], [""], [])
1093
    EmailAttachmentSender.mail("build@shop2020.in", "cafe@nes", ["rajneesh.arora@saholic.com","rajveer.singh@saholic.com","kshitij.sood@saholic.com"], " Snapdeal Auto Pricing "+runType+" " + str(timestamp), "", [get_attachment_part(filename)], [""], [])
1079
 
1094
 
1080
 
1095
 
1081
def sendAutoPricingMail(successfulAutoDecrease,successfulAutoIncrease):
1096
def sendAutoPricingMail(successfulAutoDecrease,successfulAutoIncrease):
1082
    xstr = lambda s: s or ""
1097
    xstr = lambda s: s or ""
-
 
1098
    catalog_client = CatalogClient().get_client()
-
 
1099
    inventory_client = InventoryClient().get_client()
1083
    message="""<html>
1100
    message="""<html>
1084
            <body>
1101
            <body>
1085
            <h3>Auto Decrease Items</h3>
1102
            <h3>Auto Decrease Items</h3>
1086
            <table border="1" style="width:100%;">
1103
            <table border="1" style="width:100%;">
1087
            <thead>
1104
            <thead>
1088
            <tr><th>Item Id</th>
1105
            <tr><th>Item Id</th>
1089
            <th>Product Name</th>
1106
            <th>Product Name</th>
1090
            <th>Old Price</th>
1107
            <th>Old Price</th>
1091
            <th>New Price</th>
1108
            <th>New Price</th>
-
 
1109
            <th>Old Margin</th>
-
 
1110
            <th>New Margin</th>
-
 
1111
            <th>Snapdeal Inventory</th>
1092
            </tr></thead>
1112
            </tr></thead>
1093
            <tbody>"""
1113
            <tbody>"""
1094
    for item in successfulAutoDecrease:
1114
    for item in successfulAutoDecrease:
1095
        it = Item.query.filter_by(id=item.item_id).one()
1115
        it = Item.query.filter_by(id=item.item_id).one()
-
 
1116
        mpItem = MarketplaceItems.get_by(itemId=item.item_id,source=OrderSource.SNAPDEAL)
-
 
1117
        sdItem = SnapdealItem.get_by(item_id=item.item_id)
-
 
1118
        warehouse = inventory_client.getWarehouse(sdItem.warehouseId)
-
 
1119
        vatRate = catalog_client.getVatPercentageForItem(item.item_id, warehouse.stateId, item.proposedSellingPrice)
-
 
1120
        newMargin = round((getNewOurTp(mpItem,item.proposedSellingPrice) - getNewLowestPossibleTp(mpItem,item.ourNlc,vatRate,item.proposedSellingPrice)),1)  
1096
        message+="""<tr>
1121
        message+="""<tr>
1097
                <td style="text-align:center">"""+str(item.item_id)+"""</td>
1122
                <td style="text-align:center">"""+str(item.item_id)+"""</td>
1098
                <td style="text-align:center">"""+xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color)+"""</td>
1123
                <td style="text-align:center">"""+xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color)+"""</td>
1099
                <td style="text-align:center">"""+str(item.ourSellingPrice)+"""</td>
1124
                <td style="text-align:center">"""+str(item.ourSellingPrice)+"""</td>
1100
                <td style="text-align:center">"""+str(math.ceil(item.proposedSellingPrice))+"""</td></tr>"""
1125
                <td style="text-align:center">"""+str(math.ceil(item.proposedSellingPrice))+"""</td>
-
 
1126
                <td style="text-align:center">"""+str(round(item.margin,1))+"""</td>
-
 
1127
                <td style="text-align:center">"""+str(newMargin)+"""</td>
-
 
1128
                <td style="text-align:center">"""+str(item.ourInventory)+"""</td>
-
 
1129
                </tr>"""
1101
    message+="""</tbody></table><h3>Auto Increase Items</h3><table border="1" style="width:100%;">
1130
    message+="""</tbody></table><h3>Auto Increase Items</h3><table border="1" style="width:100%;">
1102
            <thead>
1131
            <thead>
1103
            <tr><th>Item Id</th>
1132
            <tr><th>Item Id</th>
1104
            <th>Product Name</th>
1133
            <th>Product Name</th>
1105
            <th>Old Price</th>
1134
            <th>Old Price</th>
1106
            <th>New Price</th>
1135
            <th>New Price</th>
-
 
1136
            <th>Old Margin</th>
-
 
1137
            <th>New Margin</th>
-
 
1138
            <th>Snapdeal Inventory</th>
1107
            </tr></thead>
1139
            </tr></thead>
1108
            <tbody>"""
1140
            <tbody>"""
1109
    for item in successfulAutoIncrease:
1141
    for item in successfulAutoIncrease:
1110
        it = Item.query.filter_by(id=item.item_id).one()
1142
        it = Item.query.filter_by(id=item.item_id).one()
-
 
1143
        mpItem = MarketplaceItems.get_by(itemId=item.item_id,source=OrderSource.SNAPDEAL)
-
 
1144
        sdItem = SnapdealItem.get_by(item_id=item.item_id)
-
 
1145
        warehouse = inventory_client.getWarehouse(sdItem.warehouseId)
-
 
1146
        vatRate = catalog_client.getVatPercentageForItem(item.item_id, warehouse.stateId, item.proposedSellingPrice)
-
 
1147
        newMargin = round((getNewOurTp(mpItem,item.proposedSellingPrice) - getNewLowestPossibleTp(mpItem,item.ourNlc,vatRate,item.proposedSellingPrice)),1)  
1111
        message+="""<tr>
1148
        message+="""<tr>
1112
                <td style="text-align:center">"""+str(item.item_id)+"""</td>
1149
                <td style="text-align:center">"""+str(item.item_id)+"""</td>
1113
                <td style="text-align:center">"""+xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color)+"""</td>
1150
                <td style="text-align:center">"""+xstr(it.brand)+" "+xstr(it.model_name)+" "+xstr(it.model_number)+" "+xstr(it.color)+"""</td>
1114
                <td style="text-align:center">"""+str(item.ourSellingPrice)+"""</td>
1151
                <td style="text-align:center">"""+str(item.ourSellingPrice)+"""</td>
1115
                <td style="text-align:center">"""+str(math.ceil(item.ourSellingPrice+max(10,.01*item.ourSellingPrice)))+"""</td></tr>"""
1152
                <td style="text-align:center">"""+str(math.ceil(item.ourSellingPrice+max(10,.01*item.ourSellingPrice)))+"""</td>
-
 
1153
                <td style="text-align:center">"""+str(round(item.margin,1))+"""</td>
-
 
1154
                <td style="text-align:center">"""+str(newMargin)+"""</td>
-
 
1155
                <td style="text-align:center">"""+str(item.ourInventory)+"""</td>
-
 
1156
                </tr>"""
1116
    message+="""</tbody></table></body></html>"""
1157
    message+="""</tbody></table></body></html>"""
1117
    print message
1158
    print message
1118
    mailServer = smtplib.SMTP("smtp.gmail.com", 587)
1159
    mailServer = smtplib.SMTP("smtp.gmail.com", 587)
1119
    mailServer.ehlo()
1160
    mailServer.ehlo()
1120
    mailServer.starttls()
1161
    mailServer.starttls()
Line 1396... Line 1437...
1396
def getOurTp(snapdealDetails,val,spm,mpItem):
1437
def getOurTp(snapdealDetails,val,spm,mpItem):
1397
    if snapdealDetails.rank==0:
1438
    if snapdealDetails.rank==0:
1398
        return mpItem.currentTp
1439
        return mpItem.currentTp
1399
    ourTp = snapdealDetails.ourSp- snapdealDetails.ourSp*(mpItem.commission/100+mpItem.emiFee/100)*(1+(mpItem.serviceTax/100))-(val.courierCost+mpItem.closingFee)*(1+(mpItem.serviceTax/100));
1440
    ourTp = snapdealDetails.ourSp- snapdealDetails.ourSp*(mpItem.commission/100+mpItem.emiFee/100)*(1+(mpItem.serviceTax/100))-(val.courierCost+mpItem.closingFee)*(1+(mpItem.serviceTax/100));
1400
    return round(ourTp,2)
1441
    return round(ourTp,2)
-
 
1442
 
-
 
1443
def getNewLowestPossibleTp(mpItem,nlc,vatRate,proposedSellingPrice):
-
 
1444
    vat = (proposedSellingPrice/(1+(vatRate/100))-(nlc/(1+(vatRate/100))))*(vatRate/100);
-
 
1445
    inHouseCost = 15+vat+(mpItem.returnProvision/100)*proposedSellingPrice+mpItem.otherCost;
-
 
1446
    lowest_possible_tp = nlc+inHouseCost;
-
 
1447
    return round(lowest_possible_tp,2)
-
 
1448
 
-
 
1449
def getNewOurTp(mpItem,proposedSellingPrice):
-
 
1450
    ourTp = proposedSellingPrice- proposedSellingPrice*(mpItem.commission/100+mpItem.emiFee/100)*(1+(mpItem.serviceTax/100))-(mpItem.courierCost+mpItem.closingFee)*(1+(mpItem.serviceTax/100));
-
 
1451
    return round(ourTp,2)
1401
    
1452
    
1402
def getLowestPossibleSp(snapdealDetails,val,spm,mpItem):
1453
def getLowestPossibleSp(snapdealDetails,val,spm,mpItem):
1403
    if snapdealDetails.rank==0:
1454
    if snapdealDetails.rank==0:
1404
        return mpItem.minimumPossibleSp
1455
        return mpItem.minimumPossibleSp
1405
    lowestPossibleSp = (val.nlc+(val.courierCost+mpItem.closingFee)*(1+(mpItem.serviceTax/100))*(1+(val.vatRate/100))+(15+mpItem.otherCost)*(1+(val.vatRate)/100))/(1-(mpItem.commission/100+mpItem.emiFee/100)*(1+(mpItem.serviceTax/100))*(1+(val.vatRate)/100)-(mpItem.returnProvision/100)*(1+(val.vatRate)/100));
1456
    lowestPossibleSp = (val.nlc+(val.courierCost+mpItem.closingFee)*(1+(mpItem.serviceTax/100))*(1+(val.vatRate/100))+(15+mpItem.otherCost)*(1+(val.vatRate)/100))/(1-(mpItem.commission/100+mpItem.emiFee/100)*(1+(mpItem.serviceTax/100))*(1+(val.vatRate)/100)-(mpItem.returnProvision/100)*(1+(val.vatRate)/100));