Extra details in return messages
parent
268cf9e298
commit
674fba9f88
|
@ -78,14 +78,13 @@ def main():
|
||||||
Do it!
|
Do it!
|
||||||
"""
|
"""
|
||||||
for edi_filename in X12_DIRECTORY.iterdir():
|
for edi_filename in X12_DIRECTORY.iterdir():
|
||||||
pprint.pprint(edi_filename.name)
|
|
||||||
if SHANDEX_944_FILENAME_RE.match(edi_filename.name):
|
if SHANDEX_944_FILENAME_RE.match(edi_filename.name):
|
||||||
determine_edi_action(edi_filename)
|
determine_edi_action(edi_filename)
|
||||||
# file moved to 997 processing folder to be sent later
|
# file moved to 997 processing folder to be sent later
|
||||||
shutil.move(edi_filename, EDI_997_DIRECTORY / edi_filename.name)
|
shutil.move(edi_filename, EDI_997_DIRECTORY / edi_filename.name)
|
||||||
elif SHANDEX_RETURN_944_FILENAME_RE.match(edi_filename.name):
|
elif SHANDEX_RETURN_944_FILENAME_RE.match(edi_filename.name):
|
||||||
process_return(edi_filename)
|
process_return(edi_filename)
|
||||||
shutil.move(edi_filename, EDI_997_DIRECTORY / edi_filename.name)
|
#TODOshutil.move(edi_filename, EDI_997_DIRECTORY / edi_filename.name)
|
||||||
|
|
||||||
|
|
||||||
def determine_edi_action(edi_filename: pathlib.Path):
|
def determine_edi_action(edi_filename: pathlib.Path):
|
||||||
|
@ -186,21 +185,61 @@ def process_return(edi_filename: pathlib.Path):
|
||||||
x3_uom = uom
|
x3_uom = uom
|
||||||
return x3_uom
|
return x3_uom
|
||||||
pohnum = ''
|
pohnum = ''
|
||||||
line_data = ['New Shandex Return, can it be matched to an order in the system-\nFix the email up so it looks good for CS']
|
line_data = []
|
||||||
|
running_sum = 0
|
||||||
|
return_num = ''
|
||||||
|
rcpdat = ''
|
||||||
|
reason = ''
|
||||||
|
po = ''
|
||||||
for fields in tokens_from_edi_file(edi_filename):
|
for fields in tokens_from_edi_file(edi_filename):
|
||||||
if fields[0] == "W17":
|
if fields[0] == "W17":
|
||||||
#_, _, rcpdat, _, sohnum, sdhnum = fields[:6]
|
#_, _, rcpdat, _, sohnum, sdhnum = fields[:6]
|
||||||
#W17*F*20250327*143365*RA9000022
|
#W17*F*20250327*143365*RA9000022
|
||||||
_, _, rcpdat, _, sohnum = fields[:5]
|
_, _, rcpdat, _, return_num, sohnum_0 = fields[:6]
|
||||||
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':
|
||||||
|
po = fields[2]
|
||||||
|
if fields[0] == 'N9' and fields[1] == 'ZZ':
|
||||||
|
reason = fields[3]
|
||||||
if fields[0] == "W07":
|
if fields[0] == "W07":
|
||||||
# W07*33*CA**PN*10077652772170*LT*06022027A***UK*10077652772170
|
# W07*33*CA**PN*10077652772170*LT*06022027A***UK*10077652772170
|
||||||
_, qty_str, uom, _, _, gtin, _, lot = fields[:8]
|
_, qty_str, uom, _, _, gtin, _, lot = fields[:8]
|
||||||
|
running_sum += int(qty_str)
|
||||||
x3_sku = gtin_to_sku(gtin)
|
x3_sku = gtin_to_sku(gtin)
|
||||||
uom = fix_uom(uom)
|
uom = fix_uom(uom)
|
||||||
line_data.append(f'{x3_sku} {qty_str} {uom} {lot}')
|
line_data.append(f'{x3_sku}, {gtin}, {qty_str}, {uom}, {lot}')
|
||||||
simple_email_notification.email_noticication(['bleeson@stashtea.com','scrinvoices@stashtea.com','business@stashtea.com'],
|
customer_info = customer_lookup(po)
|
||||||
'Shandex Return',line_data)
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
def customer_lookup(po_number):
|
||||||
|
with yamamotoyama.get_connection() as data_base:
|
||||||
|
result = data_base.query(
|
||||||
|
"""
|
||||||
|
SELECT
|
||||||
|
count([ylicplate])[orders]
|
||||||
|
FROM [staging].[dbo].[shandex_shipments]
|
||||||
|
where yclippership = :po_number
|
||||||
|
""",
|
||||||
|
po_number=po_number,
|
||||||
|
).first()
|
||||||
|
if result['orders'] >= 2:
|
||||||
|
return 'Customer: Multiple shipments match this PO\n'
|
||||||
|
result = data_base.query(
|
||||||
|
"""
|
||||||
|
SELECT
|
||||||
|
[bpcord] [Customer],
|
||||||
|
[ylicplate] [Shandex Order]
|
||||||
|
FROM [staging].[dbo].[shandex_shipments]
|
||||||
|
where yclippership = :po_number
|
||||||
|
""",
|
||||||
|
po_number=po_number,
|
||||||
|
).first()
|
||||||
|
return f"Customer: {result['Customer']}\nShandex Order: {result['Shandex Order']}\n"
|
||||||
|
|
||||||
|
|
||||||
def gtin_to_sku(gtin):
|
def gtin_to_sku(gtin):
|
||||||
|
|
Loading…
Reference in New Issue