From cfcc37bca50baf43843ac938ea26cf23d7a30b25 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Thu, 26 Jan 2017 08:34:41 +0100 Subject: [PATCH] [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 --- openerp/addons/test_inherit/tests/test_inherit.py | 6 ++++++ openerp/osv/expression.py | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/openerp/addons/test_inherit/tests/test_inherit.py b/openerp/addons/test_inherit/tests/test_inherit.py index f6057817ee4..8e12b0b7e08 100644 --- a/openerp/addons/test_inherit/tests/test_inherit.py +++ b/openerp/addons/test_inherit/tests/test_inherit.py @@ -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) diff --git a/openerp/osv/expression.py b/openerp/osv/expression.py index f29fc8f7084..2be571e538c 100644 --- a/openerp/osv/expression.py +++ b/openerp/osv/expression.py @@ -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)