Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
2255 Vistas

Hi Forum!

I have a computed field called 'x_total_price_tax_inc', but the problem with it is that it doesn't seem to call the function it uses.


for record in self:
record.['x_total_price_tax_inc'] = record.list_price * 1.20


What could be the problem?

Avatar
Descartar
Mejor respuesta

Hello

The code you provided is a Python code snippet that updates the "x_total_price_tax_inc" field of an Odoo record with a value calculated based on the "list_price" field. To define a compute method that achieves the same result, you can do the following:

@api.depends('list_price')
def _compute_total_price_tax_inc(self):
​for record in self:
​record.x_total_price_tax_inc = record.list_price * 1.20

Explanation:

  1. The @api.depends decorator indicates that this method depends on the "list_price" field of the record, which means that it should be automatically recalculated whenever the "list_price" field is changed.

  2. The _compute_total_price_tax_inc method is a compute method that takes a single argument, which is the recordset that this method is being called on.

  3. The for record in self: loop iterates over each record in the recordset.

  4. The record.x_total_price_tax_inc = record.list_price * 1.20 line calculates the "x_total_price_tax_inc" field based on the "list_price" field and assigns the result to the "x_total_price_tax_inc" field of the current record.

  5. Once the method has finished iterating over all records in the recordset, the "x_total_price_tax_inc" field of each record will have been updated based on its "list_price" field.

Thanks & Regards,



CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209
Email: info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229-1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
may 23
17137
2
jul 22
6887
1
dic 20
37564
3
feb 24
18050
1
jun 25
15156