Skip to content

Commit

Permalink
[FIX] product_pack: include product pack price
Browse files Browse the repository at this point in the history
  • Loading branch information
ALopez-Adhoc committed Dec 2, 2024
1 parent c2f1367 commit 16af869
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 30 deletions.
4 changes: 2 additions & 2 deletions product_pack/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ The options of this field are the followings:
| **Detailed per components** | Yes, with their prices | Components + Pack | Applies to the price of the pack and | Yes, configurable |
| | | | the components | |
+-----------------------------+-----------------------------+---------------------------------+-----------------------------------------+----------------------+
| **Detailed - Totalized** | Yes, with their prices at 0 | Components | Applies to the total (pack + components)| No |
| **Detailed - Totalized** | Yes, with their prices at 0 | Components + Pack | Applies to the total (pack + components)| No |
+-----------------------------+-----------------------------+---------------------------------+-----------------------------------------+----------------------+
| **Detailed - Ignored** | Yes, with their prices at 0 | Only Pack | Applies to the pack | No |
+-----------------------------+-----------------------------+---------------------------------+-----------------------------------------+----------------------+
| **No detailed** | No | Components | Applies to the total (pack + components)| No |
| **No detailed** | No | Components + Pack | Applies to the total (pack + components)| No |
+-----------------------------+-----------------------------+---------------------------------+-----------------------------------------+----------------------+

**Note:** If pricelist enabled, Odoo will display the price according to the corresponding pricelist. In the case of a pricelist with discount policy "Show public price & discount to the customer" keep in mind that the "Non Detailed" and "Detailed - Totalized in main product" packs do not display the discount.
Expand Down
15 changes: 3 additions & 12 deletions product_pack/models/product_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,9 @@ def _get_product_price(self, product, quantity, uom=None, date=False, **kwargs):
"""
self and self.ensure_one()
if product._is_pack_to_be_handled():
# NOTE: This exception is to avoid adding the list price of the packs
# "totalized" and "non detailed". Should be removed to solve the issue #169.
if (
product.pack_type == "non_detailed"
or product.pack_component_price == "totalized"
):
pack_price = 0
else:
pack_price = self._compute_price_rule(
product, quantity, uom=uom, date=date, **kwargs
)[product.id][0]

pack_price = self._compute_price_rule(
product, quantity, uom=uom, date=date, **kwargs
)[product.id][0]
for line in product.sudo().pack_line_ids:
pack_price += line._get_pack_line_price(
self, quantity, uom=uom, date=date, **kwargs
Expand Down
12 changes: 1 addition & 11 deletions product_pack/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,7 @@ def _compute_product_lst_price(self):
if uom:
uom = self.env["uom.uom"].browse([uom])

Check warning on line 42 in product_pack/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

product_pack/models/product_product.py#L42

Added line #L42 was not covered by tests
for product in packs:
# NOTE: This exception is to avoid adding the list price of the packs
# "totalized" and "non detailed". Should be removed to solve the issue #169.
if (
product.pack_type == "non_detailed"
or product.pack_component_price == "totalized"
):
list_price = 0
else:
list_price = product._price_compute("list_price", uom=uom).get(
product.id
)
list_price = product._price_compute("list_price", uom=uom).get(product.id)
list_price += sum(
product.pack_line_ids._pack_line_price_compute(
"list_price", uom=uom
Expand Down
4 changes: 2 additions & 2 deletions product_pack/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ The options of this field are the followings:
| **Detailed per components** | Yes, with their prices | Components + Pack | Applies to the price of the pack and | Yes, configurable |
| | | | the components | |
+-----------------------------+-----------------------------+---------------------------------+-----------------------------------------+----------------------+
| **Detailed - Totalized** | Yes, with their prices at 0 | Components | Applies to the total (pack + components)| No |
| **Detailed - Totalized** | Yes, with their prices at 0 | Components + Pack | Applies to the total (pack + components)| No |
+-----------------------------+-----------------------------+---------------------------------+-----------------------------------------+----------------------+
| **Detailed - Ignored** | Yes, with their prices at 0 | Only Pack | Applies to the pack | No |
+-----------------------------+-----------------------------+---------------------------------+-----------------------------------------+----------------------+
| **No detailed** | No | Components | Applies to the total (pack + components)| No |
| **No detailed** | No | Components + Pack | Applies to the total (pack + components)| No |
+-----------------------------+-----------------------------+---------------------------------+-----------------------------------------+----------------------+

**Note:** If pricelist enabled, Odoo will display the price according to the corresponding pricelist. In the case of a pricelist with discount policy "Show public price & discount to the customer" keep in mind that the "Non Detailed" and "Detailed - Totalized in main product" packs do not display the discount.
6 changes: 3 additions & 3 deletions product_pack/tests/test_product_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_pack_price_with_pricelist_context(self):
price = pack.with_context(
pricelist=self.discount_pricelist.id
)._get_contextual_price()
self.assertEqual(price, 2574.0)
self.assertEqual(price, 2601.675)

# Pack Ignored
pack = self.env.ref("product_pack.product_pack_cpu_detailed_ignored")
Expand All @@ -147,4 +147,4 @@ def test_pack_price_with_pricelist_context(self):
price = pack.with_context(
pricelist=self.discount_pricelist.id
)._get_contextual_price()
self.assertEqual(price, 2574.0)
self.assertEqual(price, 2601.675)

0 comments on commit 16af869

Please sign in to comment.