[FIX] res.partner: search using 'child_of' should include inactive children
This is necessary for 2 reasons: - when searching on Business documents the search domain will be [('partner_id', 'child_of', 'ACME')] in order to match all descendants, and it must match inactive children as well - in other cases like for resolving IDs to update via store triggers, it is necessary that 'child_of' returns inactive children too. The implementation is tricky because the ORM automatically transform 'child_of' domains into recursive searches with [('parent_id', 'in', ids)], which is the same query that the reverse one2many 'child_ids' will also use to find contacts. The overridden search() therefore matches this domain pattern only when there is one criterion (to avoid side-effects in other cases) and a dummy extra 'domain' was added to the definition of the 'child_ids' o2m so it won't match. The net result is that child_ids will not return inactive children while child_of will return all descendants when it is the only criterion. This is the expected behavior whenever child_of is used on res.partner, because it's safer to always show business documents. The only side-effects will be for custom/manual search calls with a single criterion of the form ('parent_id','in', x) and those can be fixed by adding an extra domain component ('active','=',True), just like child_ids does. bzr revid: odo@openerp.com-20130419135756-2kbhwr23lygqdoob
This commit is contained in:
parent
3c5559045c
commit
cfb53f1aad
|
@ -216,7 +216,7 @@ class res_partner(osv.osv, format_address):
|
|||
'date': fields.date('Date', select=1),
|
||||
'title': fields.many2one('res.partner.title', 'Title'),
|
||||
'parent_id': fields.many2one('res.partner', 'Related Company'),
|
||||
'child_ids': fields.one2many('res.partner', 'parent_id', 'Contacts'),
|
||||
'child_ids': fields.one2many('res.partner', 'parent_id', 'Contacts', domain=[('active','=',True)]), # force "active_test" domain to bypass _search() override
|
||||
'ref': fields.char('Reference', size=64, select=1),
|
||||
'lang': fields.selection(_lang_get, 'Language',
|
||||
help="If the selected language is loaded in the system, all documents related to this contact will be printed in this language. If not, it will be English."),
|
||||
|
@ -568,6 +568,15 @@ class res_partner(osv.osv, format_address):
|
|||
rec_id = self.create(cr, uid, {self._rec_name: name or email, 'email': email or False}, context=context)
|
||||
return self.name_get(cr, uid, [rec_id], context)[0]
|
||||
|
||||
def _search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False, access_rights_uid=None):
|
||||
""" Override search() to always show inactive children when searching via ``child_of`` operator. The ORM will
|
||||
always call search() with a simple domain of the form [('parent_id', 'in', [ids])]. """
|
||||
# a special ``domain`` is set on the ``child_ids`` o2m to bypass this logic, as it uses similar domain expressions
|
||||
if len(args) == 1 and len(args[0]) == 3 and args[0][:2] == ('parent_id','in'):
|
||||
context = dict(context or {}, active_test=False)
|
||||
return super(res_partner, self)._search(cr, user, args, offset=offset, limit=limit, order=order, context=context,
|
||||
count=count, access_rights_uid=access_rights_uid)
|
||||
|
||||
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
|
||||
if not args:
|
||||
args = []
|
||||
|
|
Loading…
Reference in New Issue