From 3918882d041e4ee940ebb47a6ca4409c0b80623a Mon Sep 17 00:00:00 2001 From: bleeson Date: Mon, 17 Jun 2024 10:26:44 -0700 Subject: [PATCH] Allow multiple lines of the same SKU at different prices. --- source_ecommerce_make_order.py | 19 +++++++++++-------- source_ecommerce_make_shipment.py | 15 +++++++++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/source_ecommerce_make_order.py b/source_ecommerce_make_order.py index 32c25f3..4db3bfb 100644 --- a/source_ecommerce_make_order.py +++ b/source_ecommerce_make_order.py @@ -44,7 +44,7 @@ def main(): else: process_files(file) shutil.move(file, SHIPMENTS_DIRECTORY / file.name) - #archives are in the shipping folder + # archives are in the shipping folder combine_zshpords() def sftp_server() -> paramiko.SFTPClient: @@ -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 @@ -181,7 +182,7 @@ def get_details_from_shopify(order): ,[ecommerce_shipped_orders].[shipping_lines__price] ,[ecommerce_shipped_order_lines].[sku] ,[ecommerce_shipped_order_lines].[quantity] - ,[ecommerce_shipped_order_lines].[price] + ,[ecommerce_shipped_order_lines].[price] from [staging].[dbo].[ecommerce_shipped_orders] left join [staging].[dbo].[ecommerce_shipped_order_lines] on [ecommerce_shipped_orders].[id] = [ecommerce_shipped_order_lines].[id] @@ -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): diff --git a/source_ecommerce_make_shipment.py b/source_ecommerce_make_shipment.py index bf49970..5065e52 100644 --- a/source_ecommerce_make_shipment.py +++ b/source_ecommerce_make_shipment.py @@ -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)