Allow for multiple lots and orders in a single file
parent
3005823cc4
commit
7ca7b0edb8
|
@ -44,9 +44,8 @@ def main():
|
|||
else:
|
||||
process_files(file)
|
||||
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()
|
||||
#TODO determine X3 processing schedule
|
||||
|
||||
def sftp_server() -> paramiko.SFTPClient:
|
||||
with paramiko.SSHClient() as ssh_client:
|
||||
|
@ -85,7 +84,7 @@ def combine_zshpords():
|
|||
archive_directory = SOH_IMPORT_DIRECTORY / "archive"
|
||||
archive_directory.mkdir(exist_ok=True)
|
||||
with (SOH_IMPORT_DIRECTORY / "ZSHPORD.dat").open(
|
||||
"a", encoding="utf-8", newline="\n"
|
||||
"w", encoding="utf-8", newline="\n"
|
||||
) as combined_import_file:
|
||||
for individual_import_filename in SOH_IMPORT_DIRECTORY.glob(
|
||||
"ZSHPORD_*.dat"
|
||||
|
@ -104,11 +103,22 @@ def process_files(file):
|
|||
with open(file) as source_file:
|
||||
csv_reader = csv.reader(source_file)
|
||||
sales_order = SalesOrder()
|
||||
previous_order = ''
|
||||
current_order = ''
|
||||
for num, row in enumerate(csv_reader):
|
||||
if num == 0:
|
||||
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_date = row[8]
|
||||
customer_name = row[9]
|
||||
|
@ -124,28 +134,28 @@ def process_files(file):
|
|||
ship_site = "?" #TODO fixme
|
||||
discount = "?" #TODO fixme
|
||||
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.bpdnam = customer_name
|
||||
sales_order.header.invdtaamt_5 = ship_charge
|
||||
sales_order.header.invdtaamt_7 = '0.33' #TODO discount
|
||||
sales_order.header.invdtaamt_8 = '0.51'#TODO taxes
|
||||
|
||||
#gather line data
|
||||
line_product = row[0]
|
||||
line_qty = row[2]
|
||||
line_lot = row[3]
|
||||
line_price = row[19]
|
||||
sales_order.append(
|
||||
SalesOrderDetail(
|
||||
itmref=line_product,
|
||||
qty=line_qty,
|
||||
gropri=line_price
|
||||
#gather line data
|
||||
line_product = row[0]
|
||||
line_qty = row[2]
|
||||
line_lot = row[3]
|
||||
line_price = row[19]
|
||||
sales_order.append(
|
||||
SalesOrderDetail(
|
||||
itmref=line_product,
|
||||
qty=int(line_qty),
|
||||
gropri=line_price
|
||||
)
|
||||
)
|
||||
)
|
||||
time_stamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
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:
|
||||
sales_order.output(import_file)
|
||||
|
||||
|
@ -360,15 +370,14 @@ class SalesOrderDetailList:
|
|||
Append
|
||||
"""
|
||||
itmref = salesorder_detail.itmref
|
||||
# if itmref in self._item_set:
|
||||
# for detail in self._details:
|
||||
# if detail == itmref:
|
||||
# detail.subdetails.append(shipment_subdetail)
|
||||
# return
|
||||
self._item_set.add(itmref)
|
||||
#salesorder_detail.fill()
|
||||
#salesorder_detail.append(shipment_subdetail)
|
||||
self._details.append(salesorder_detail)
|
||||
qty = salesorder_detail.qty
|
||||
if itmref in self._item_set:
|
||||
for detail in self._details:
|
||||
if detail.itmref == itmref:
|
||||
detail.qty += qty
|
||||
else:
|
||||
self._item_set.add(itmref)
|
||||
self._details.append(salesorder_detail)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self._details)
|
||||
|
|
|
@ -25,10 +25,9 @@ def main():
|
|||
continue
|
||||
else:
|
||||
process_files(file)
|
||||
shutil.move(file, INCOMING_DIRECTORY / "archive" / file.name)
|
||||
#shutil.move(file, INCOMING_DIRECTORY / "archive" / file.name)
|
||||
combine_zship945s()
|
||||
#TODO determine X3 processing schedule
|
||||
#TODO determine X3 processing schedule
|
||||
|
||||
|
||||
def combine_zship945s():
|
||||
"""
|
||||
|
@ -37,7 +36,7 @@ def combine_zship945s():
|
|||
archive_directory = SDH_IMPORT_DIRECTORY / "archive"
|
||||
archive_directory.mkdir(exist_ok=True)
|
||||
with (SDH_IMPORT_DIRECTORY / "ZSHIP945S.dat").open(
|
||||
"a", encoding="utf-8", newline="\n"
|
||||
"w", encoding="utf-8", newline="\n"
|
||||
) as combined_import_file:
|
||||
for individual_import_filename in SDH_IMPORT_DIRECTORY.glob(
|
||||
"ZSHIP945S_*.dat"
|
||||
|
@ -71,11 +70,24 @@ def process_files(file):
|
|||
with open(file) as source_file:
|
||||
csv_reader = csv.reader(source_file)
|
||||
warehouse_shipment = WarehouseShipment()
|
||||
previous_order = ''
|
||||
previous_item = ''
|
||||
for num, row in enumerate(csv_reader):
|
||||
if num == 0:
|
||||
continue #skip header lines
|
||||
if num == 1: #gather header information
|
||||
if num >= 1: #gather header information
|
||||
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]
|
||||
customer_name = row[9]
|
||||
# shipadd1 = row[9] # address information is not stored in X3
|
||||
|
@ -91,27 +103,36 @@ def process_files(file):
|
|||
discount = "?" #TODO fixme
|
||||
warehouse_shipment.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.growei = weight
|
||||
#gather line data
|
||||
#TODO how are multiple lots processed?
|
||||
line_product = row[0]
|
||||
line_qty = row[2]
|
||||
line_lot = row[3]
|
||||
line_price = row[19]
|
||||
subdetail = WarehouseShipmentSubDetail(
|
||||
qtypcu=-1 * int(line_qty),
|
||||
lot=line_lot,
|
||||
)
|
||||
warehouse_shipment.append(
|
||||
WarehouseShipmentDetail(
|
||||
sohnum=sohnum,
|
||||
itmref=line_product,
|
||||
qty=int(line_qty),
|
||||
),
|
||||
subdetail,
|
||||
)
|
||||
#gather line data
|
||||
#TODO how are multiple lots processed?
|
||||
line_product = row[0]
|
||||
line_qty = row[2]
|
||||
line_lot = row[3]
|
||||
line_price = row[19]
|
||||
subdetail = WarehouseShipmentSubDetail(
|
||||
qtypcu=-1 * int(line_qty),
|
||||
lot=line_lot,
|
||||
)
|
||||
if previous_item != line_product:
|
||||
detail = WarehouseShipmentDetail(
|
||||
sohnum=sohnum,
|
||||
itmref=line_product,
|
||||
qty=int(line_qty),
|
||||
)
|
||||
# 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")
|
||||
with yamamotoyama.x3_imports.open_import_file(
|
||||
SDH_IMPORT_DIRECTORY / f"ZSHIP945S_{warehouse_shipment.sohnum}_{time_stamp}.dat"
|
||||
|
@ -170,6 +191,7 @@ class WarehouseShipmentDetail:
|
|||
"""
|
||||
Add subdetail
|
||||
"""
|
||||
|
||||
subdetail.pcu = self.sau
|
||||
self.subdetails.append(subdetail)
|
||||
|
||||
|
@ -180,6 +202,8 @@ class WarehouseShipmentDetail:
|
|||
total_cases = 0
|
||||
for subdetail in self.subdetails:
|
||||
total_cases += subdetail.qtypcu
|
||||
if subdetail.pcu == '':
|
||||
subdetail.pcu = self.sau
|
||||
return abs(total_cases)
|
||||
|
||||
def convert_to_strings(self) -> typing.List[str]:
|
||||
|
@ -253,7 +277,6 @@ class WarehouseShipmentDetail:
|
|||
).first()
|
||||
else:
|
||||
raise NotImplementedError # TODO
|
||||
|
||||
result = get()
|
||||
self.soplin = result.SOPLIN_0
|
||||
self.itmdes = result.ITMDES1_0
|
||||
|
|
Loading…
Reference in New Issue