Subversion Repositories SmartDukaan

Rev

Rev 5530 | Go to most recent revision | Details | 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:
27
        subject = date + ': ' + str(unscannedCount) + ' items not scanned IN yet'
28
    EmailAttachmentSender.mail('cnc.center@shop2020.in', '5h0p2o2o', 'mandeep.dhir@shop2020.in', subject, "\n".join(body))
29
 
30
def generateAndReportScanMismatches(date):
31
    reportMismatches(generateScanMismatches(date), date)
32
 
33
def main():
34
    parser = OptionParser()
35
    parser.add_option("-d", "--date", dest="date", default = datetime.date.today().isoformat(), type='string', help='date in YYYY-MM-DD format')
36
    (options, args) = parser.parse_args()
37
    generateAndReportScanMismatches(options.date)
38
 
39
if __name__ == '__main__':
40
    main()