From 40778d883d7894cccdd709c421aea1dcd056e54d Mon Sep 17 00:00:00 2001 From: jem-odoo Date: Mon, 26 Feb 2018 14:19:03 +0100 Subject: [PATCH] [IMP] doc: add selection method guideline Sometime, we need to get selection values from a method. Here are the guidelines about how to correctly name method and place it in the code. --- doc/reference/guidelines.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/reference/guidelines.rst b/doc/reference/guidelines.rst index 11db3c1e8c3..cd83f0bd8f5 100644 --- a/doc/reference/guidelines.rst +++ b/doc/reference/guidelines.rst @@ -826,6 +826,7 @@ Symbols and Conventions - Compute Field : the compute method pattern is *_compute_* - Search method : the search method pattern is *_search_* - Default method : the default method pattern is *_default_* + - Selection method: the selection method pattern is *_selection_* - Onchange method : the onchange method pattern is *_onchange_* - Constraint method : the constraint method pattern is *_check_* - Action method : an object action method is prefix with *action_*. Its decorator is @@ -836,7 +837,8 @@ Symbols and Conventions #. Private attributes (``_name``, ``_description``, ``_inherit``, ...) #. Default method and ``_default_get`` #. Field declarations - #. Compute and search methods in the same order as field declaration + #. Compute, inverse and search methods in the same order as field declaration + #. Selection method (methods used to return computed values for selection fields) #. Constrains methods (``@api.constrains``) and onchange methods (``@api.onchange``) #. CRUD methods (ORM overrides) #. Action methods @@ -860,6 +862,7 @@ Symbols and Conventions seats_available = fields.Integer(oldname='register_avail', string='Available Seats', store=True, readonly=True, compute='_compute_seats') price = fields.Integer(string='Price') + type = fields.Selection(string="Type", selection='_selection_type') # compute and search fields, in the same order of fields declaration @api.multi @@ -867,6 +870,10 @@ Symbols and Conventions def _compute_seats(self): ... + @api.model + def _selection_type(self): + return [] + # Constraints and onchanges @api.constrains('seats_max', 'seats_available') def _check_seats_limit(self):