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

Odoo - Automatic computed fields stored on a second table

By
Odoo Group Ecuador
on 3/2/16, 2:42 PM 404 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)


@api.one
@api.depends('account_invoice_tax.amount')
def _compute_new(self):
    for record in self:
        record.computed = record.calculado * 2
# not relevant which formula used
0
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)

@api.depends('amount')
def _compute_valor_retenido(self):
    for record in self:
        record.x_valor_retenido = record.amount * 2

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: 3/2/16, 2:42 PM
Seen: 404 times
Last updated: 3/16/16, 2:33 PM