Subversion Repositories SmartDukaan

Rev

Rev 5576 | Rev 7088 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5496 mandeep.dh 1
'''
2
Created on 22-Jun-2012
3
 
4
This script fetches the scan mismatches as per the invoices received
5
and sends an email to concerned people.
6
 
7
@author: mandeep
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.fetchScansPerInvoiceNumber(to_java_date(datetime.datetime.strptime(date, '%Y-%m-%d')))
18
 
19
def reportMismatches(mismatches, date):
20
    body = ["\t".join(['Date', 'Invoice Number', 'Supplier', 'No. of Items as per Invoice', 'No. of Items actually scanned'])]
21
    unscannedCount = 0
22
    for invoiceScan in mismatches:
23
        body.append("\t".join([date, invoiceScan.invoiceNumber, invoiceScan.supplierName, str(invoiceScan.numItems), str(invoiceScan.scannedQuantity)]))
24
        unscannedCount += invoiceScan.numItems - invoiceScan.scannedQuantity
25
    subject = date + ': All items scanned IN!'
26
    if body.__len__() > 1:
5576 mandeep.dh 27
        subject = date + ': ' + str(abs(unscannedCount))
5545 mandeep.dh 28
        if unscannedCount > 0:
29
            subject += ' items not scanned IN yet'
30
        else:
31
            subject += ' extra items got scanned IN'
5964 amar.kumar 32
    EmailAttachmentSender.mail('cnc.center@shop2020.in', '5h0p2o2o', ['mandeep.dhir@shop2020.in', 'amit.kumar@shop2020.in', 'ashutosh.saxena@shop2020.in', 'sandeep.sachdeva@shop2020.in','amar.kumar@shop2020.in'], subject, "\n".join(body))
5496 mandeep.dh 33
 
34
def generateAndReportScanMismatches(date):
35
    reportMismatches(generateScanMismatches(date), date)
36
 
37
def main():
38
    parser = OptionParser()
39
    parser.add_option("-d", "--date", dest="date", default = datetime.date.today().isoformat(), type='string', help='date in YYYY-MM-DD format')
40
    (options, args) = parser.parse_args()
41
    generateAndReportScanMismatches(options.date)
42
 
43
if __name__ == '__main__':
44
    main()