Navi
Navi

Reputation: 1052

How to store values using onchange in odoo?

If I save the amount_total value changes to prior position because it is readonly. i want that field to be readonly.

discount = fields.Selection([('fixed', 'fixed Price'), ('percentage', 'Percentage')], string="Discount")
amount = fields.Float("Amount")
total = fields.Float("Discounted Amount", store=True, compute='discount_amount')
amount_total = fields.Monetary(string='Total', store=True,readonly=True, compute='_amount_all')




    @api.onchange('total')
def totalamount(self):
    if self.total:
        self.amount_total -= self.total

How to deal with this

Upvotes: 1

Views: 2221

Answers (1)

sfx
sfx

Reputation: 1841

Instead of writing on change function you can do like the following

@api.depends('total')
def _amount_all(self):
    if self.total:
       total_amount = self.amount_total - self.total
    self.update({
           'amount_total': total_amount
        })

Upvotes: 1

Related Questions