Rev 16277 | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 31-Jul-2015This script fetches the transfer in mismatches as per the shipment references receivedand sends an email to concerned people.@author: manish'''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.fetchScansPerTransferInvoiceNumber(to_java_date(datetime.datetime.strptime(date, '%Y-%m-%d')))def reportMismatches(mismatches, date):print mismatchesbody = ["\t".join(['Date', 'Shipment Reference', 'Source', 'Transfer Lot Id', 'No. of Items as per Shipment Reference', 'Inventory Type', 'No. of Items actually scanned'])]unscannedCount = 0for invoiceScan in mismatches:body.append("\t".join([date, invoiceScan.shipmentReference, invoiceScan.source, str(invoiceScan.transferLotId), str(invoiceScan.quantity), invoiceScan.inventoryType, str(invoiceScan.scannedQuantity)]))unscannedCount += invoiceScan.quantity - invoiceScan.scannedQuantitysubject = date + ': All items scanned in Shipment References!'if body.__len__() > 1:subject = date + ': ' + str(abs(unscannedCount))if unscannedCount > 0:subject += ' items not scanned IN yet in below Shipment References'else:subject += ' extra items got scanned in below Shipment References'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))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()