Skip to content

Commit ff2dcb5

Browse files
committed
[FIX] sale_three_discounts: ensure proper handling of discount field during record creation and updates
closes #1461 Signed-off-by: matiasperalta1 <mnp@adhoc.com.ar>
1 parent ccf4bde commit ff2dcb5

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

sale_three_discounts/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
##############################################################################
2020
{
2121
"name": "Sale Three Discounts",
22-
"version": "18.0.1.3.0",
22+
"version": "18.0.1.4.0",
2323
"category": "Sales Management",
2424
"sequence": 14,
2525
"author": "ADHOC SA",

sale_three_discounts/models/account_move_line.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,26 @@ def check_discount_validity(self):
2929

3030
@api.depends("discount1", "discount2", "discount3")
3131
def _compute_discount(self):
32-
for line in self.filtered(lambda x: x.move_type not in ("in_invoice", "in_refund")):
32+
for line in self:
3333
discount_factor = 1.0
3434
for discount in [line.discount1, line.discount2, line.discount3]:
3535
discount_factor *= (100.0 - discount) / 100.0
3636
line.discount = 100.0 - (discount_factor * 100.0)
37+
38+
@api.model
39+
def _get_multiple_discount_field_names(self):
40+
return ["discount1", "discount2", "discount3"]
41+
42+
@api.model_create_multi
43+
def create(self, vals_list):
44+
for vals in vals_list:
45+
if vals.get("discount") and not any(vals.get(field) for field in self._get_multiple_discount_field_names()):
46+
vals["discount1"] = vals.pop("discount")
47+
return super().create(vals_list)
48+
49+
def write(self, vals):
50+
discount_fields = self._get_multiple_discount_field_names()
51+
if "discount" in vals:
52+
vals["discount1"] = vals.pop("discount")
53+
vals.update({field: 0 for field in discount_fields[1:]})
54+
return super().write(vals)

sale_three_discounts/views/account_invoice_views.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@
66
<field name="model">account.move</field>
77
<field name="inherit_id" ref="account.view_move_form" />
88
<field name="arch" type="xml">
9-
<xpath expr="//field[@name='invoice_line_ids']//list//field[@name='discount']" position="attributes">
10-
<attribute name="readonly">parent.move_type in ('out_invoice', 'out_refund')</attribute>
11-
<attribute name="force_save">1</attribute>
12-
</xpath>
139
<xpath expr="//field[@name='invoice_line_ids']//list//field[@name='discount']" position="before">
14-
<field name="discount1" column_invisible="parent.move_type not in ('out_invoice', 'out_refund')" groups="sale.group_discount_per_so_line" />
15-
<field name="discount2" column_invisible="parent.move_type not in ('out_invoice', 'out_refund')" groups="sale.group_discount_per_so_line" />
16-
<field name="discount3" column_invisible="parent.move_type not in ('out_invoice', 'out_refund')" groups="sale.group_discount_per_so_line" />
10+
<field name="discount1" groups="sale.group_discount_per_so_line" />
11+
<field name="discount2" groups="sale.group_discount_per_so_line" />
12+
<field name="discount3" groups="sale.group_discount_per_so_line" />
1713
</xpath>
1814
<xpath expr="//field[@name='line_ids']//list//field[@name='discount_amount_currency']" position="before">
1915
<field name="discount1" column_invisible="True" />

0 commit comments

Comments
 (0)