Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

save custom field in account form.

By
JORGE TORRES
on 6/28/16, 3:20 PM 153 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

0
Nikunj Antala
On 6/29/16, 12:51 AM

 @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


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/28/16, 3:20 PM
Seen: 153 times
Last updated: 7/11/16, 9:22 AM