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/product_pack/tests/test_product_pack.py b/product_pack/tests/test_product_pack.py index 854117622..95cdbb643 100644 --- a/product_pack/tests/test_product_pack.py +++ b/product_pack/tests/test_product_pack.py @@ -75,7 +75,7 @@ def test_get_pack_lst_price(self): component_2.product_id.list_price = 15.0 component_3 = self.env.ref("product_pack.pack_cpu_detailed_components_4") component_3.product_id.list_price = 5.0 - self.assertEqual(50.0, pack.lst_price) + self.assertEqual(80.75, pack.lst_price) def test_pack_company(self): # Try to assign pack lines with product that do not belong to pack 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