Stage coman receipts.

master
bleeson 2025-07-23 08:41:17 -07:00
parent fe5d2968f4
commit 317292b98f
1 changed files with 77 additions and 6 deletions

View File

@ -98,14 +98,13 @@ def determine_edi_action(edi_filename: pathlib.Path):
break
if transaction:
if transaction.startswith('SHP'):
if transaction.startswith('SHP'):#intersites
process_intersite_receipt(edi_filename)
elif transaction.startswith('RA'):
elif transaction.startswith('RA'):#returns
process_return(edi_filename)
# PO is used when Shandex does not receive a 943, will they receive 943s for comans?
elif transaction.startswith('PO'):#TODO how are coman pos received
simple_email_notification.email_noticication(['bleeson@stashtea.com'],
'Unknown Shandex 944',[transaction])
elif transaction.startswith('PO'):#coman receipts
process_coman_receipt(edi_filename)
#simple_email_notification.email_noticication(['bleeson@stashtea.com'],'Unknown Shandex 944',[transaction])
else:
raise Exception('Unknown transaction type')
else:
@ -261,6 +260,77 @@ def process_intersite_receipt(edi_filename: pathlib.Path):
import_receipt(warehouse_receipt)
def process_coman_receipt(edi_filename: pathlib.Path):
"""
Convert a specific EDI file into an import file.
"""
def fix_uom(uom):
x3_uom = ''
if uom == 'CA':
x3_uom = 'CS'
else:
x3_uom = uom
return x3_uom
warehouse_receipt = Receipt()
shandex_pohnum = ''
for fields in tokens_from_edi_file(edi_filename):
if fields[0] == "W17":
_, _, rcpdat, _, pohnum = fields[:5]
warehouse_receipt.sdhnum = get_coman_shipment(pohnum)
validated = check_shipment_status(warehouse_receipt.sdhnum)
warehouse_receipt.header.rcpdat = datetime.datetime.strptime(
rcpdat, "%Y%m%d"
).date() # 20230922
if fields[0] == "N9" and fields[1] == "PO":
shandex_pohnum = fields[2]
if fields[0] == "W07":
# W07*2025*CA**PN*10077652321019*LT*18JUN2027SE***UK*10077652321019
# N9*LI*1
_, qty_str, uom, _, _, gtin, _, lot = fields[:8]
itmref = gtin_to_sku(gtin)['ITMREF_0']
subdetail = ReceiptSubDetail(
pcu=fix_uom(uom),
qtypcu=int(qty_str),
lot=lot
)
if fields[0] == 'N9' and fields[1] == 'LI':
# N9*LI*1000
#line = fields[2] #This line isn't the line number from X3, it needs to be looked up
line = find_shipment_line(warehouse_receipt.sdhnum, itmref)
warehouse_receipt.append(
ReceiptDetail(
sdhnum=warehouse_receipt.sdhnum,
poplin=int(line),
itmref=itmref,
uom=fix_uom(uom),
qtyuom=int(qty_str)
),
subdetail,
)
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
import_receipt(warehouse_receipt)
def get_coman_shipment(pohnum):
with yamamotoyama.get_connection() as data_base:
result = data_base.query(
"""
select
[SDH].[SDHNUM_0]
from [PROD].[PORDER] [POH]
join [PROD].[SORDER] [SOH]
on [SOH].[CUSORDREF_0] = [POH].[POHNUM_0]
join [PROD].[SDELIVERY] [SDH]
on [SDH].[SOHNUM_0] = [SOH].[SOHNUM_0]
where
[POH].[POHNUM_0] = :order
""",
order=pohnum,
).first()
return result['SDHNUM_0']
def import_receipt(warehouse_receipt):
"""send the shipment information to the shandex staging database"""
with yamamotoyama.get_connection() as data_base:
@ -640,6 +710,7 @@ class Receipt:
shipment=self.sdhnum,
).first()
def _fill_info_from_shipment(self):
"""
When we learn the SOHNUM, we can copy information from the sales order.