diff --git a/joint_buying_product/i18n/fr.po b/joint_buying_product/i18n/fr.po index ebd112e9..528030f1 100644 --- a/joint_buying_product/i18n/fr.po +++ b/joint_buying_product/i18n/fr.po @@ -2501,6 +2501,12 @@ msgstr "Vous ne pouvez pas mettre une unité de mesure poids / unité, si l'arti msgid "You can not set a negative quantity in the 'Purchase Quantity' field !" msgstr "Vous ne pouvez pas saisir de quantité négative dans le champ 'quantité à commander' !" +#. module: joint_buying_product +#: code:addons/joint_buying_product/models/res_partner.py:105 +#, python-format +msgid "You can not uncheck 'Use Order Categories' if some categories are defined in the 'Next Orders' Section." +msgstr "Vous ne pouvez pas décocher la case 'Utiliser les catégories de commandes, si certaines catégories sont paramétrées dans la section 'Prochaines commandes'." + #. module: joint_buying_product #: code:addons/joint_buying_product/models/joint_buying_purchase_order.py:407 #, python-format diff --git a/joint_buying_product/models/res_partner.py b/joint_buying_product/models/res_partner.py index 57462fb4..7aebe960 100644 --- a/joint_buying_product/models/res_partner.py +++ b/joint_buying_product/models/res_partner.py @@ -2,7 +2,8 @@ # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import api, fields, models +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError class ResPartner(models.Model): @@ -94,6 +95,19 @@ def _compute_joint_buying_grouped_order_qty(self): partner.joint_buying_grouped_order_ids ) + @api.constrains( + "joint_buying_use_category", "joint_buying_frequency_ids.category_ids" + ) + def _check_joint_buying_use_category(self): + for partner in self.filtered(lambda x: not x.joint_buying_use_category): + if partner.mapped("joint_buying_frequency_ids.category_ids"): + raise ValidationError( + _( + "You can not uncheck 'Use Order Categories'" + " if some categories are defined in the 'Next Orders' Section." + ) + ) + # Custom Section def _get_joint_buying_products(self, categories): self.ensure_one()