Skip to content

Commit

Permalink
[FIX] product_pack: include pack price in totalized
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-zanotti committed Feb 1, 2024
1 parent 6589bc9 commit e091a24
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
6 changes: 3 additions & 3 deletions product_pack/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ 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?
for product in packs.with_context(prefetch_fields=False):
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")
Expand Down
22 changes: 14 additions & 8 deletions sale_product_pack/tests/test_sale_product_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
Expand All @@ -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
Expand Down

0 comments on commit e091a24

Please sign in to comment.