Skip to Content
Menu
This question has been flagged
2 Replies
2436 Views

Hello

How can I show in the view: id = "product_template_product_form_view" the total field = fields.Float ('total', compute = '_ getamount') of class class AccountTax (models.Model) ?

this is my code:

ratio.py :

from odoo import fields, models, api, tools


class ProductTemplate(models.Model):
_name = 'product.template'
_inherit = 'product.template'

pventa_iva = fields.Float('PVP (IVA)')
pcompra_iva = fields.Float('COSTE (IVA)')
ratio = fields.Float('Ratio')
iva = fields.Integer('datos iva', compute='_venta_iva')
cant = fields.Many2many(comodel_name='account.tax', string='Tasas')
impuestos = fields.Float(compute='_compute_impuestos')

@api.depends('taxes_id')
def _venta_iva(self):
for record in self:
record.iva = record.taxes_id


class AccountTax(models.Model):
_name = 'account.tax'
_inherit = 'account.tax'

total = fields.Float('total', compute='_getamount')

@api.depends('amount')
def _getamount(self):
for record in self:
record.total = record.amount


And this is my view:

<record id="product_template_product_form_view" model="ir.ui.view">
<field name="name">product.template.product.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<field name="list_price" position="before">
<field name="ratio"/>
<!-- <field name="amount" ref="account.view_tax_form"/> -->
</field>
<field name="list_price" position="after">
<field name="pventa_iva"/>
</field>
<field name="uom_id" position="before">
<field name="pcompra_iva"/>
<field name="iva"/>
<span t-esc="o._getamount"/>
<!-- <field name="total" ref="vista_iva"/>-->
<field name="cant"/>
<field name="impuestos"/>
<field name="taxes_id" widget="many2many_tags" on_change="1" can_create="true" can_write="true" modifiers="{}"/>
</field>
</field>
</record>

<record id="vista_iva" model="ir.ui.view">
<field name="name">vista.iva</field>
<field name="model">account.tax</field>
<field name="inherit_id" ref="account.view_tax_form"/>
<field name="arch" type="xml">
<field name="amount" position="after">
<field name="total"/>
</field>
</field>
</record>
Avatar
Discard

Would you please share the issue you are facing in this code?

Best Answer

Hm... for Many2many relation I can't say. Are you using the relation correctly? Try using a computed field and get the values with a method that computes all data in the relation.

The One2many and Many2one relations you have other options to get data. One2many you can use display a list of children.

In Many2one you can use related to show fields from parent 

total = fields.Float(related='<field with relation>.total')

 and then you can use that field in the view.

Look at this widgets, maybe one can help you

https://odooforbeginnersblog.wordpress.com/2017/03/09/widgets-in-odoo/

Avatar
Discard
Related Posts Replies Views Activity
1
Jan 24
12008
0
Apr 17
1786
4
Apr 24
170735
0
Dec 23
610
2
Oct 23
4750