Odoo Help


Odoo - Automatic computed fields stored on a second table

Odoo Group Ecuador
on 3/2/16, 2:42 PM 581 views

I am working i on a project which goal is:

Project have two tables (account_invoice_tax and new_computed_stored)

I created a Class but is not working, please forgive my gross coding, I am newbie :)

class account_invoice_tax(models.Model):
_inherits = {'new.computed.stored':'new_id'}
_inherit = 'account.invoice.tax'
retencion_id = fields.Many2one('new.computed.stored',ondelete='cascade',required=True)
computed = fields.Char(string='Some_help', compute='_compute_new', help='Insert_Something', store=True)

def _compute_new(self):
    for record in self:
        record.computed = record.calculado * 2
# not relevant which formula used
Odoo Group Ecuador
On 3/6/16, 1:24 PM

I found solution, I use not good the inheritance.

My solution was:

class account_invoice_tax(models.Model):
_inherit = 'account.invoice.tax'
x_tipo_impuesto = fields.Char('Tipo de Impuesto')
x_base_imponible = fields.Char('Base Imponible')
x_codigo_retencion = fields.Char('Código Retencion')
x_porcentaje_retencion = fields.Char('Porcentaje Retencion')
x_valor_retenido = fields.Float('Valor Retenido', compute='_compute_valor_retenido', digits=(12,2), store=True)
x_name = fields.Char('Item')
partner_id = fields.Char(string='Proveedor', store=True, related='invoice_id.partner_id.name')
retencion_id = fields.Many2one('modus.retenciones', 'Número de Retención', index=False)
ejercicio_fiscal = fields.Char('Ejercicio Fiscal')
base_imponible = fields.Float('Base Imponible', digits=(12,2), required=False)
codigo_impuesto = fields.Char('Código Impuesto')
impuesto_retencion = fields.Char('Impuesto')
porcent_retencion = fields.Float('Porcentaje Retención', digits=(3,0), required=False)
valor_retencion = fields.Float('Valor Retención', compute='_compute_valor_retencion', digits=(12,2), store=True)

@api.depends('base_imponible', 'porcent_retencion')
def _compute_valor_retencion(self):
    for record in self:
        record.valor_retencion = record.base_imponible * (record.porcent_retencion / 100)

def _compute_valor_retenido(self):
    for record in self:
        record.x_valor_retenido = record.amount * 2

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/2/16, 2:42 PM
Seen: 581 times
Last updated: 3/16/16, 2:33 PM