Subversion Repositories SmartDukaan

Rev

Rev 16277 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
16264 manish.sha 1
'''
2
Created on 31-Jul-2015
3
 
4
This script fetches the transfer in mismatches as per the shipment references received
5
and sends an email to concerned people.
6
 
7
@author: manish
8
'''
9
from optparse import OptionParser
10
from shop2020.clients.WarehouseClient import WarehouseClient
11
from shop2020.utils import EmailAttachmentSender
12
from shop2020.utils.Utils import to_java_date
13
import datetime
14
 
15
def generateScanMismatches(date):
16
    warehouseClient = WarehouseClient().get_client()
17
    return warehouseClient.fetchScansPerTransferInvoiceNumber(to_java_date(datetime.datetime.strptime(date, '%Y-%m-%d')))
18
 
19
def reportMismatches(mismatches, date):
20
    print mismatches
21
    body = ["\t".join(['Date', 'Shipment Reference', 'Source', 'Transfer Lot Id', 'No. of Items as per Shipment Reference', 'Inventory Type', 'No. of Items actually scanned'])]
22
    unscannedCount = 0
23
    for invoiceScan in mismatches:
24
        body.append("\t".join([date, invoiceScan.shipmentReference, invoiceScan.source, str(invoiceScan.transferLotId), str(invoiceScan.quantity), invoiceScan.inventoryType, str(invoiceScan.scannedQuantity)]))
25
        unscannedCount += invoiceScan.quantity - invoiceScan.scannedQuantity
26
    subject = date + ': All items scanned in Shipment References!'
27
    if body.__len__() > 1:
28
        subject = date + ': ' + str(abs(unscannedCount))
29
        if unscannedCount > 0:
30
            subject += ' items not scanned IN yet in below Shipment References'
31
        else:
32
            subject += ' extra items got scanned in below Shipment References'
20168 amit.gupta 33
    EmailAttachmentSender.mail('adwords@shop2020.in', 'adwords_shop2020', ['amit.gupta@shop2020.in', 'warehousedel@shop2020.in', 'himanshu.pandey@shop2020.in', 'shiv.kumar@shop2020.in'], subject, "\n".join(body))
16264 manish.sha 34
 
35
def generateAndReportScanMismatches(date):
36
    reportMismatches(generateScanMismatches(date), date)
37
 
38
def main():
39
    parser = OptionParser()
40
    parser.add_option("-d", "--date", dest="date", default = datetime.date.today().isoformat(), type='string', help='date in YYYY-MM-DD format')
41
    (options, args) = parser.parse_args()
42
    generateAndReportScanMismatches(options.date)
43
 
44
if __name__ == '__main__':
45
    main()