[FIX] core: flush() domain returned by search method
Assume field B depends on A, and searching on B is rewritten as a domain that mentions A. If A is modified, and then we search on B, one has to flush A to the database before searching. closes odoo/odoo#57963 X-original-commit: b242b7b1382ee39ebefa58c556931b7dae77f669 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
@@ -170,6 +170,7 @@ class Message(models.Model):
|
||||
if operator not in ('=', '!=', '<', '<=', '>', '>=', 'in', 'not in'):
|
||||
return []
|
||||
# retrieve all the messages that match with a specific SQL query
|
||||
self.flush(['body'])
|
||||
query = """SELECT id FROM "%s" WHERE char_length("body") %s %%s""" % \
|
||||
(self._table, operator)
|
||||
self.env.cr.execute(query, (value,))
|
||||
|
||||
@@ -1047,6 +1047,7 @@ class TestFields(TransactionCaseWithUserDemo):
|
||||
def test_25_related_multi(self):
|
||||
""" test write() on several related fields based on a common computed field. """
|
||||
foo = self.env['test_new_api.foo'].create({'name': 'A', 'value1': 1, 'value2': 2})
|
||||
oof = self.env['test_new_api.foo'].create({'name': 'B', 'value1': 1, 'value2': 2})
|
||||
bar = self.env['test_new_api.bar'].create({'name': 'A'})
|
||||
self.assertEqual(bar.foo, foo)
|
||||
self.assertEqual(bar.value1, 1)
|
||||
@@ -1057,6 +1058,11 @@ class TestFields(TransactionCaseWithUserDemo):
|
||||
self.assertEqual(foo.value1, 3)
|
||||
self.assertEqual(foo.value2, 4)
|
||||
|
||||
# modify 'name', and search on 'foo': this should flush 'name'
|
||||
bar.name = 'B'
|
||||
self.assertEqual(bar.foo, oof)
|
||||
self.assertIn(bar, bar.search([('foo', 'in', oof.ids)]))
|
||||
|
||||
def test_26_inherited(self):
|
||||
""" test inherited fields. """
|
||||
# a bunch of fields are inherited from res_partner
|
||||
|
||||
@@ -707,6 +707,7 @@ class expression(object):
|
||||
right = comodel._search([(path[1], operator, right)], order='id')
|
||||
operator = 'in'
|
||||
domain = field.determine_domain(model, operator, right)
|
||||
model._flush_search(domain, order='id')
|
||||
|
||||
for elem in normalize_domain(domain):
|
||||
push(elem, model, alias, internal=True)
|
||||
|
||||
Reference in New Issue
Block a user