Criptomart/red-supermercados-coop#17 add account_invoice_triple_discount_readonly: fix write discount2 and dicount3 columns. Make discount (total) readonly
This commit is contained in:
parent
7df39dbda8
commit
5c213a3d6a
9 changed files with 215 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
from . import triple_discount_mixin
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
from odoo import fields, models
|
||||
|
||||
|
||||
class TripleDiscountMixin(models.AbstractModel):
|
||||
_inherit = "triple.discount.mixin"
|
||||
|
||||
# Make the discount field readonly to prevent manual edits
|
||||
discount = fields.Float(readonly=True)
|
||||
|
||||
def write(self, vals):
|
||||
discount_fields = self._get_multiple_discount_field_names()
|
||||
|
||||
if "discount" in vals:
|
||||
# Check if any of discount1, discount2 or discount3
|
||||
# are being explicitly modified
|
||||
has_explicit_discounts = any(field in vals for field in discount_fields)
|
||||
|
||||
if has_explicit_discounts:
|
||||
# If there are explicit discounts, remove the computed 'discount' field
|
||||
# to avoid overwriting the explicit values
|
||||
vals.pop("discount")
|
||||
else:
|
||||
# If only 'discount' comes, apply legacy behavior:
|
||||
# map to discount1 and reset discount2 and discount3
|
||||
vals["discount1"] = vals.pop("discount")
|
||||
vals.update({field: 0 for field in discount_fields[1:]})
|
||||
|
||||
return super().write(vals)
|
||||
Loading…
Add table
Add a link
Reference in a new issue