Skip to Content
Menu
This question has been flagged
1 Reply
2024 Views

i made a new field in account form and it work well i calculated on it as well but when i save it, my new field was reset to 0.

I cant save the form with my field information and i dont know why?



from openerp import models, fields, api, exceptions

class ColombianTaxes(models.Model):

""" Model to create and manipulate personal taxes"""

_description= "Model to create own taxes"

_name = 'account.invoice'

_inherit = 'account.invoice'

# Define rfuente as new tax.

rfuente = fields.Monetary('Retencion en la fuente:',store="True" , compute = "rfuente_pc")

# Calculate rfuente and total amount

@api.onchange('amount_untaxed', 'amount_total')

def rfuente_pc(self):

self.rfuente = self.amount_untaxed * 0.025

self.amount_total = self.amount_total + self.rfuente

Avatar
Discard
Best Answer

 @api.onchange will call in change of simple form field. But, when you want to use computed field (field.function) then you need to use @api.depends decorator.

Example:

compute_field = fields.Text(
    string="Compute Field", store=True,
    compute="_get_compute_field"
)
@api.depends('employee_id') def _get_compute_field(self): if self.employee_id.department_id: self.compute_field = self.employee_id.department_id.name


Avatar
Discard