Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
4454 Widoki

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


Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

@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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
sie 25
166
4
lip 25
1507
1
lip 25
825
2
lip 25
853
1
lip 25
1965