Change to tracking number format. Added "dashboard" information.

master
bleeson 2024-03-14 08:20:47 -07:00
parent 726e17c295
commit 4ad4ad79a5
2 changed files with 70 additions and 2 deletions

View File

@ -40,7 +40,7 @@ def main():
if SOURCE_867_FILENAME_RE.match(edi_filename.name):
process_file(edi_filename)
#TODO respond with 997?
#shutil.move(edi_filename, X12_DIRECTORY / "archive" / edi_filename.name)#TODO uncomment
#shutil.move(edi_filename, THIS_DIRECTORY / "processed_867s" / edi_filename.name)#TODO uncomment
combine_zship867s()
@ -114,7 +114,7 @@ def process_file(edi_filename: pathlib.Path):
for fields in tokens_from_edi_file(edi_filename):
if fields[0] == "GS":
control_number = fields[5]
warehouse_shipment.header.ylicplate = f'SHANDEX-{control_number}'
warehouse_shipment.header.ylicplate = f'{control_number}'
if fields[0] == "DTM":
date_field = fields[2]
warehouse_shipment.header.shidat = datetime.datetime.strptime(

View File

@ -0,0 +1,68 @@
#!/usr/bin/env python3
"""
Update X3 with information from middleware
To reprocess a file, move it to the correct folder on the FTP
"""
import shutil
import yamamotoyama
import pathlib
THIS_DIRECTORY = pathlib.Path(__file__).parent
RECEIVED_867_DIRECTORY = THIS_DIRECTORY / "processed_867s"
ARCHIVE = RECEIVED_867_DIRECTORY / "archive"
INSERT_867s = """\
execute [PROD].[insert_shandex_867_data]
:ctrlnum,
:credat;
"""
def main():
"""
Do it!
"""
process_received_867s()
remove_completed_867s()
def remove_completed_867s():
"""
Clean up all of the files received from the FTP
"""
for file in RECEIVED_867_DIRECTORY.iterdir():
if file.name.endswith('.edi'):
shutil.move(file,ARCHIVE / file.name)
def import_received_867s(data):
with yamamotoyama.get_connection() as data_base:
with data_base.transaction():
data_base.bulk_query(INSERT_867s, data)
def process_received_867s():
#pull out the control number on the GS line
for file in RECEIVED_867_DIRECTORY.iterdir():
control_number = ''
transaction_date = ''
if file.name.endswith('.edi'):
with file.open(encoding="utf-8", newline="") as edi_file:
for record in edi_file.read().split("~"):
fields = record.split("*")
if fields[0] == 'GS':
control_number = fields[6]
if fields[0] == 'BPT':
transaction_date = fields[3]
data = {
"ctrlnum":control_number,
"credat":transaction_date
}
import_received_867s(data)
if __name__ == "__main__":
main()