Allow multiple lines of the same SKU at different prices.

master
bleeson 2024-06-17 10:26:44 -07:00
parent cc66d44bd1
commit 3918882d04
2 changed files with 22 additions and 12 deletions

View File

@ -131,6 +131,7 @@ def process_files(file): #I am assuming I am getting a sorted csv file by order
# shipzip = row[13]
tracking = row[16]
weight = row[18]
#pprint.pprint(order_id)
taxes = shopify_order_info[0]['current_total_tax']#row[22]
ship_charge = shopify_order_info[0]['shipping_lines__price']#row[21]
discount = shopify_order_info[0]['current_total_discounts']#row[24]
@ -148,7 +149,7 @@ def process_files(file): #I am assuming I am getting a sorted csv file by order
line_qty = row[3]
line_lot = row[4]
line_price = row[20]
shopify_item_data = get_item_from_shopify_order(shopify_order_info, line_product)
shopify_item_data = get_item_from_shopify_order(shopify_order_info, line_product, line_price)
sales_order.append(
SalesOrderDetail(
itmref=shopify_item_data['sku'],#line_product,
@ -163,9 +164,9 @@ def process_files(file): #I am assuming I am getting a sorted csv file by order
sales_order.output(import_file)
def get_item_from_shopify_order(line_item_list, product):
def get_item_from_shopify_order(line_item_list, product, gropri):
for record in line_item_list:
if record['sku'] == product:
if record['sku'] == product and str(record['price']).rstrip('0') == gropri:
return record
return None
@ -402,12 +403,14 @@ class SalesOrderDetailList:
"""
itmref = salesorder_detail.itmref
qty = salesorder_detail.qty
if itmref in self._item_set:
gropri = salesorder_detail.gropri
set_item = itmref + '_' + str(gropri)
if set_item in self._item_set:
for detail in self._details:
if detail.itmref == itmref:
if detail.itmref+'_'+str(detail.gropri) == set_item:
detail.qty += qty
else:
self._item_set.add(itmref)
self._item_set.add(set_item)
self._details.append(salesorder_detail)
def __iter__(self):

View File

@ -57,7 +57,7 @@ def find_so_from_po(cust_po):
"""
select
SOHNUM_0
from PROD.SORDER
from [PROD].SORDER
where
SOHTYP_0 = 'WEB'
and BPCORD_0 = 'STSHOPIFY'
@ -120,6 +120,7 @@ def process_files(file):
sohnum=sohnum,
itmref=line_product,
qty=int(line_qty),
gropri=line_price,
),
subdetail,
)
@ -176,6 +177,7 @@ class WarehouseShipmentDetail:
subdetails: typing.List[WarehouseShipmentSubDetail] = dataclasses.field(
default_factory=list
)
gropri: decimal.Decimal = decimal.Decimal() #to match against when multiple of the same skus are used
def append(self, subdetail: WarehouseShipmentSubDetail):
"""
@ -238,9 +240,11 @@ class WarehouseShipmentDetail:
where
[SOP].[SOHNUM_0] = :sohnum
and [SOP].[ITMREF_0] = :itmref
and [SOP].[GROPRI_0] = :gropri
""",
sohnum=self.sohnum,
itmref=self.itmref,
gropri=self.gropri,
)
.first()
.how_many
@ -256,11 +260,13 @@ class WarehouseShipmentDetail:
where
[SOP].[SOHNUM_0] = :sohnum
and [SOP].[ITMREF_0] = :itmref
and [SOP].[GROPRI_0] = :gropri
order by
[SOP].[SOPLIN_0]
""",
sohnum=self.sohnum,
itmref=self.itmref,
gropri=self.gropri,
).first()
else:
pprint.pprint(self.sohnum)
@ -464,12 +470,13 @@ class WarehouseShipmentDetailList:
Append
"""
itmref = shipment_detail.itmref
if itmref in self._item_set:
set_item = itmref+'_'+str(shipment_detail.gropri)
if set_item in self._item_set:
for detail in self._details:
if detail == itmref:
if detail.itmref+'_'+str(detail.gropri) == set_item:
detail.subdetails.append(shipment_subdetail)
return
self._item_set.add(itmref)
self._item_set.add(set_item)
shipment_detail.fill()
shipment_detail.append(shipment_subdetail)
self._details.append(shipment_detail)