Skip to content

Commit b42e083

Browse files
committed
[FIX] price_security: restrict global discount and fixed amount
X-original-commit: 2963aaa
1 parent 811ddd1 commit b42e083

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-1
lines changed

price_security/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
# directory
44
##############################################################################
55
from . import models
6+
from . import wizard

price_security/__manifest__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
##############################################################################
2020
{
2121
"name": "Price Security",
22-
"version": "18.0.1.1.0",
22+
"version": "18.0.1.2.0",
2323
"category": "Sales Management",
2424
"author": "ADHOC SA, Odoo Community Association (OCA)",
2525
"website": "http://www.adhoc.com.ar/",
@@ -32,6 +32,7 @@
3232
"data": [
3333
"security/price_security_security.xml",
3434
"security/ir.model.access.csv",
35+
"wizard/sale_order_discount_views.xml",
3536
"views/account_move_views.xml",
3637
"views/account_payment_term_views.xml",
3738
"views/product_template_views.xml",

price_security/i18n/es.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,12 @@ msgstr ""
214214
#: code:addons/price_security/models/res_users.py:0
215215
msgid "You can not give any discount greater than pricelist discounts"
216216
msgstr ""
217+
218+
#. module: price_security
219+
#. odoo-python
220+
#: code:addons/price_security/wizard/sale_order_discount.py:0
221+
#, python-format
222+
msgid ""
223+
"You do not have permission to apply this type of discount with the current "
224+
"pricelist."
225+
msgstr "No tienes permiso para aplicar este tipo de descuento con la lista de precios actual."

price_security/wizard/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import sale_order_discount
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from odoo import _, api, fields, models
2+
from odoo.exceptions import ValidationError
3+
4+
5+
class SaleOrderDiscount(models.TransientModel):
6+
_inherit = "sale.order.discount"
7+
8+
discount_restriction = fields.Boolean(compute="_compute_discount_restriction")
9+
10+
@api.depends("discount_type")
11+
def _compute_discount_restriction(self):
12+
restricted_types = {"amount", "so_discount"}
13+
user = self.env.user
14+
15+
for wizard in self:
16+
if (
17+
wizard.discount_type in restricted_types
18+
and user.has_group("price_security.group_only_view")
19+
and wizard.sale_order_id.pricelist_id in user.discount_restriction_ids.mapped("pricelist_id")
20+
):
21+
wizard.discount_restriction = True
22+
else:
23+
wizard.discount_restriction = False
24+
25+
@api.constrains("discount_type")
26+
def _check_discount_type(self):
27+
if self.filtered("discount_restriction"):
28+
raise ValidationError(
29+
_("You do not have permission to apply this type of discount " "with the current pricelist.")
30+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<odoo>
3+
<record id="sale_order_line_wizard_form" model="ir.ui.view">
4+
<field name="name">sale.order.line.wizard.form</field>
5+
<field name="model">sale.order.discount</field>
6+
<field name="inherit_id" ref="sale.sale_order_line_wizard_form"/>
7+
<field name="arch" type="xml">
8+
<xpath expr="//sheet" position="before">
9+
<div class="alert alert-warning" role="alert" invisible="not discount_restriction">
10+
Advertencia: No tienes permiso para aplicar este tipo de descuento con la lista de precios actual.
11+
</div>
12+
</xpath>
13+
</field>
14+
</record>
15+
</odoo>

0 commit comments

Comments
 (0)