Allow for multiple lots and orders in a single file

master
bleeson 2024-03-08 08:40:08 -08:00
parent 3005823cc4
commit 7ca7b0edb8
2 changed files with 84 additions and 52 deletions

View File

@ -44,9 +44,8 @@ def main():
else: else:
process_files(file) process_files(file)
shutil.move(file, SHIPMENTS_DIRECTORY / file.name) shutil.move(file, SHIPMENTS_DIRECTORY / file.name)
#shutil.move(file, INCOMING_DIRECTORY / "archive" / file.name)#archives go in the shipping folder #archives are in the shipping folder
combine_zshpords() combine_zshpords()
#TODO determine X3 processing schedule
def sftp_server() -> paramiko.SFTPClient: def sftp_server() -> paramiko.SFTPClient:
with paramiko.SSHClient() as ssh_client: with paramiko.SSHClient() as ssh_client:
@ -85,7 +84,7 @@ def combine_zshpords():
archive_directory = SOH_IMPORT_DIRECTORY / "archive" archive_directory = SOH_IMPORT_DIRECTORY / "archive"
archive_directory.mkdir(exist_ok=True) archive_directory.mkdir(exist_ok=True)
with (SOH_IMPORT_DIRECTORY / "ZSHPORD.dat").open( with (SOH_IMPORT_DIRECTORY / "ZSHPORD.dat").open(
"a", encoding="utf-8", newline="\n" "w", encoding="utf-8", newline="\n"
) as combined_import_file: ) as combined_import_file:
for individual_import_filename in SOH_IMPORT_DIRECTORY.glob( for individual_import_filename in SOH_IMPORT_DIRECTORY.glob(
"ZSHPORD_*.dat" "ZSHPORD_*.dat"
@ -104,11 +103,22 @@ def process_files(file):
with open(file) as source_file: with open(file) as source_file:
csv_reader = csv.reader(source_file) csv_reader = csv.reader(source_file)
sales_order = SalesOrder() sales_order = SalesOrder()
previous_order = ''
current_order = ''
for num, row in enumerate(csv_reader): for num, row in enumerate(csv_reader):
if num == 0: if num == 0:
continue #skip header lines continue #skip header lines
# pprint.pprint(row) if num >= 1: #gather header information
if num == 1: #gather header information current_order = row[5]
if current_order != previous_order:
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
if sales_order.header.cusordref != '':
with yamamotoyama.x3_imports.open_import_file(
SOH_IMPORT_DIRECTORY / f"ZSHPORD_{current_order}_{time_stamp}_{sales_order.header.cusordref}.dat"
) as import_file:
sales_order.output(import_file)
sales_order = SalesOrder()
previous_order = current_order
order_id = row[5] order_id = row[5]
order_date = row[8] order_date = row[8]
customer_name = row[9] customer_name = row[9]
@ -124,28 +134,28 @@ def process_files(file):
ship_site = "?" #TODO fixme ship_site = "?" #TODO fixme
discount = "?" #TODO fixme discount = "?" #TODO fixme
sales_order.header.cusordref = order_id sales_order.header.cusordref = order_id
sales_order.header.orddat = datetime.datetime.strptime(order_date,'%m/%d/%Y').strftime('%Y%m%d') #TODO strftim this sales_order.header.orddat = datetime.datetime.strptime(order_date,'%m/%d/%y %I:%M %p').strftime('%Y%m%d') #TODO strftim this
sales_order.header.stofcy = ship_site sales_order.header.stofcy = ship_site
sales_order.header.bpdnam = customer_name sales_order.header.bpdnam = customer_name
sales_order.header.invdtaamt_5 = ship_charge sales_order.header.invdtaamt_5 = ship_charge
sales_order.header.invdtaamt_7 = '0.33' #TODO discount sales_order.header.invdtaamt_7 = '0.33' #TODO discount
sales_order.header.invdtaamt_8 = '0.51'#TODO taxes sales_order.header.invdtaamt_8 = '0.51'#TODO taxes
#gather line data #gather line data
line_product = row[0] line_product = row[0]
line_qty = row[2] line_qty = row[2]
line_lot = row[3] line_lot = row[3]
line_price = row[19] line_price = row[19]
sales_order.append( sales_order.append(
SalesOrderDetail( SalesOrderDetail(
itmref=line_product, itmref=line_product,
qty=line_qty, qty=int(line_qty),
gropri=line_price gropri=line_price
)
) )
)
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
with yamamotoyama.x3_imports.open_import_file( with yamamotoyama.x3_imports.open_import_file(
SOH_IMPORT_DIRECTORY / f"ZSHPORD_{file.name}_{time_stamp}.dat" SOH_IMPORT_DIRECTORY / f"ZSHPORD_{current_order}_{time_stamp}_{sales_order.header.cusordref}.dat"
) as import_file: ) as import_file:
sales_order.output(import_file) sales_order.output(import_file)
@ -360,15 +370,14 @@ class SalesOrderDetailList:
Append Append
""" """
itmref = salesorder_detail.itmref itmref = salesorder_detail.itmref
# if itmref in self._item_set: qty = salesorder_detail.qty
# for detail in self._details: if itmref in self._item_set:
# if detail == itmref: for detail in self._details:
# detail.subdetails.append(shipment_subdetail) if detail.itmref == itmref:
# return detail.qty += qty
self._item_set.add(itmref) else:
#salesorder_detail.fill() self._item_set.add(itmref)
#salesorder_detail.append(shipment_subdetail) self._details.append(salesorder_detail)
self._details.append(salesorder_detail)
def __iter__(self): def __iter__(self):
return iter(self._details) return iter(self._details)

View File

@ -25,10 +25,9 @@ def main():
continue continue
else: else:
process_files(file) process_files(file)
shutil.move(file, INCOMING_DIRECTORY / "archive" / file.name) #shutil.move(file, INCOMING_DIRECTORY / "archive" / file.name)
combine_zship945s() combine_zship945s()
#TODO determine X3 processing schedule
#TODO determine X3 processing schedule
def combine_zship945s(): def combine_zship945s():
""" """
@ -37,7 +36,7 @@ def combine_zship945s():
archive_directory = SDH_IMPORT_DIRECTORY / "archive" archive_directory = SDH_IMPORT_DIRECTORY / "archive"
archive_directory.mkdir(exist_ok=True) archive_directory.mkdir(exist_ok=True)
with (SDH_IMPORT_DIRECTORY / "ZSHIP945S.dat").open( with (SDH_IMPORT_DIRECTORY / "ZSHIP945S.dat").open(
"a", encoding="utf-8", newline="\n" "w", encoding="utf-8", newline="\n"
) as combined_import_file: ) as combined_import_file:
for individual_import_filename in SDH_IMPORT_DIRECTORY.glob( for individual_import_filename in SDH_IMPORT_DIRECTORY.glob(
"ZSHIP945S_*.dat" "ZSHIP945S_*.dat"
@ -71,11 +70,24 @@ def process_files(file):
with open(file) as source_file: with open(file) as source_file:
csv_reader = csv.reader(source_file) csv_reader = csv.reader(source_file)
warehouse_shipment = WarehouseShipment() warehouse_shipment = WarehouseShipment()
previous_order = ''
previous_item = ''
for num, row in enumerate(csv_reader): for num, row in enumerate(csv_reader):
if num == 0: if num == 0:
continue #skip header lines continue #skip header lines
if num == 1: #gather header information if num >= 1: #gather header information
sohnum = find_so_from_po(row[5]) sohnum = find_so_from_po(row[5])
if num == 1:
previous_order = sohnum
if previous_order != sohnum:
if warehouse_shipment.sohnum != '':
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
with yamamotoyama.x3_imports.open_import_file(
SDH_IMPORT_DIRECTORY / f"ZSHIP945S_{warehouse_shipment.sohnum}_{time_stamp}.dat"
) as import_file:
warehouse_shipment.output(import_file)
warehouse_shipment = WarehouseShipment()
previous_order = sohnum
order_date = row[8] order_date = row[8]
customer_name = row[9] customer_name = row[9]
# shipadd1 = row[9] # address information is not stored in X3 # shipadd1 = row[9] # address information is not stored in X3
@ -91,27 +103,36 @@ def process_files(file):
discount = "?" #TODO fixme discount = "?" #TODO fixme
warehouse_shipment.sohnum = sohnum warehouse_shipment.sohnum = sohnum
#warehouse_shipment.header.sohnum = sohnum #warehouse_shipment.header.sohnum = sohnum
warehouse_shipment.header.shidat = datetime.datetime.strptime(order_date,'%m/%d/%Y') warehouse_shipment.header.shidat = datetime.datetime.strptime(order_date,'%m/%d/%y %I:%M %p')
warehouse_shipment.header.ylicplate = tracking warehouse_shipment.header.ylicplate = tracking
warehouse_shipment.header.growei = weight warehouse_shipment.header.growei = weight
#gather line data #gather line data
#TODO how are multiple lots processed? #TODO how are multiple lots processed?
line_product = row[0] line_product = row[0]
line_qty = row[2] line_qty = row[2]
line_lot = row[3] line_lot = row[3]
line_price = row[19] line_price = row[19]
subdetail = WarehouseShipmentSubDetail( subdetail = WarehouseShipmentSubDetail(
qtypcu=-1 * int(line_qty), qtypcu=-1 * int(line_qty),
lot=line_lot, lot=line_lot,
) )
warehouse_shipment.append( if previous_item != line_product:
WarehouseShipmentDetail( detail = WarehouseShipmentDetail(
sohnum=sohnum, sohnum=sohnum,
itmref=line_product, itmref=line_product,
qty=int(line_qty), qty=int(line_qty),
), )
subdetail, # pprint.pprint(detail)
) # pprint.pprint(subdetail)
warehouse_shipment.append(
detail,
subdetail,
)
else:
warehouse_shipment.append(
detail,
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")
with yamamotoyama.x3_imports.open_import_file( with yamamotoyama.x3_imports.open_import_file(
SDH_IMPORT_DIRECTORY / f"ZSHIP945S_{warehouse_shipment.sohnum}_{time_stamp}.dat" SDH_IMPORT_DIRECTORY / f"ZSHIP945S_{warehouse_shipment.sohnum}_{time_stamp}.dat"
@ -170,6 +191,7 @@ class WarehouseShipmentDetail:
""" """
Add subdetail Add subdetail
""" """
subdetail.pcu = self.sau subdetail.pcu = self.sau
self.subdetails.append(subdetail) self.subdetails.append(subdetail)
@ -180,6 +202,8 @@ class WarehouseShipmentDetail:
total_cases = 0 total_cases = 0
for subdetail in self.subdetails: for subdetail in self.subdetails:
total_cases += subdetail.qtypcu total_cases += subdetail.qtypcu
if subdetail.pcu == '':
subdetail.pcu = self.sau
return abs(total_cases) return abs(total_cases)
def convert_to_strings(self) -> typing.List[str]: def convert_to_strings(self) -> typing.List[str]:
@ -253,7 +277,6 @@ class WarehouseShipmentDetail:
).first() ).first()
else: else:
raise NotImplementedError # TODO raise NotImplementedError # TODO
result = get() result = get()
self.soplin = result.SOPLIN_0 self.soplin = result.SOPLIN_0
self.itmdes = result.ITMDES1_0 self.itmdes = result.ITMDES1_0