summaryrefslogtreecommitdiff
path: root/doc/python3.rst
diff options
context:
space:
mode:
authorYannick Tivisse <yti@odoo.com>2018-05-04 16:45:41 +0200
committerYannick Tivisse <yti@odoo.com>2018-05-23 11:15:46 +0200
commit473c74f6368b9ce4c2242c53263811a925837855 (patch)
tree3ddb4ff028624973c42560ae892a06b35c8a1c54 /doc/python3.rst
parent565277acbb3995a304f8ea2a9aed98c3518420a3 (diff)
[IMP] various: Override _(name_)search instead of (name_)search
Purpose ======= The method _name_search and _search add support to search as another user. All the overrides of name_search and search redefine the behavior of the search. This bring inconsistencies as the result of a call to _name_search and name_search could differ on certain modules, which is not acceptable. Specification ============= Example: ~~~~~~~~ If the name_search method is overridden to search also on the driver name, then calling name_search with a label 'JF' will return all the cars with a name containing 'JF' or all the cars with a driver name containing 'JF'. Let's say that we have a ir.rule preventing a user to read the cars of another company. Then the call to name search only returns the cars satisfying the previous condition AND belonging to his company. Now, we want to overpass this constraint. We call _name_search with the attribute name_get_uid=1. Then the call to _name_search returns all the cars from all the companies with a name like 'JF', but nothing is done about the driver_name. Example of wrong search redefinition on a model ----------------------------------------------- @api.model def name_search(self, name, args=None, operator='ilike', limit=100): domain = args or [] domain = expression.AND([domain, [('name', 'ilike', name)]]) partners = self.env['res.partner'].search([('name', operator, name)]) if partners and name: domain = expression.OR([domain, ['|', ('driver_id', 'in', partners.ids), ('driver_id', '=', False)]]) rec = self.search(domain, limit=limit) return rec.name_get() Example of correct search redefinition on a model ------------------------------------------------- @api.model def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): domain = args or [] domain = expression.AND([domain, [('name', operator, name)]]) partner_ids = self.env['res.partner']._search([('name', operator, name)], access_rights_uid=name_get_uid) if partner_ids: domain = expression.OR([domain, ['|', ('driver_id', 'in', partner_ids), ('driver_id', '=', False)]]) rec = self._search(domain, limit=limit, access_rights_uid=name_get_uid) return self.browse(rec).name_get() The same logic should be applied on the overrides of the search method.
Diffstat (limited to 'doc/python3.rst')
0 files changed, 0 insertions, 0 deletions