Changes to process to allow for order swith multiple SKUs. Shipping intentionally crashes on this type of order and must be resaolved manually.
parent
3918882d04
commit
28f6f627f5
|
@ -18,6 +18,7 @@ import re
|
||||||
import shutil
|
import shutil
|
||||||
import typing
|
import typing
|
||||||
import paramiko
|
import paramiko
|
||||||
|
import decimal
|
||||||
|
|
||||||
import records # type: ignore
|
import records # type: ignore
|
||||||
|
|
||||||
|
@ -43,9 +44,9 @@ def main():
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
process_files(file)
|
process_files(file)
|
||||||
shutil.move(file, SHIPMENTS_DIRECTORY / file.name)
|
#shutil.move(file, SHIPMENTS_DIRECTORY / file.name)
|
||||||
# archives are in the shipping folder
|
# archives are in the shipping folder
|
||||||
combine_zshpords()
|
#combine_zshpords()
|
||||||
|
|
||||||
def sftp_server() -> paramiko.SFTPClient:
|
def sftp_server() -> paramiko.SFTPClient:
|
||||||
with paramiko.SSHClient() as ssh_client:
|
with paramiko.SSHClient() as ssh_client:
|
||||||
|
@ -119,7 +120,16 @@ def process_files(file): #I am assuming I am getting a sorted csv file by order
|
||||||
sales_order.output(import_file)
|
sales_order.output(import_file)
|
||||||
sales_order = SalesOrder()
|
sales_order = SalesOrder()
|
||||||
previous_order = current_order
|
previous_order = current_order
|
||||||
shopify_order_info = get_details_from_shopify(current_order)
|
shopify_order_info = get_details_from_shopify(current_order)
|
||||||
|
shopify_line_dict = create_shopify_dict(shopify_order_info)
|
||||||
|
for entry in shopify_line_dict:
|
||||||
|
sales_order.append(
|
||||||
|
SalesOrderDetail(
|
||||||
|
itmref=shopify_line_dict[entry]['sku'],
|
||||||
|
qty=int(shopify_line_dict[entry]['quantity']),
|
||||||
|
gropri=shopify_line_dict[entry]['price']
|
||||||
|
)
|
||||||
|
)
|
||||||
ship_site = row[0]
|
ship_site = row[0]
|
||||||
order_id = row[6]
|
order_id = row[6]
|
||||||
order_date = row[9]
|
order_date = row[9]
|
||||||
|
@ -131,7 +141,6 @@ def process_files(file): #I am assuming I am getting a sorted csv file by order
|
||||||
# shipzip = row[13]
|
# shipzip = row[13]
|
||||||
tracking = row[16]
|
tracking = row[16]
|
||||||
weight = row[18]
|
weight = row[18]
|
||||||
#pprint.pprint(order_id)
|
|
||||||
taxes = shopify_order_info[0]['current_total_tax']#row[22]
|
taxes = shopify_order_info[0]['current_total_tax']#row[22]
|
||||||
ship_charge = shopify_order_info[0]['shipping_lines__price']#row[21]
|
ship_charge = shopify_order_info[0]['shipping_lines__price']#row[21]
|
||||||
discount = shopify_order_info[0]['current_total_discounts']#row[24]
|
discount = shopify_order_info[0]['current_total_discounts']#row[24]
|
||||||
|
@ -145,18 +154,13 @@ def process_files(file): #I am assuming I am getting a sorted csv file by order
|
||||||
sales_order.header.invdtaamt_8 = taxes
|
sales_order.header.invdtaamt_8 = taxes
|
||||||
|
|
||||||
#gather line data
|
#gather line data
|
||||||
line_product = row[1]
|
# line_product = row[1]
|
||||||
line_qty = row[3]
|
# line_qty = int(row[3])
|
||||||
line_lot = row[4]
|
# line_lot = row[4]
|
||||||
line_price = row[20]
|
# line_price = row[20]
|
||||||
shopify_item_data = get_item_from_shopify_order(shopify_order_info, line_product, line_price)
|
# shopify_item_data = get_item_from_shopify_order(shopify_line_dict, line_product, line_qty)
|
||||||
sales_order.append(
|
|
||||||
SalesOrderDetail(
|
# shopify_line_dict = remove_item_from_shopify_order(shopify_line_dict, shopify_item_data['sku'], shopify_item_data['quantity'],shopify_item_data['price'])
|
||||||
itmref=shopify_item_data['sku'],#line_product,
|
|
||||||
qty=int(shopify_item_data['quantity']),#int(line_qty),
|
|
||||||
gropri=shopify_item_data['price']#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_{current_order}_{time_stamp}_{sales_order.header.cusordref}.dat"
|
SOH_IMPORT_DIRECTORY / f"ZSHPORD_{current_order}_{time_stamp}_{sales_order.header.cusordref}.dat"
|
||||||
|
@ -164,10 +168,44 @@ def process_files(file): #I am assuming I am getting a sorted csv file by order
|
||||||
sales_order.output(import_file)
|
sales_order.output(import_file)
|
||||||
|
|
||||||
|
|
||||||
def get_item_from_shopify_order(line_item_list, product, gropri):
|
def create_shopify_dict(shopify_record):
|
||||||
for record in line_item_list:
|
order_info = {}
|
||||||
if record['sku'] == product and str(record['price']).rstrip('0') == gropri:
|
for record in shopify_record:
|
||||||
return record
|
sku = record['sku']
|
||||||
|
qty = record['quantity']
|
||||||
|
price = record['price']
|
||||||
|
key = sku + '_' + str(price)
|
||||||
|
if key in order_info:
|
||||||
|
order_info[key]['quantity'] += qty
|
||||||
|
else:
|
||||||
|
order_info[key] = {
|
||||||
|
'sku':record['sku'],
|
||||||
|
'quantity':record['quantity'],
|
||||||
|
'price':record['price'],
|
||||||
|
}
|
||||||
|
return order_info
|
||||||
|
|
||||||
|
|
||||||
|
def remove_item_from_shopify_order(line_item_dict, product, qty, price):
|
||||||
|
#after using some or all of a line, decrement or remove it
|
||||||
|
for line in line_item_dict:
|
||||||
|
line_info = line_item_dict[line]
|
||||||
|
qty_to_remove = line_info['quantity']
|
||||||
|
if line_info['sku'] == product and line_info['quantity'] > 0 and line_info['price'] == price:
|
||||||
|
if qty_to_remove > line_info['quantity']: #more qty is required than on the line
|
||||||
|
pprint.pprint('too much to remove from 1 line')
|
||||||
|
remainder = qty_to_remove - line_info['quantity']
|
||||||
|
line_item_dict = remove_item_from_shopify_order(line_item_dict, product, remainder, price)
|
||||||
|
else:
|
||||||
|
line_info['quantity'] -= qty_to_remove
|
||||||
|
return line_item_dict
|
||||||
|
|
||||||
|
|
||||||
|
def get_item_from_shopify_order(line_item_dict, product, qty):
|
||||||
|
for line in line_item_dict:
|
||||||
|
line_info = line_item_dict[line]
|
||||||
|
if line_info == product and line_info['quantity'] > 0:
|
||||||
|
return line_info
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -240,11 +240,9 @@ class WarehouseShipmentDetail:
|
||||||
where
|
where
|
||||||
[SOP].[SOHNUM_0] = :sohnum
|
[SOP].[SOHNUM_0] = :sohnum
|
||||||
and [SOP].[ITMREF_0] = :itmref
|
and [SOP].[ITMREF_0] = :itmref
|
||||||
and [SOP].[GROPRI_0] = :gropri
|
|
||||||
""",
|
""",
|
||||||
sohnum=self.sohnum,
|
sohnum=self.sohnum,
|
||||||
itmref=self.itmref,
|
itmref=self.itmref,
|
||||||
gropri=self.gropri,
|
|
||||||
)
|
)
|
||||||
.first()
|
.first()
|
||||||
.how_many
|
.how_many
|
||||||
|
@ -260,13 +258,11 @@ class WarehouseShipmentDetail:
|
||||||
where
|
where
|
||||||
[SOP].[SOHNUM_0] = :sohnum
|
[SOP].[SOHNUM_0] = :sohnum
|
||||||
and [SOP].[ITMREF_0] = :itmref
|
and [SOP].[ITMREF_0] = :itmref
|
||||||
and [SOP].[GROPRI_0] = :gropri
|
|
||||||
order by
|
order by
|
||||||
[SOP].[SOPLIN_0]
|
[SOP].[SOPLIN_0]
|
||||||
""",
|
""",
|
||||||
sohnum=self.sohnum,
|
sohnum=self.sohnum,
|
||||||
itmref=self.itmref,
|
itmref=self.itmref,
|
||||||
gropri=self.gropri,
|
|
||||||
).first()
|
).first()
|
||||||
else:
|
else:
|
||||||
pprint.pprint(self.sohnum)
|
pprint.pprint(self.sohnum)
|
||||||
|
|
Loading…
Reference in New Issue