Added X3 information to return.

master
bleeson 2025-09-10 15:23:00 -07:00
parent d6606e0c17
commit 9184f0dce5
1 changed files with 23 additions and 6 deletions

View File

@ -218,9 +218,9 @@ def process_return(edi_filename: pathlib.Path):
rcpdat = datetime.datetime.strptime(rcpdat, "%Y%m%d").date() # 20230922 rcpdat = datetime.datetime.strptime(rcpdat, "%Y%m%d").date() # 20230922
if fields[0] == 'N9' and fields[1] == 'PO': if fields[0] == 'N9' and fields[1] == 'PO':
po = fields[2] po = fields[2]
if fields[0] == 'N9' and fields[1] == 'ZZ': if fields[0] == 'N9' and fields[1] == 'ZZ' and fields[2] == 'INFO':
#N9*ZZ*INFO #N9*ZZ*INFO*REFUSAL AS OVERAGE
reason = fields[2] reason = fields[3]
if fields[0] == 'N9' and fields[1] == 'CR': if fields[0] == 'N9' and fields[1] == 'CR':
shandex_customer = fields[2] shandex_customer = fields[2]
shandex_customer = customer_map_lookup(shandex_customer + '%') + '\n' shandex_customer = customer_map_lookup(shandex_customer + '%') + '\n'
@ -232,13 +232,30 @@ def process_return(edi_filename: pathlib.Path):
uom = fix_uom(uom) uom = fix_uom(uom)
line_data.append(f'{x3_sku}, {gtin}, {qty_str}, {uom}, {lot}') line_data.append(f'{x3_sku}, {gtin}, {qty_str}, {uom}, {lot}')
customer_info = customer_lookup(po) 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 shipment_info = shipment_lookup(po)
simple_email_notification.email_noticication(['bleeson@stashtea.com','scrinvoices@stashtea.com','business@stashtea.com'], line_data = [f'Return#: {return_num}\n' + customer_info + shipment_info +f'Return date: {rcpdat}\nReason: {reason}\nPO: {po}\nCases: {running_sum}'] + line_data
'Shandex Return',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 # simple_email_notification.email_noticication(['bleeson@stashtea.com'],#testing
# f'New Shandex Return {return_num}',line_data) # 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): def customer_map_lookup(customer_code):
possible_customers = [] possible_customers = []
with yamamotoyama.get_connection() as data_base: with yamamotoyama.get_connection() as data_base: