diff --git a/price_security/__manifest__.py b/price_security/__manifest__.py
index ae848e6cb..06bffa169 100644
--- a/price_security/__manifest__.py
+++ b/price_security/__manifest__.py
@@ -19,7 +19,7 @@
##############################################################################
{
"name": "Price Security",
- "version": "18.0.1.3.0",
+ "version": "18.0.1.4.0",
"category": "Sales Management",
"author": "ADHOC SA, Odoo Community Association (OCA)",
"website": "http://www.adhoc.com.ar/",
diff --git a/price_security/models/account_payment_term.py b/price_security/models/account_payment_term.py
index 0ac227929..afeddbcaf 100644
--- a/price_security/models/account_payment_term.py
+++ b/price_security/models/account_payment_term.py
@@ -9,6 +9,14 @@ class AccountPaymentTerm(models.Model):
_inherit = "account.payment.term"
sequence = fields.Integer(default=lambda self: self._get_default_sequence())
+ payment_term_allowed_ids = fields.Many2many(
+ comodel_name="account.payment.term",
+ relation="account_payment_term_allowed_rel",
+ column1="user_id",
+ column2="payment_term_id",
+ string="Allowed Payment Terms",
+ help="Payment terms that a user with restrictions can select",
+ )
def _get_default_sequence(self):
last_sequence = self.env["account.payment.term"].search([], order="sequence DESC", limit=1).sequence
diff --git a/price_security/models/product_pricelist.py b/price_security/models/product_pricelist.py
index feb608acf..888bdcb40 100644
--- a/price_security/models/product_pricelist.py
+++ b/price_security/models/product_pricelist.py
@@ -9,3 +9,11 @@ class ProductPricelist(models.Model):
_inherit = "product.pricelist"
sequence = fields.Integer()
+ pricelist_allowed_ids = fields.Many2many(
+ comodel_name="product.pricelist",
+ relation="product_pricelist_allowed_rel",
+ column1="pricelist_id",
+ column2="allowed_pricelist_id",
+ string="Allowed Pricelists",
+ help="Pricelists that a user with price restriction can select",
+ )
diff --git a/price_security/models/sale_order.py b/price_security/models/sale_order.py
index dc37a0d69..0fb2624a9 100644
--- a/price_security/models/sale_order.py
+++ b/price_security/models/sale_order.py
@@ -11,24 +11,39 @@
class SaleOrder(models.Model):
_inherit = "sale.order"
- @api.constrains("pricelist_id", "payment_term_id", "partner_id")
- def check_priority(self):
- if not self.env.user.has_group("price_security.group_only_view"):
- return True
- if (
- self.partner_id.property_product_pricelist
- and self.pricelist_id
- and self.partner_id.property_product_pricelist.sequence < self.pricelist_id.sequence
- ):
- raise UserError(_("Selected pricelist priority can not be higher than pircelist " "configured on partner"))
- if (
- self.partner_id.property_payment_term_id
- and self.payment_term_id
- and self.partner_id.property_payment_term_id.sequence < self.payment_term_id.sequence
- ):
- raise UserError(
- _("Selected payment term priority can not be higher than " "payment term configured on partner")
- )
+ @api.constrains("payment_term_id", "partner_id")
+ def check_allowed_payment_term(self):
+ for order in self:
+ if not self.env.user.has_group("price_security.group_only_view"):
+ continue
+
+ partner_payment_term = order.partner_id.property_payment_term_id
+ if not partner_payment_term or not order.payment_term_id:
+ continue
+
+ allowed = partner_payment_term.payment_term_allowed_ids
+
+ if order.payment_term_id not in allowed and order.payment_term_id != partner_payment_term:
+ raise UserError(
+ _("You are not allowed to select this payment term according to the restrictions configured")
+ )
+
+ @api.constrains("pricelist_id", "partner_id")
+ def check_allowed_pricelist(self):
+ for order in self:
+ if not self.env.user.has_group("price_security.group_only_view"):
+ continue
+
+ partner_pricelist = order.partner_id.property_product_pricelist
+ if not partner_pricelist or not order.pricelist_id:
+ continue
+
+ allowed = partner_pricelist.pricelist_allowed_ids
+
+ if order.pricelist_id not in allowed and order.pricelist_id != partner_pricelist:
+ raise UserError(
+ _("You are not allowed to select this pricelist according to the restrictions configured")
+ )
@api.onchange("partner_id")
def check_partner_pricelist_change(self):
@@ -38,7 +53,7 @@ def check_partner_pricelist_change(self):
if self.order_line and pricelist != self._origin.pricelist_id:
if self.env.user.has_group("price_security.group_only_view"):
self.partner_id = self._origin.partner_id
- msj = _("You can not change partner if there are sale lines" " and pricelist is going to be changed")
+ msj = _("You can not change partner if there are sale lines and pricelist is going to be changed")
else:
msj = _(
"The change of the customer generates a change in the"
diff --git a/price_security/views/account_payment_term_views.xml b/price_security/views/account_payment_term_views.xml
index 8c2d10102..151b3509b 100644
--- a/price_security/views/account_payment_term_views.xml
+++ b/price_security/views/account_payment_term_views.xml
@@ -8,6 +8,9 @@
+
+
+
@@ -18,6 +21,9 @@
+
+
+
diff --git a/price_security/views/product_pricelist_views.xml b/price_security/views/product_pricelist_views.xml
index 763b15c52..f7f4ea1cc 100644
--- a/price_security/views/product_pricelist_views.xml
+++ b/price_security/views/product_pricelist_views.xml
@@ -8,6 +8,20 @@
+
+
+
+
+
+
+
+ product.pricelist.list
+ product.pricelist
+
+
+
+
+