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

Hello,

i'm odoo developer for more than 8 years now and still have one question, i've read documentation many time also in code but for now can't find answer what difference with and without decoration model and model_create_multi in both code works V15


-----------------------------------------------


@api.model_create_multi

def create(self, vals):

​ cashboxes = super().create(vals)

​ return cashboxes


-----------------------------------------------


@api.model

def _get_default_currency(self):

​ journal = self._get_default_journal()

​ return journal.currency_id


Avatar
Discard
Best Answer

Hi Tom Cikog,

  • The @api.model_create_multi decorator is used to decorate the create method in an Odoo model. This decorator is used when you want to make multiple records of the model at once. Editing the method with @api.model_create_multi can create multiple records with a single API call, which can significantly improve performance compared to creating records one at a time
  • The @api.Model decorator is used to outline default values or techniques on the model stage.

In summary, the main difference is that @api.model_create_multi is used to create multiple records at once, while @api.model is used to define methods or default values ​​at the model level Properties both have their own implementation specific context in Odoo development.

Thanks.

Avatar
Discard
Best Answer

Hi,

The @api.model_create_multi decorator is used to decorate the create() method in an Odoo model. This decorator is used when you want to create multiple records of the model at once. Without the decorator, the create() method can only create one record at a time.

The @api.model decorator is used to decorate methods that operate on the model level, not on the recordset level. This decorator is used for methods that do not need to access the current record, such as the _get_default_currency() method in your example.

In your code, both the create() and _get_default_currency() methods will work without the decorators. However, using the decorators can make your code more readable and maintainable.

Hope it helps

Avatar
Discard
Best Answer

@api.model_create_multi : Create multiple records of a model in a single call and you can pass a list of dictionaries to create multiple records simultaneously.

@api.model : Create single record of a model.

Thanks & Regards,

David

Avatar
Discard
Related Posts Replies Views Activity
1
May 25
94
0
May 25
244
1
May 25
446
1
May 25
533
0
Apr 25
2