Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] product_pricelist_alternative: validate alternative pricelist with based formula pricelist #1576

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions product_pricelist_alternative/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ msgstr "Politique de prix alternatifs"
msgid "Alternative Pricelists"
msgstr "Listes de prix alternatives"

#. module: product_pricelist_alternative
#. odoo-python
#: code:addons/product_pricelist_alternative/models/product_pricelist.py:0
#, python-format
msgid ""
"Formulas based on another pricelist are not allowed on alternative "
"pricelists."
msgstr ""
"Les formules basées sur un autre liste de prix ne sont pas autorisées sur les listes de prix alternatives "
"alternatifs."

#. module: product_pricelist_alternative
#: model:ir.model.fields,field_description:product_pricelist_alternative.field_product_pricelist__alternative_pricelist_ids
msgid "Alternative pricelists"
Expand All @@ -44,3 +55,16 @@ msgstr "Ignorer les alternatives"
#: model:ir.model.fields.selection,name:product_pricelist_alternative.selection__product_pricelist_item__alternative_pricelist_policy__use_lower_price
msgid "Use lower price"
msgstr "Utiliser le prix le plus bas"

#. module: product_pricelist_alternative
#. odoo-python
#: code:addons/product_pricelist_alternative/models/product_pricelist_item.py:0
#, python-format
msgid ""
"It is not possible to encode this price rule. Formulas based on another "
"pricelist are not allowed on alternative pricelists. Please change to "
"another type of price computation."
msgstr ""
"Il n'est pas possible d'encoder cette règle de prix. Les formules basées sur une autre "
"ne sont pas autorisées dans les listes de prix alternatives. Veuillez passer à "
"un autre type de calcul de prix."
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Project-Id-Version: Odoo Server 16.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-04-10 13:21+0000\n"
"PO-Revision-Date: 2024-04-10 13:21+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -33,6 +35,15 @@ msgstr ""
msgid "Alternative to Pricelist"
msgstr ""

#. module: product_pricelist_alternative
#. odoo-python
#: code:addons/product_pricelist_alternative/models/product_pricelist.py:0
#, python-format
msgid ""
"Formulas based on another pricelist are not allowed on alternative "
"pricelists."
msgstr ""

#. module: product_pricelist_alternative
#: model:ir.model.fields.selection,name:product_pricelist_alternative.selection__product_pricelist_item__alternative_pricelist_policy__ignore
msgid "Ignore alternatives"
Expand All @@ -55,6 +66,16 @@ msgstr ""
msgid "Is alternative to pricelists"
msgstr ""

#. module: product_pricelist_alternative
#. odoo-python
#: code:addons/product_pricelist_alternative/models/product_pricelist_item.py:0
#, python-format
msgid ""
"It is not possible to encode this price rule. Formulas based on another "
"pricelist are not allowed on alternative pricelists. Please change to "
"another type of price computation."
msgstr ""

#. module: product_pricelist_alternative
#: model:ir.model,name:product_pricelist_alternative.model_product_pricelist
msgid "Pricelist"
Expand Down
16 changes: 16 additions & 0 deletions product_pricelist_alternative/models/product_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class Pricelist(models.Model):
Expand Down Expand Up @@ -80,3 +81,18 @@
if alternative_price_rule[product.id][0] < res[product.id][0]:
res[product.id] = alternative_price_rule[product.id]
return res

@api.constrains("alternative_pricelist_ids")
def _check_pricelist_alternative_items_based_on_other_pricelist(self):
"""Alternative pricelists can not contain items based on other pricelist"""
for pricelist in self:
if pricelist.alternative_pricelist_ids.item_ids.filtered(
lambda item: item.compute_price == "formula"
and item.base == "pricelist"
):
santostelmo marked this conversation as resolved.
Show resolved Hide resolved
raise ValidationError(

Check warning on line 93 in product_pricelist_alternative/models/product_pricelist.py

View check run for this annotation

Codecov / codecov/patch

product_pricelist_alternative/models/product_pricelist.py#L93

Added line #L93 was not covered by tests
_(
"Formulas based on another pricelist are not allowed "
"on alternative pricelists."
)
)
20 changes: 19 additions & 1 deletion product_pricelist_alternative/models/product_pricelist_item.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright 2024 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class PricelistItem(models.Model):
Expand All @@ -15,3 +16,20 @@ class PricelistItem(models.Model):
default="use_lower_price",
required=True,
)

@api.constrains("base")
def _check_pricelist_alternative_items_based_on_other_pricelist(self):
"""Alternative pricelists can not contain items based on other pricelist"""
for item in self:
if (
item.compute_price == "formula"
and item.base == "pricelist"
and item.pricelist_id.is_alternative_to_pricelist_count
):
raise ValidationError(
_(
"It is not possible to encode this price rule. Formulas based "
"on another pricelist are not allowed on alternative pricelists."
" Please change to another type of price computation."
)
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2024 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.exceptions import ValidationError
from odoo.tests import common, tagged

from .common import CommonProductPricelistAlternative
Expand Down Expand Up @@ -92,3 +92,15 @@ def test_skip_alternative_pricelist(self):
)._get_product_price(self.usb_adapter, 1.0),
95,
)

def test_check_pricelist_alternative_items_based_on_other_pricelist(self):
with self.assertRaises(ValidationError) as e:
self.alternative_pricelist_01.item_ids.write(
{
"compute_price": "formula",
"base": "pricelist",
"base_pricelist_id": self.alternative_pricelist_02.id,
}
)
msg = "Formulas based on another pricelist are not allowed on alternative pricelists."
self.assertIn(msg, e.exception.args[0])
Loading