-1

In odoo v11 when i use @api.multi decorator, the self variable is the actual recordset. But what records are in that recordset?

For example: In odoo I click on a partner. The partner has a computed field. The method of that computed field is decorated with @api.multi. In that recordset on the 0th place, there is the record i want. But why there are other records?

I know what @api.one does - iterating through the recordset and redefining the self variable as the current recordset.

I'm facing this problem, because i want to fill fields via a WebService call from Navision at the time I click on a partner. So i defined a temp field which is computed by a method. in that method i call the webservice and update the four fields i want to show.

any explanations / suggestions?

Thanks. -JS

  • In compute methods you get the list of records that needs to recompute the value because something changes that trigger computting for all of them.. – Charif DZ Nov 17 '18 at 06:12

1 Answers1

0

I am not sure I interpret your question 100% correctly.

api.one() is deprecated since V9 due to common misinterpretation by developers, according to ORM API V11 documentation
Successor of api.one() is by using api.multi(), within the method, call ensure_one when needed.

If your model expects only One record in the particular recordsets, do this

@api.multi
@api.depends('your_temp_field')
def _my_method(self):
    self.ensure_one() # self is a recordsets, if it contains more than 1 record, error will be raised.
    for record in self:
        record.field1 = 'value1'
        record.field2 = 'value2'
        record.field3 = 'value3'
        record.field4 = 'value4'

If your model expects more than One record, but you need to modify specific record(s).
You can simply use some if-else statements for targeted records.
If you only want the 0th position, use index field as your condition instead.

Be aware index adds overhead to your database in terms of performance and size as well since default search/sorting function are based on that.

You can find a good example here.

Cayprol
  • 21
  • 2