Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
2265 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
3
Mei 23
17143
2
Jul 22
6892
1
Des 20
37584
3
Feb 24
18054
1
Jun 25
15178