Rev 7088 | Rev 10322 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 22-Jun-2012This script fetches the scan mismatches as per the invoices receivedand sends an email to concerned people.@author: mandeep'''from optparse import OptionParserfrom shop2020.clients.WarehouseClient import WarehouseClientfrom shop2020.utils import EmailAttachmentSenderfrom shop2020.utils.Utils import to_java_dateimport datetimedef generateScanMismatches(date):warehouseClient = WarehouseClient().get_client()return warehouseClient.fetchScansPerInvoiceNumber(to_java_date(datetime.datetime.strptime(date, '%Y-%m-%d')))def reportMismatches(mismatches, date):print mismatchesbody = ["\t".join(['Date', 'Invoice Number', 'Supplier', 'No. of Items as per Invoice', 'No. of Items actually scanned'])]unscannedCount = 0for invoiceScan in mismatches:body.append("\t".join([date, invoiceScan.invoiceNumber, invoiceScan.supplierName, str(invoiceScan.numItems), str(invoiceScan.scannedQuantity)]))unscannedCount += invoiceScan.numItems - invoiceScan.scannedQuantitysubject = date + ': All items scanned IN!'if body.__len__() > 1:subject = date + ': ' + str(abs(unscannedCount))if unscannedCount > 0:subject += ' items not scanned IN yet'else:subject += ' extra items got scanned IN'EmailAttachmentSender.mail('cnc.center@shop2020.in', '5h0p2o2o', ['amar.kumar@shop2020.in', 'rajveer.singh@shop2020.in', 'sandeep.sachdeva@shop2020.in', 'amit.kumar@shop2020.in'], subject, "\n".join(body))def generateAndReportScanMismatches(date):reportMismatches(generateScanMismatches(date), date)def main():parser = OptionParser()parser.add_option("-d", "--date", dest="date", default = datetime.date.today().isoformat(), type='string', help='date in YYYY-MM-DD format')(options, args) = parser.parse_args()generateAndReportScanMismatches(options.date)if __name__ == '__main__':main()