diff options
| author | Adrian Torres <adt@odoo.com> | 2019-07-10 14:59:37 +0200 |
|---|---|---|
| committer | Adrian Torres <adt@odoo.com> | 2019-07-17 14:13:12 +0200 |
| commit | 4b38cc6590abcb58a0ca102a06063eb3db7ac1f4 (patch) | |
| tree | cfd11739fc6b4c0cb4b23b54cc6badad4bf5c55e /doc/reference/guidelines.rst | |
| parent | f6fdde96bddfedf8764cd8a73089e44340d476ae (diff) | |
[REM] *: calls to @api.multi
Multi is the default api for methods, it is not necessary to explicitly
decorate methods with it, adds clutter and most people use it because
they see that the rest of the code uses it.
Done with `find . -type f -name '*.py' | xargs sed -i '/@api.multi/d'`
Diffstat (limited to 'doc/reference/guidelines.rst')
| -rw-r--r-- | doc/reference/guidelines.rst | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/doc/reference/guidelines.rst b/doc/reference/guidelines.rst index de9723121ff..c1a282cf19f 100644 --- a/doc/reference/guidelines.rst +++ b/doc/reference/guidelines.rst @@ -586,13 +586,11 @@ Programming in Odoo Make your method work in batch ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -When adding a function, make sure it can process multiple records. Typically, -such methods are decorated with the ``api.multi`` decorator. Then you will have -to iterate on ``self`` to treat each record. +When adding a function, make sure it can process multiple records by iterating +on self to treat each record. .. code-block:: python - @api.multi def my_method(self) for record in self: record.do_cool_stuff() @@ -607,7 +605,6 @@ is recommended to use ``read_group`` method, to compute all value in only one re .. code-block:: python - @api.multi def _compute_equipment_count(self): """ Count the number of equipement per category """ equipment_data = self.env['hr.equipment'].read_group([('category_id', 'in', self.ids)], ['category_id'], ['category_id']) @@ -943,8 +940,8 @@ Symbols and Conventions - Selection method: the selection method pattern is *_selection_<field_name>* - Onchange method : the onchange method pattern is *_onchange_<field_name>* - Constraint method : the constraint method pattern is *_check_<constraint_name>* - - Action method : an object action method is prefix with *action_*. Its decorator is - ``@api.multi``, but since it use only one record, add ``self.ensure_one()`` + - Action method : an object action method is prefix with *action_*. + Since it uses only one record, add ``self.ensure_one()`` at the beginning of the method. - In a Model attribute order should be @@ -979,7 +976,6 @@ Symbols and Conventions event_type = fields.Selection(string="Type", selection='_selection_type') # compute and search fields, in the same order of fields declaration - @api.multi @api.depends('seats_max', 'registration_ids.state', 'registration_ids.nb_register') def _compute_seats(self): ... @@ -1002,7 +998,6 @@ Symbols and Conventions ... # Action methods - @api.multi def action_validate(self): self.ensure_one() ... |
