Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
4432 Переглядів

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


Аватар
Відмінити
Найкраща відповідь

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.

Аватар
Відмінити
Найкраща відповідь

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

Аватар
Відмінити
Найкраща відповідь

@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

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
Change position chatter Вирішено
1
серп. 25
132
4
лип. 25
1433
1
лип. 25
748
2
лип. 25
773
1
лип. 25
1909