From b297ffe68ac6d1fc21a3e3c9a6bc3e6fca99cf79 Mon Sep 17 00:00:00 2001 From: bleeson Date: Thu, 6 Jun 2024 09:05:09 -0700 Subject: [PATCH] Fix for UOM lookups and tracking both BOL and PO# on Deliveries. --- edi_867.py | 59 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/edi_867.py b/edi_867.py index eac556d..3bb6ec6 100644 --- a/edi_867.py +++ b/edi_867.py @@ -36,10 +36,11 @@ SOURCE_867_FILENAME_RE = re.compile( r"\A 867_STASH-YAMAMOTOYAMA_ .* [.]edi \Z", re.X | re.M | re.S ) -UOM_MAPPING = { - "CA" : "CS", - "EC" : "EA" -} +# Not needed, Shandex stores everything how they want so we need to look up in X3 +# UOM_MAPPING = { + # "CA" : "CS", + # "EC" : "EA" +#} #NAME_ADDRESS_CITY_TERRITORY_POSTAL : X3 Customer Code X3_CUSTOMER_MAPPING = { 'AVRI1000_AVRIQC' : 'AVRI0001', @@ -63,7 +64,9 @@ X3_CUSTOMER_MAPPING = { 'SATA1000_SATAQC' : 'SATA0002', 'UNFI1000_UNFIBC' : 'UNFI0011', 'UNFI1000_UNFION' : 'UNFI0004', - 'SAMP1000_0000' : 'YARI0001' + 'SAMP1000_0000' : 'YARI0001', + 'PURI1000_PURIQC' : 'PURI0005', + 'JIVA1000_JIVABC' : 'JIVA0002', } def main(): @@ -133,22 +136,43 @@ def tokens_from_edi_file( yield fields def get_product_from_gtin(gtin): + #pprint.pprint(gtin) with yamamotoyama.get_connection() as database: result = database.query( """ select - ITM.ITMREF_0, - ITM.ITMDES1_0 + [ITM].[ITMREF_0], + [ITM].[ITMDES1_0], + [ITM].[EANCOD_0], + [ITM].[ZCASEUPC_0], + [ITM].[STU_0] from PROD.ITMMASTER ITM join PROD.ITMFACILIT ITF on ITM.ITMREF_0 = ITF.ITMREF_0 and ITF.STOFCY_0 = 'WON' where - ZCASEUPC_0 = :zcaseupc - + replace([ITM].[ZCASEUPC_0],' ','') = :zcaseupc """, zcaseupc=gtin, ).first() + if result is None: + result = database.query( + """ + select + [ITM].[ITMREF_0], + [ITM].[ITMDES1_0], + [ITM].[EANCOD_0], + [ITM].[ZCASEUPC_0], + [ITM].[STU_0] + from [PROD].[ITMMASTER] [ITM] + join [PROD].[ITMFACILIT] [ITF] + on [ITM].[ITMREF_0] = [ITF].[ITMREF_0] + and [ITF].[STOFCY_0] = 'WON' + where + replace([ITM].[EANCOD_0],' ','') = :zcaseupc + """, + zcaseupc=gtin, + ).first() return result def process_file(edi_filename: pathlib.Path): @@ -157,6 +181,7 @@ def process_file(edi_filename: pathlib.Path): """ shipping_date = '' previous_picking_number = '' + po_number = '' warehouse_shipment = WarehouseShipment() for fields in tokens_from_edi_file(edi_filename): if fields[0] == "DTM": @@ -164,6 +189,9 @@ def process_file(edi_filename: pathlib.Path): if fields[0] == "PTD" and len(fields) > 2:#There is one PTD in the header that is not used picking_number = fields[5] warehouse_shipment.header.ylicplate = f'{previous_picking_number}' + if po_number != '': + warehouse_shipment.header.yclippership = warehouse_shipment.header.ylicplate + warehouse_shipment.header.ylicplate = f'{po_number}' if picking_number != previous_picking_number and previous_picking_number != '': if warehouse_shipment.header.bpdnam != 'Shandex Group': #pprint.pprint(warehouse_shipment.header.ylicplate) @@ -171,14 +199,15 @@ def process_file(edi_filename: pathlib.Path): shipping_date, "%Y%m%d") time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") with yamamotoyama.x3_imports.open_import_file( - IMPORTS_DIRECTORY / f"ZSHIP867_{picking_number}_{time_stamp}.dat" + IMPORTS_DIRECTORY / f"ZSHIP867_{warehouse_shipment.header.ylicplate}_{time_stamp}.dat" ) as import_file: warehouse_shipment.output(import_file) warehouse_shipment = WarehouseShipment() + po_number = '' warehouse_shipment.header.ylicplate = f'{picking_number}' previous_picking_number = picking_number if fields[0] =='REF' and fields[1] == 'IL': - picking_number = fields[2] + po_number = fields[2] if fields[0] == "N1" and fields[1] == 'ST': ship_to_customer = fields[2] shandex_code_part1 = fields[4] @@ -194,8 +223,10 @@ def process_file(edi_filename: pathlib.Path): ship_to_zip = fields[3] warehouse_shipment.header.bpdposcod = ship_to_zip warehouse_shipment.header.bpdcty = ship_to_city - warehouse_shipment.header.bpdsat = ship_to_province + warehouse_shipment.header.bpdsat = ship_to_province customer_key = warehouse_shipment.create_customer_key(shandex_code_part2, shandex_code_part1) + if customer_key == 'SAMP1000_0000': #flag sample orders better + warehouse_shipment.header.bpdnam = 'SMP: ' + warehouse_shipment.header.bpdnam if customer_key not in X3_CUSTOMER_MAPPING.keys(): pprint.pprint(customer_key + ' not found.') missing_customer_alert(customer_key) @@ -212,10 +243,10 @@ def process_file(edi_filename: pathlib.Path): if fields[0] == "AMT": #AMT*LP*53.90 _, _, price = fields[:3] - sau = UOM_MAPPING[uom] lookup_values = get_product_from_gtin(gtin) itmref = lookup_values['ITMREF_0'] itmdes = lookup_values['ITMDES1_0'] + sau = lookup_values['STU_0'] #pprint.pprint(itmdes) subdetail = WarehouseShipmentSubDetail( qtypcu=-1 * int(qty_str), @@ -410,6 +441,7 @@ class WarehouseShipmentHeader: pjt: str = "" bptnum: str = "" ylicplate: str = "SHANDEX" + yclippership: str = "" invdtaamt_2: decimal.Decimal = decimal.Decimal() invdtaamt_3: decimal.Decimal = decimal.Decimal() invdtaamt_4: decimal.Decimal = decimal.Decimal() @@ -494,6 +526,7 @@ class WarehouseShipmentHeader: self.pjt, self.bptnum, self.ylicplate, + self.yclippership, self.invdtaamt_2, self.invdtaamt_3, self.invdtaamt_4,