diff --git a/edi_944_to_table.py b/edi_944_to_table.py index a40330e..66d1c5c 100644 --- a/edi_944_to_table.py +++ b/edi_944_to_table.py @@ -84,7 +84,7 @@ def main(): shutil.move(edi_filename, EDI_997_DIRECTORY / edi_filename.name) elif SHANDEX_RETURN_944_FILENAME_RE.match(edi_filename.name): process_return(edi_filename) - #TODOshutil.move(edi_filename, EDI_997_DIRECTORY / edi_filename.name) + shutil.move(edi_filename, EDI_997_DIRECTORY / edi_filename.name) def determine_edi_action(edi_filename: pathlib.Path): @@ -191,6 +191,7 @@ def process_return(edi_filename: pathlib.Path): rcpdat = '' reason = '' po = '' + shandex_customer = '' for fields in tokens_from_edi_file(edi_filename): if fields[0] == "W17": #_, _, rcpdat, _, sohnum, sdhnum = fields[:6] @@ -201,6 +202,9 @@ def process_return(edi_filename: pathlib.Path): po = fields[2] if fields[0] == 'N9' and fields[1] == 'ZZ': reason = fields[3] + if fields[0] == 'N9' and fields[1] == 'CR': + shandex_customer = fields[2] + shandex_customer = customer_map_lookup(shandex_customer + '%') + '\n' if fields[0] == "W07": # W07*33*CA**PN*10077652772170*LT*06022027A***UK*10077652772170 _, qty_str, uom, _, _, gtin, _, lot = fields[:8] @@ -210,10 +214,27 @@ def process_return(edi_filename: pathlib.Path): 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) - simple_email_notification.email_noticication(['bleeson@stashtea.com'], - f'New Shandex Return {return_num}',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 customer_map_lookup(customer_code): + possible_customers = [] + with yamamotoyama.get_connection() as data_base: + result = data_base.query( + """ + SELECT DISTINCT + [x3_customer] + FROM [staging].[dbo].[shandex_customer_map] + WHERE shandex_key like :customer_code + """, + customer_code=customer_code, + ).all() + for record in result: + possible_customers.append(record['x3_customer']) + return ','.join(possible_customers) def customer_lookup(po_number):