[FIX] expression: leaf in o2m with m2o inherits'd field

The reverse field of a one2many could be originating from an
inherits'd field, this was solved in some instance with f5e5bbda.

The issue could still happen in some instances when doing a comparison
of:

- the one2many field to a False value,
- the one2many with a negative operator and an empty set to negate,

With this change, the ORM is used in such a situation.

closes #15234
opw-704962
This commit is contained in:
Nicolas Lempereur 2017-01-26 08:34:41 +01:00
parent 4232a08164
commit cfcc37bca5
2 changed files with 14 additions and 1 deletions

View File

@ -74,6 +74,12 @@ class test_inherits(common.TransactionCase):
self.assertIn(daughter, partner_demo.daughter_ids)
# search the partner from the daughter record
partners = self.env['res.partner'].search([('daughter_ids', 'like', 'not existing daugther')])
self.assertFalse(partners)
partners = self.env['res.partner'].search([('daughter_ids', 'not like', 'not existing daugther')])
self.assertIn(partner_demo, partners)
partners = self.env['res.partner'].search([('daughter_ids', '!=', False)])
self.assertIn(partner_demo, partners)
partners = self.env['res.partner'].search([('daughter_ids', 'in', daughter.ids)])
self.assertIn(partner_demo, partners)

View File

@ -981,7 +981,14 @@ class expression(object):
if call_null:
o2m_op = 'in' if operator in NEGATIVE_TERM_OPERATORS else 'not in'
push(create_substitution_leaf(leaf, ('id', o2m_op, select_distinct_from_where_not_null(cr, column._fields_id, comodel._table)), model))
# determine ids from column._fields_id
if comodel._fields[column._fields_id].store:
ids1 = select_distinct_from_where_not_null(cr, column._fields_id, comodel._table)
else:
ids2 = comodel.search(cr, uid, [(column._fields_id, '!=', False)], context=context)
recs = comodel.browse(cr, SUPERUSER_ID, ids2, {'prefetch_fields': False})
ids1 = recs.mapped(column._fields_id).ids
push(create_substitution_leaf(leaf, ('id', o2m_op, ids1), model))
elif column._type == 'many2many':
rel_table, rel_id1, rel_id2 = column._sql_names(model)