Skip to content

Commit

Permalink
[IMP] joint_buying_product: avoid bad configuration if use Order Cate…
Browse files Browse the repository at this point in the history
…gories is bad unchecked
  • Loading branch information
legalsylvain committed Oct 18, 2024
1 parent 7b6a4c9 commit 228748f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions joint_buying_product/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion joint_buying_product/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 228748f

Please sign in to comment.