Added staging of picking information to 867 for returns. Added return case to 944 processing.
parent
4e55415475
commit
c14ea359aa
|
@ -398,6 +398,7 @@ def process_file(edi_filename: pathlib.Path, x3_customer_mapping):
|
||||||
warehouse_shipment.header.ylicplate = f'{po_number}'
|
warehouse_shipment.header.ylicplate = f'{po_number}'
|
||||||
if picking_number != previous_picking_number and previous_picking_number != '':
|
if picking_number != previous_picking_number and previous_picking_number != '':
|
||||||
if warehouse_shipment.header.bpdnam != 'Shandex Group':
|
if warehouse_shipment.header.bpdnam != 'Shandex Group':
|
||||||
|
warehouse_shipment.header.pick_ticket = previous_picking_number
|
||||||
warehouse_shipment.header.shidat = datetime.datetime.strptime(
|
warehouse_shipment.header.shidat = datetime.datetime.strptime(
|
||||||
shipping_date, "%Y%m%d")
|
shipping_date, "%Y%m%d")
|
||||||
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
|
@ -472,6 +473,7 @@ def process_file(edi_filename: pathlib.Path, x3_customer_mapping):
|
||||||
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
if warehouse_shipment.header.bpcord == '':
|
if warehouse_shipment.header.bpcord == '':
|
||||||
missing_customer_alert(customer_key)
|
missing_customer_alert(customer_key)
|
||||||
|
warehouse_shipment.header.pick_ticket = picking_number
|
||||||
import_shipment(warehouse_shipment)
|
import_shipment(warehouse_shipment)
|
||||||
|
|
||||||
|
|
||||||
|
@ -566,7 +568,7 @@ def import_shipment(warehouse_shipment):
|
||||||
sdhtyp=warehouse_shipment.header.sdhtyp,
|
sdhtyp=warehouse_shipment.header.sdhtyp,
|
||||||
growei=warehouse_shipment.header.growei,
|
growei=warehouse_shipment.header.growei,
|
||||||
pacnbr=warehouse_shipment.header.pacnbr,
|
pacnbr=warehouse_shipment.header.pacnbr,
|
||||||
star71=warehouse_shipment.header.star71,
|
star71=warehouse_shipment.header.pick_ticket,
|
||||||
star72=warehouse_shipment.header.star72,
|
star72=warehouse_shipment.header.star72,
|
||||||
star81=warehouse_shipment.header.star81,
|
star81=warehouse_shipment.header.star81,
|
||||||
star82=warehouse_shipment.header.star82
|
star82=warehouse_shipment.header.star82
|
||||||
|
@ -769,6 +771,7 @@ class WarehouseShipmentHeader:
|
||||||
bptnum: str = ""
|
bptnum: str = ""
|
||||||
ylicplate: str = "SHANDEX"
|
ylicplate: str = "SHANDEX"
|
||||||
yclippership: str = ""
|
yclippership: str = ""
|
||||||
|
pick_ticket: str = ""
|
||||||
invdtaamt_2: decimal.Decimal = decimal.Decimal()
|
invdtaamt_2: decimal.Decimal = decimal.Decimal()
|
||||||
invdtaamt_3: decimal.Decimal = decimal.Decimal()
|
invdtaamt_3: decimal.Decimal = decimal.Decimal()
|
||||||
invdtaamt_4: decimal.Decimal = decimal.Decimal()
|
invdtaamt_4: decimal.Decimal = decimal.Decimal()
|
||||||
|
|
|
@ -75,59 +75,35 @@ def main():
|
||||||
"""
|
"""
|
||||||
for edi_filename in X12_DIRECTORY.iterdir():
|
for edi_filename in X12_DIRECTORY.iterdir():
|
||||||
if SHANDEX_944_FILENAME_RE.match(edi_filename.name):
|
if SHANDEX_944_FILENAME_RE.match(edi_filename.name):
|
||||||
process_file(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)#TODO uncomment
|
||||||
|
|
||||||
|
|
||||||
def new_944_alert(sdhnum, pohnum, rcpdat):
|
def determine_edi_action(edi_filename: pathlib.Path):
|
||||||
msg = MIMEMultipart()
|
|
||||||
msg['Subject'] = 'New Receipt from Shandex'
|
|
||||||
msg['Precedence'] = 'bulk'
|
|
||||||
msg['From'] = 'x3report@stashtea.com'
|
|
||||||
msg['To'] = 'icortes@yamamotoyama.com,mdelacruz@yamamotoyama.com,dalmanza@yamamotoyama.com,jpena@yamamotoyama.com'
|
|
||||||
msg['CC'] = 'bleeson@stashtea.com'
|
|
||||||
emailtext = f'Delivery: {sdhnum}\nPO: {pohnum}\nDate: {rcpdat}'
|
|
||||||
msg.attach(MIMEText(emailtext, 'plain'))
|
|
||||||
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as smtp:
|
|
||||||
smtp.login(user='x3reportmk2@yamamotoyama.com', password=r'n</W<7fr"VD~\2&[pZc5')
|
|
||||||
smtp.send_message(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def validation_alert(sdhnum):
|
|
||||||
msg = MIMEMultipart()
|
|
||||||
msg['Subject'] = 'New Receipt from Shandex'
|
|
||||||
msg['Precedence'] = 'bulk'
|
|
||||||
msg['From'] = 'x3report@stashtea.com'
|
|
||||||
msg['To'] = 'icortes@yamamotoyama.com,mdelacruz@yamamotoyama.com,dalmanza@yamamotoyama.com,jpena@yamamotoyama.com'
|
|
||||||
msg['CC'] = 'bleeson@stashtea.com'
|
|
||||||
emailtext = f'A Shandex receipt for {sdhnum} could not be loaded into X3 because the shipment is not validated.'
|
|
||||||
msg.attach(MIMEText(emailtext, 'plain'))
|
|
||||||
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as smtp:
|
|
||||||
smtp.login(user='x3reportmk2@yamamotoyama.com', password=r'n</W<7fr"VD~\2&[pZc5')
|
|
||||||
smtp.send_message(msg)
|
|
||||||
|
|
||||||
def combine_zpthis():
|
|
||||||
"""
|
"""
|
||||||
Collect all ZPTHI imports into a single file for easy import.
|
944s from Shandex are either:
|
||||||
|
-Intersite transfer receipt
|
||||||
|
-Comanufacturer PO receipt
|
||||||
|
-Customer return
|
||||||
"""
|
"""
|
||||||
archive_directory = IMPORTS_DIRECTORY / "archive"
|
transaction = ''
|
||||||
archive_directory.mkdir(exist_ok=True)
|
for fields in tokens_from_edi_file(edi_filename):
|
||||||
with (IMPORTS_DIRECTORY / "ZPTHI.dat").open(
|
if fields[0] == "W17":
|
||||||
"w", encoding="utf-8", newline="\n"
|
transaction = fields[4]
|
||||||
) as combined_import_file:
|
break
|
||||||
for individual_import_filename in IMPORTS_DIRECTORY.glob(
|
pprint.pprint(transaction)
|
||||||
"ZPTHI_*.dat"
|
if transaction:
|
||||||
):
|
if transaction.startswith('SHP'):
|
||||||
with individual_import_filename.open(
|
process_intersite_receipt(edi_filename)
|
||||||
"r", encoding="utf-8", newline="\n"
|
elif transaction.startswith('RA'):
|
||||||
) as individual_import_file:
|
process_return(edi_filename)
|
||||||
for line in individual_import_file:
|
# elif transaction.startswith('RA*'):#TODO how are coman pos received
|
||||||
combined_import_file.write(line)
|
# pprint.pprint('return')
|
||||||
shutil.move(
|
else:
|
||||||
individual_import_filename,
|
raise Exception('Unknown transaction type')
|
||||||
archive_directory / individual_import_filename.name,
|
else:
|
||||||
)
|
raise Exception('Unknown transaction type')
|
||||||
|
|
||||||
|
|
||||||
def tokens_from_edi_file(
|
def tokens_from_edi_file(
|
||||||
|
@ -184,7 +160,51 @@ def check_shipment_status(delivery):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def process_file(edi_filename: pathlib.Path):
|
|
||||||
|
def process_return(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
|
||||||
|
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']
|
||||||
|
for fields in tokens_from_edi_file(edi_filename):
|
||||||
|
if fields[0] == "W17":
|
||||||
|
#_, _, rcpdat, _, sohnum, sdhnum = fields[:6]
|
||||||
|
#W17*F*20250327*143365*RA9000022
|
||||||
|
_, _, rcpdat, _, sohnum = fields[:5]
|
||||||
|
rcpdat = datetime.datetime.strptime(rcpdat, "%Y%m%d").date() # 20230922
|
||||||
|
if fields[0] == "W07":
|
||||||
|
# W07*33*CA**PN*10077652772170*LT*06022027A***UK*10077652772170
|
||||||
|
_, qty_str, uom, _, _, gtin, _, lot = fields[:8]
|
||||||
|
x3_sku = gtin_to_sku(gtin)['ITMREF_0']
|
||||||
|
uom = fix_uom(uom)
|
||||||
|
line_data.append(f'{x3_sku} {qty_str} {uom} {lot}')
|
||||||
|
simple_email_notification.email_noticication(['bleeson@stashtea.com'],
|
||||||
|
'Shandex Return',line_data)
|
||||||
|
|
||||||
|
|
||||||
|
def gtin_to_sku(gtin):
|
||||||
|
with yamamotoyama.get_connection() as data_base:
|
||||||
|
result = data_base.query(
|
||||||
|
"""
|
||||||
|
select
|
||||||
|
ITMREF_0
|
||||||
|
from PROD.ITMMASTER
|
||||||
|
where replace(ZCASEUPC_0, ' ', '') = :gtin
|
||||||
|
""",
|
||||||
|
gtin=gtin,
|
||||||
|
).first()
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def process_intersite_receipt(edi_filename: pathlib.Path):
|
||||||
"""
|
"""
|
||||||
Convert a specific EDI file into an import file.
|
Convert a specific EDI file into an import file.
|
||||||
"""
|
"""
|
||||||
|
@ -232,12 +252,7 @@ def process_file(edi_filename: pathlib.Path):
|
||||||
subdetail,
|
subdetail,
|
||||||
)
|
)
|
||||||
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
#new_944_alert(sdhnum, pohnum, warehouse_receipt.header.rcpdat)#TODO is this needed?
|
#import_receipt(warehouse_receipt)#TODO uncomment
|
||||||
# with yamamotoyama.x3_imports.open_import_file(
|
|
||||||
# IMPORTS_DIRECTORY / f"ZPTHI_{warehouse_receipt.sdhnum}_{time_stamp}.dat"
|
|
||||||
# ) as import_file:
|
|
||||||
# warehouse_receipt.output(import_file)
|
|
||||||
import_receipt(warehouse_receipt)
|
|
||||||
|
|
||||||
|
|
||||||
def import_receipt(warehouse_receipt):
|
def import_receipt(warehouse_receipt):
|
||||||
|
@ -658,6 +673,33 @@ class Receipt:
|
||||||
#pprint.pprint(record_list)
|
#pprint.pprint(record_list)
|
||||||
output(record_list)
|
output(record_list)
|
||||||
|
|
||||||
|
def build_text_output(self, import_file: typing.TextIO):
|
||||||
|
"""
|
||||||
|
Output entire order to a string.
|
||||||
|
"""
|
||||||
|
output = ''
|
||||||
|
output.append(self.header.convert_to_strings())
|
||||||
|
output.append('\n')
|
||||||
|
for detail in self.details:
|
||||||
|
output.append(detail.convert_to_strings())
|
||||||
|
output.append('\n')
|
||||||
|
for subdetail in detail.subdetails:
|
||||||
|
shipment = detail.sdhnum
|
||||||
|
item = detail.itmref
|
||||||
|
for record in subdetail.stojous(shipment, item):
|
||||||
|
record_list = [
|
||||||
|
record['Code'],
|
||||||
|
record['STA_0'],
|
||||||
|
record['PCU_0'],
|
||||||
|
record['QTYPCU_0'],
|
||||||
|
record['LOT_0'],
|
||||||
|
record['BPSLOT_0'],
|
||||||
|
record['SERNUM_0']
|
||||||
|
]
|
||||||
|
#pprint.pprint(record_list)
|
||||||
|
output.append(record_list)
|
||||||
|
output.append('\n')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue