From 9184f0dce55067bb9b1df81a80da0f259c3b4eca Mon Sep 17 00:00:00 2001 From: bleeson Date: Wed, 10 Sep 2025 15:23:00 -0700 Subject: [PATCH] Added X3 information to return. --- edi_944_to_table.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/edi_944_to_table.py b/edi_944_to_table.py index e562600..784ffd5 100644 --- a/edi_944_to_table.py +++ b/edi_944_to_table.py @@ -218,9 +218,9 @@ def process_return(edi_filename: pathlib.Path): rcpdat = datetime.datetime.strptime(rcpdat, "%Y%m%d").date() # 20230922 if fields[0] == 'N9' and fields[1] == 'PO': po = fields[2] - if fields[0] == 'N9' and fields[1] == 'ZZ': - #N9*ZZ*INFO - reason = fields[2] + if fields[0] == 'N9' and fields[1] == 'ZZ' and fields[2] == 'INFO': + #N9*ZZ*INFO*REFUSAL AS OVERAGE + reason = fields[3] if fields[0] == 'N9' and fields[1] == 'CR': shandex_customer = fields[2] shandex_customer = customer_map_lookup(shandex_customer + '%') + '\n' @@ -232,13 +232,30 @@ def process_return(edi_filename: pathlib.Path): uom = fix_uom(uom) line_data.append(f'{x3_sku}, {gtin}, {qty_str}, {uom}, {lot}') customer_info = customer_lookup(po) - line_data = [f'Return#: {return_num}\n' + customer_info + f'Return date: {rcpdat}\nReason: {reason}\nPO: {po}\nCases: {running_sum}'] + line_data - simple_email_notification.email_noticication(['bleeson@stashtea.com','scrinvoices@stashtea.com','business@stashtea.com'], - 'Shandex Return',line_data) + shipment_info = shipment_lookup(po) + line_data = [f'Return#: {return_num}\n' + customer_info + shipment_info +f'Return date: {rcpdat}\nReason: {reason}\nPO: {po}\nCases: {running_sum}'] + line_data + simple_email_notification.email_noticication(['bleeson@stashtea.com','scrinvoices@stashtea.com','business@stashtea.com'],'Shandex Return',line_data) # simple_email_notification.email_noticication(['bleeson@stashtea.com'],#testing # f'New Shandex Return {return_num}',line_data) +def shipment_lookup(po_number): + with yamamotoyama.get_connection() as data_base: + result = data_base.query( + """ + SELECT + string_agg(SDH.SDHNUM_0+' - '+SDH.BPCORD_0,', ')[Customers] + FROM [staging].[dbo].[shandex_shipments] + left join x3.PROD.SDELIVERY SDH + on [shandex_shipments].ylicplate = SDH.YLICPLATE_0 + and SDH.STOFCY_0 = 'WON' + where yclippership = :po_number + """, + po_number=po_number, + ).first() + return f"X3 Shipment Info: {result['Customers']}\n" + + def customer_map_lookup(customer_code): possible_customers = [] with yamamotoyama.get_connection() as data_base: