Subversion Repositories SmartDukaan

Rev

Rev 21162 | 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):
7088 amar.kumar 20
    print mismatches
5496 mandeep.dh 21
    body = ["\t".join(['Date', 'Invoice Number', 'Supplier', 'No. of Items as per Invoice', 'No. of Items actually scanned'])]
22
    unscannedCount = 0
23
    for invoiceScan in mismatches:
24
        body.append("\t".join([date, invoiceScan.invoiceNumber, invoiceScan.supplierName, str(invoiceScan.numItems), str(invoiceScan.scannedQuantity)]))
25
        unscannedCount += invoiceScan.numItems - invoiceScan.scannedQuantity
26
    subject = date + ': All items scanned IN!'
27
    if body.__len__() > 1:
5576 mandeep.dh 28
        subject = date + ': ' + str(abs(unscannedCount))
5545 mandeep.dh 29
        if unscannedCount > 0:
30
            subject += ' items not scanned IN yet'
31
        else:
32
            subject += ' extra items got scanned IN'
23631 amit.gupta 33
    EmailAttachmentSender.mail('cnc.center@shop2020.in', '5h0p2o2o', ['amit.gupta@shop2020.in','shivam9718617332@gmail.com', 'deena.nath@smartdukaan.com'], subject, "\n".join(body))
5496 mandeep.dh 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()