Skip to content

Commit

Permalink
[FIX] product_pricelist_alternative: No alternative price in waterfal…
Browse files Browse the repository at this point in the history
…l pricelists
  • Loading branch information
santostelmo committed Oct 11, 2024
1 parent 51ab0ae commit 672827a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
4 changes: 3 additions & 1 deletion product_pricelist_alternative/models/product_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def _compute_price_rule(self, products, qty, uom=None, date=False, **kwargs):

# In some contexts we want to ignore alternative pricelists
# and return the original price
if self.env.context.get("skip_alternative_pricelist", False):
if self.env.context.get(
"skip_alternative_pricelist", False
) or self.env.context.get("based_on_other_pricelist", False):
return res

for product in products:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ def _check_pricelist_alternative_items_based_on_other_pricelist(self):
" Please change to another type of price computation."
)
)

def _compute_price(self, product, quantity, uom, date, currency=None):
if self.compute_price == "formula" and self.base == "pricelist":
self = self.with_context(based_on_other_pricelist=True)
return super()._compute_price(product, quantity, uom, date, currency)
43 changes: 39 additions & 4 deletions product_pricelist_alternative/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setUpClass(cls):

cls.alternative_pricelist_01 = cls.env["product.pricelist"].create(
{
"name": "Alternative pricelist 01",
"name": "Alternative pricelist_01",
"item_ids": [
Command.create(
{
Expand All @@ -37,7 +37,7 @@ def setUpClass(cls):
)
cls.alternative_pricelist_02 = cls.env["product.pricelist"].create(
{
"name": "Alternative pricelist 02",
"name": "Alternative alternative_pricelist_02",
"item_ids": [
Command.create(
{
Expand All @@ -51,9 +51,25 @@ def setUpClass(cls):
}
)

cls.alternative_pricelist_03 = cls.env["product.pricelist"].create(
{
"name": "Alternative alternative_pricelist_03",
"item_ids": [
Command.create(
{
"compute_price": "fixed",
"product_id": cls.usb_adapter.id,
"applied_on": "0_product_variant",
"fixed_price": 110,
}
),
],
}
)

cls.pricelist01 = cls.env["product.pricelist"].create(
{
"name": "Sale pricelist",
"name": "Sale pricelist01",
"item_ids": [
Command.create(
{
Expand Down Expand Up @@ -86,7 +102,7 @@ def setUpClass(cls):

cls.pricelist02 = cls.env["product.pricelist"].create(
{
"name": "Sale pricelist",
"name": "Sale pricelist02",
"item_ids": [
Command.create(
{
Expand All @@ -102,3 +118,22 @@ def setUpClass(cls):
],
}
)

cls.pricelist03 = cls.env["product.pricelist"].create(
{
"name": "Sale pricelist03",
"item_ids": [
Command.create(
{
"compute_price": "formula",
"base": "pricelist",
"base_pricelist_id": cls.pricelist01.id,
"applied_on": "3_global",
}
),
],
"alternative_pricelist_ids": [
(4, cls.alternative_pricelist_03.id),
],
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def test_product_price_considering_alternative_pricelist_with_lower_price(self):
result[self.usb_adapter.id][1], self.pricelist02.item_ids[0].id
)

def test_product_price_formula_based_on_other_price(self):
"""Test that pricelists with formula based on other pricelist
does not take alternative pricelists into account"""
self.assertEqual(self.pricelist03._get_product_price(self.usb_adapter, 1.0), 95)

def test_product_price_ignore_alternative_pricelist(self):
"""Test that the product price ignore alternative pricelist"""

Expand Down

0 comments on commit 672827a

Please sign in to comment.