Skip to Content
Menu
This question has been flagged
3 Replies
10676 Views

hello


what is the difference in api.multi and api.model_create_multi


and also want to know the difference between api.onchange and api.depends


thank you in advance


Avatar
Discard
Best Answer

Hi,

api.model_create_multi

The model_create_multi decorator is used with the methods that create multiple records from a single dictionary or a list of dictionaries. The values are passed as parameters to the method.

Here is an example code for @api.model_create_multi:

@api.model_create_multi
def create(self, vals):
cashboxes = super(AccountBankStmtCashWizard, self).create(vals)
cashboxes._validate_cashbox()
return cashboxes

@api.multi was used in the older versions.
@api.multi is used when we want to loop on records in this case self is the recordset , the recordset hold multiple record so we need to loop manually to extract record , if we want to verify that the Recordset hold a single record while using @api.multi ,we have to add self.ensure_one().

Regards

Avatar
Discard
Best Answer

Hello
@api.multi was used in the older versions and it means that the method can run with multiple records in the "self" variable (it is deprecated)
@api.model_create_multi is used in the create method in order to create multiple records in the same run.
using this decorater you shoud get a list of values instead of just a dict of values

Avatar
Discard
Best Answer

@api.depends

This decorator is specifically used for "fields.function" in odoo. For a "field.function", you can calculate the value and store it in a field, where it may possible that the calculation depends on some other field(s) of same table or some other table, in that case you can use '@api.depends' to keep a 'watch' on a field of some table.

So, this will trigger the call to the decorated function if any of the fields in the decorator is 'altered by ORM or changed in the form'.

Let's say there is a table 'A' with fields "x,y & z" and table 'B' with fields "p", where 'p' is a field.function depending upon the field 'x' from table 'A', so if any of the change is made in the field 'x', it will trigger the decorated function for calculating the field 'p' in table 'B'.

Make sure table "A" and "B" are related in some way.

@api.onchange

This decorator will trigger the call to the decorated function if any of the fields specified in the decorator is changed in the form. Here scope is limited to the same screen / model.

Let's say on form we have fields "DOB" and "Age", so we can have @api.onchange decorator for "DOB", where as soon as you change the value of "DOB", you can calculate the "age" field.

You may field similarities in @api.depends and @api.onchange, but the some differences are that scope of onchange is limited to the same screen / model while @api.depends works other related screen / model also.

Avatar
Discard

If I have both an @api.depends('field1') and another @api.depends('field1', 'anyotherfield') for two different methods which one will get executed first?