diff --git a/edi_947.py b/edi_947.py index f49a005..3d49446 100644 --- a/edi_947.py +++ b/edi_947.py @@ -65,10 +65,29 @@ DAMAGE_CODE_DESCRIPTIONS_MAPPING = { "AA" : "Physical Count", "05" : "Product Put on Hold" } - +#translate WMS status codes from shandex to suggested X3 status codes +SHANDEX_WMS_CODES = { + "G":"A", + "A":"A", + "U":"A", + "C":"Q", + "H":"Q", + "Q":"QH", + "R":"QH", + "Z":"RD", + "B":"RD", + "D":"RD", + "E":"RD", + "F":"RD", + "O":"RD", + "X":"RD", + "P":"RD", + "L":"RD", + "W":"RD", +} #This transaction can also be used for inventory counts, which we will report on but not process -EMAIL_ONLY_CODES = ['AA'] +EMAIL_ONLY_CODES = ['AA','AV','07','05','55'] #When we receive an EDI to change status, it will either be A or Q, the reverse of the earlier code DAMAGE_CODE_SOURCE_MAPPING = { @@ -190,14 +209,14 @@ def gtin_lookup(gtin): ).first()["ITMREF_0"] -def stock_movement_alert(itmref, qty, lot, status): +def stock_movement_alert(itmref, qty, lot, status, license_plate, control_number, reason, bucket): msg = MIMEMultipart() msg['Subject'] = 'New Stock Change from Shandex' msg['Precedence'] = 'bulk' msg['From'] = 'x3report@stashtea.com' msg['To'] = 'woninventory@stashtea.com' msg['CC'] = 'bleeson@stashtea.com,icarrera@yamamotoyama.com' - emailtext = f'Item: {itmref}\nQty: {qty}\nLot: {lot}\nStatus: {DAMAGE_CODE_MAPPING[status]}\nReason: {DAMAGE_CODE_DESCRIPTIONS_MAPPING[status]}' + emailtext = f'Item: {itmref}\nQty: {qty}\nLot: {lot}\nStatus: {DAMAGE_CODE_MAPPING[status]}\nReason: {DAMAGE_CODE_DESCRIPTIONS_MAPPING[status]}\nLP: {license_plate}\nControl: {control_number}\nReason{reason}\nStock Bucket: {bucket}' msg.attach(MIMEText(emailtext, 'plain')) service = gmail_authenticate() encoded_message = base64.urlsafe_b64encode(msg.as_bytes()).decode() @@ -214,6 +233,15 @@ def process_file(edi_filename: pathlib.Path): warehouse_stockchange = StockChange() vcrlin = 0 for fields in tokens_from_edi_file(edi_filename): + status = '' + qty = '' + uom = '' + gtin = '' + lot = '' + license_plate = '' + control_number = '' + reason = '' + bucket = '' if fields[0] == "G62": iptdat = fields[2] warehouse_stockchange.header.iptdat = datetime.datetime.strptime( @@ -226,33 +254,44 @@ def process_file(edi_filename: pathlib.Path): # W19*AV*35*CA**UK*10077652082651***03022026C _, status, qty, uom, _, _, gtin, _, _, lot = fields[:10] product = gtin_lookup(gtin) - stock_movement_alert(product, qty, lot, status) - if status in EMAIL_ONLY_CODES: - continue - warehouse_stockchange.header.vcrdes = DAMAGE_CODE_DESCRIPTIONS_MAPPING[status] - subdetail = StockChangeSubDetail( - qtypcu=int(qty), - qtystu=int(qty), - sta=DAMAGE_CODE_MAPPING[status], - pcu=uom - ) - detail_line = StockChangeDetail( - vcrlin=vcrlin, - itmref=product, - pcu=uom, - sta=DAMAGE_CODE_SOURCE_MAPPING[status], - lot=lot - ) - warehouse_stockchange.append( - detail_line, - subdetail, - ) - time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") - - with yamamotoyama.x3_imports.open_import_file( - IMPORTS_DIRECTORY / f"ZSCS_{transaction_number}_{time_stamp}.dat" - ) as import_file: - warehouse_stockchange.output(import_file) + if fields[0] == 'N9': + if fields[1] == 'LV': + license_plate = fields[2] + elif fields[1] == 'X9': + control_number = fields[2] + elif fields[1] == 'TD': + reason = fields[2] + elif fields[1] == 'ZZ': + bucket = fields[2] + stock_movement_alert(product, qty, lot, status, license_plate, control_number, reason, bucket) + #Per John Pena 9/2025, don't perform imports, only notify + # if status in EMAIL_ONLY_CODES: + # continue + # warehouse_stockchange.header.vcrdes = DAMAGE_CODE_DESCRIPTIONS_MAPPING[status] + # subdetail = StockChangeSubDetail( + # qtypcu=int(qty), + # qtystu=int(qty), + # sta=DAMAGE_CODE_MAPPING[status], + # pcu=uom + # ) + # detail_line = StockChangeDetail( + # vcrlin=vcrlin, + # itmref=product, + # pcu=uom, + # sta=DAMAGE_CODE_SOURCE_MAPPING[status], + # lot=lot + # ) + # warehouse_stockchange.append( + # detail_line, + # subdetail, + # ) + # time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") + + # if warehouse_stockchange.details._details: + # with yamamotoyama.x3_imports.open_import_file( + # IMPORTS_DIRECTORY / f"ZSCS_{transaction_number}_{time_stamp}.dat" + # ) as import_file: + # warehouse_stockchange.output(import_file) @dataclasses.dataclass