Skip to content

[IMP] *: correct create examples #12527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions content/administration/odoo_sh/getting_started/first_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -481,15 +481,16 @@ Add
.. code-block:: python

@api.model
def create(self, values):
if 'name' in values:
values['name'] = unidecode(values['name'])
return super(my_module, self).create(values)

def write(self, values):
if 'name' in values:
values['name'] = unidecode(values['name'])
return super(my_module, self).write(values)
def create(self, vals_list):
for vals in vals_list:
if 'name' in vals:
vals['name'] = unidecode(vals['name'])
return super().create(vals_list)

def write(self, vals):
if 'name' in vals:
vals['name'] = unidecode(vals['name'])
return super().write(vals)

Adding a Python dependency requires a module version increase for the platform to install it.

Expand Down
3 changes: 2 additions & 1 deletion content/contributing/development/coding_guidelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,8 @@ Symbols and Conventions
...

# CRUD methods (and name_search, _search, ...) overrides
def create(self, values):
@api.model
def create(self, vals_list):
...

# Action methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ specific business logic::
...

@api.model
def create(self, vals):
def create(self, vals_list):
# Do some business logic, modify vals...
...
# Then call super to execute the parent method
return super().create(vals)
return super().create(vals_list)

The decorator :func:`~odoo.api.model` is necessary for the :meth:`~odoo.models.Model.create`
method because the content of the recordset ``self`` is not relevant in the context of creation,
Expand Down