Fix for UOM lookups and tracking both BOL and PO# on Deliveries.
							parent
							
								
									eb4d0beac8
								
							
						
					
					
						commit
						b297ffe68a
					
				
							
								
								
									
										57
									
								
								edi_867.py
								
								
								
								
							
							
						
						
									
										57
									
								
								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] | ||||
|  | @ -196,6 +225,8 @@ def process_file(edi_filename: pathlib.Path): | |||
|             warehouse_shipment.header.bpdcty = ship_to_city | ||||
|             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, | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue