112 lines
3.4 KiB
Python
112 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Consume a generic 997 file from 3PLs
|
|
Functional Acknowledgment
|
|
We don't do anything with these, code is holding old skeleton
|
|
"""
|
|
# pylint: disable=too-many-instance-attributes
|
|
import dataclasses
|
|
import datetime
|
|
import decimal
|
|
import functools
|
|
import pathlib
|
|
import re
|
|
import shutil
|
|
import typing
|
|
|
|
import records # type: ignore
|
|
|
|
import yamamotoyama # type: ignore
|
|
import yamamotoyama.x3_imports # type: ignore
|
|
|
|
THIS_DIRECTORY = pathlib.Path(__file__).parent
|
|
X12_DIRECTORY = THIS_DIRECTORY / "incoming"
|
|
|
|
SHANDEX_997_FILENAME_RE = re.compile(
|
|
r"\A 997_YAMAMOTOYAMA_ .* [.]edi \Z", re.X | re.M | re.S
|
|
)
|
|
|
|
|
|
def main():
|
|
"""
|
|
Do it!
|
|
"""
|
|
for edi_filename in X12_DIRECTORY.iterdir():
|
|
if SHANDEX_997_FILENAME_RE.match(edi_filename.name):
|
|
#process_file(edi_filename)
|
|
shutil.move(edi_filename, X12_DIRECTORY / "archive" / edi_filename.name)
|
|
|
|
|
|
def tokens_from_edi_file(
|
|
edi_filename: pathlib.Path,
|
|
) -> typing.Iterator[typing.List[str]]:
|
|
"""
|
|
Read tokens from EDI file
|
|
"""
|
|
with edi_filename.open(encoding="utf-8", newline="") as edi_file:
|
|
for record in edi_file.read().split("~"):
|
|
fields = record.split("*")
|
|
if fields[0] in {
|
|
"ISA",
|
|
"GS",
|
|
"ST",
|
|
"N1",
|
|
"N2",
|
|
"N3",
|
|
"N4",
|
|
"G62",
|
|
"W27",
|
|
"W10",
|
|
"LX",
|
|
"MAN",
|
|
}:
|
|
continue
|
|
yield fields
|
|
|
|
|
|
def process_file(edi_filename: pathlib.Path):
|
|
"""
|
|
997 is a functional acknowledgment, we don't need to do anything with it in X3
|
|
Do we need to send it somewhere for reporting purposes?
|
|
"""
|
|
# warehouse_receipt = Receipt()
|
|
# warehouse_receipt.header.ylicplate = '' #if we don't find a tracking number, submit a blank
|
|
# for fields in tokens_from_edi_file(edi_filename):
|
|
# if fields[0] == "W06":
|
|
# _, _, sohnum, shidat_str = fields[:4]
|
|
# warehouse_receipt.sohnum = sohnum
|
|
# warehouse_receipt.header.shidat = datetime.datetime.strptime(
|
|
# shidat_str, "%Y%m%d"
|
|
# ).date() # 20230922
|
|
# if fields[0] == "N9" and fields[1] == "2I" and len(fields) > 2 and tracking_number_not_found:
|
|
# warehouse_receipt.header.ylicplate = fields[2]
|
|
# tracking_number_not_found = False
|
|
# if fields[0] == "W12":
|
|
# W12*CC*32*32*0*CA**VN*08279*01112025C~
|
|
# _, _, qty_str, det_qty, _, _, _, _, itmref, lot = fields[:10]
|
|
# subdetail = ReceiptSubDetail(
|
|
# qtypcu=-1 * int(det_qty),
|
|
# lot=lot,
|
|
# )
|
|
# warehouse_receipt.append(
|
|
# ReceiptDetail(
|
|
# sohnum=warehouse_receipt.sohnum,
|
|
# itmref=itmref,
|
|
# qty=int(qty_str),
|
|
# ),
|
|
# subdetail,
|
|
# )
|
|
# if fields[0] == "W03":
|
|
# _, _, weight, _ = fields
|
|
# warehouse_receipt.header.growei = weight
|
|
# time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
# with yamamotoyama.x3_imports.open_import_file(
|
|
# IMPORTS_DIRECTORY / f"ZSHIP945S_{warehouse_receipt.sohnum}_{time_stamp}.dat"
|
|
# ) as import_file:
|
|
# warehouse_receipt.output(import_file)
|
|
return
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|