From e091a24e262cdecc1bc8cbe65abf0fc877f450c7 Mon Sep 17 00:00:00 2001 From: Bruno Zanotti Date: Thu, 1 Feb 2024 13:01:36 -0300 Subject: [PATCH] [FIX] product_pack: include pack price in totalized --- product_pack/models/product_product.py | 6 ++--- .../tests/test_sale_product_pack.py | 22 ++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/product_pack/models/product_product.py b/product_pack/models/product_product.py index b040a4314..a15f2f027 100644 --- a/product_pack/models/product_product.py +++ b/product_pack/models/product_product.py @@ -33,8 +33,8 @@ def split_pack_products(self): def price_compute( self, price_type, uom=False, currency=False, company=False, date=False ): - packs, no_packs = self.split_pack_products() - prices = super(ProductProduct, no_packs).price_compute( + packs, _ = self.split_pack_products() + prices = super(ProductProduct, self).price_compute( price_type, uom, currency, company, date ) # TODO:@bruno-zanotti prefetch_fields=False still necessary? @@ -42,7 +42,7 @@ def price_compute( pack_line_prices = product.sudo().pack_line_ids._pack_line_price_compute( price_type, uom, currency, company, date ) - prices[product.id] = sum(pack_line_prices.values()) + prices[product.id] += sum(pack_line_prices.values()) return prices @api.depends("list_price", "price_extra") diff --git a/sale_product_pack/tests/test_sale_product_pack.py b/sale_product_pack/tests/test_sale_product_pack.py index 390f8dfd1..344344a6e 100644 --- a/sale_product_pack/tests/test_sale_product_pack.py +++ b/sale_product_pack/tests/test_sale_product_pack.py @@ -157,14 +157,17 @@ def test_create_totalized_price_order_line(self): self.assertAlmostEqual( (self.sale_order.order_line - line).mapped("price_subtotal"), [0, 0, 0] ) - # Pack price is equal to the sum of component prices - self.assertAlmostEqual(line.price_subtotal, 2662.5) - self.assertAlmostEqual(self._get_component_prices_sum(product_tp), 2662.5) + # Pack price is equal to the sum of component prices + product price + self.assertAlmostEqual(line.price_subtotal, 2693.25) + pack_price = ( + self._get_component_prices_sum(product_tp) + line.product_id.list_price + ) + self.assertAlmostEqual(pack_price, 2693.25) # Update pricelist with a discount self.sale_order.pricelist_id = self.discount_pricelist self.sale_order.action_update_prices() - self.assertAlmostEqual(line.price_subtotal, 2396.25) + self.assertAlmostEqual(line.price_subtotal, 2184.3) self.assertEqual( (self.sale_order.order_line - line).mapped("price_subtotal"), [0, 0, 0] ) @@ -182,14 +185,17 @@ def test_create_non_detailed_price_order_line(self): # After create, there will be only one line, because product_type is # not a detailed one self.assertEqual(self.sale_order.order_line, line) - # Pack price is equal to the sum of component prices - self.assertAlmostEqual(line.price_subtotal, 2662.5) - self.assertAlmostEqual(self._get_component_prices_sum(product_ndtp), 2662.5) + # Pack price is equal to the sum of component prices + product price + self.assertAlmostEqual(line.price_subtotal, 2693.25) + pack_price = ( + self._get_component_prices_sum(product_ndtp) + line.product_id.list_price + ) + self.assertAlmostEqual(pack_price, 2693.25) # Update pricelist with a discount self.sale_order.pricelist_id = self.discount_pricelist self.sale_order.action_update_prices() - self.assertAlmostEqual(line.price_subtotal, 2396.25) + self.assertAlmostEqual(line.price_subtotal, 2184.3) def test_update_qty(self): # Ensure the quantities are always updated