-
-
Notifications
You must be signed in to change notification settings - Fork 15
Closed
Description
Cases like:
name = fields.Char(
compute=_compute_name,
default=_default_name,
)
Should be avoided because:
- Methods are harcoded, which means they can't be inherited, because set methods are from that specific class, instead of model methods.
- We are forced to define such methods above field definition, which is against our guidelines, which specifies fields should go first, then methods.
Instead, the following should be done:
name = fields.Char(
compute="_compute_name",
default=lambda self: self._default_name(),
)
i.e. passing computed method as a string and default method as a lambda.
Attributes to consider for both cases
The following attributes support receiving a string:
computeinversesearchselection
(See the odoo.fields.determine method for more info and all the places where it is called)
The following attributes do not support receiving a string, hence they require passing a lambda:
defaultdomaintranslateondelete(dictionary values, not the dictionary itself)
(See all appearances of the callable() function in odoo.fields)
Discouraging cases like the above will prevent issues like odoo/odoo#185419.
CC @moylop260 @teposteaj
ajteposte
Metadata
Metadata
Assignees
Labels
No labels