Include records without link with negative search on xxx2many

issue10178
review345981002
This commit is contained in:
Cédric Krier committed 2021-04-25 17:56:39 +02:00
1 parent 1ee46331ef
commit e4015d7bf3
4 files changed
+66 -1

No files matched your search

+4 -1
View File
@@ -453,7 +453,10 @@ class Many2Many(Field):
relation_domain, tables=relation_tables)
query_table = convert_from(None, relation_tables)
query = query_table.select(origin, where=expression)
return table.id.in_(query)
expression = table.id.in_(query)
if operator.startswith('!') or operator.startswith('not '):
expression |= ~table.id.in_(relation.select(origin))
return expression
def definition(self, model, language):
encoder = PYSONEncoder()
+2
View File
@@ -354,6 +354,8 @@ class One2Many(Field):
if operator == 'not where':
expression = ~expression
elif operator.startswith('!') or operator.startswith('not '):
expression |= ~table.id.in_(target.select(origin))
return expression
def definition(self, model, language):
+30
View File
@@ -39,6 +39,21 @@ class CommonTestCaseMixin:
self.assertListEqual(many2manys, [many2many])
@with_transaction()
def test_search_equals_no_link(self):
"Test search many2many equals without link"
Many2Many = self.Many2Many()
many2many, no_link = Many2Many.create([{
'targets': [('create', [{'name': "Target"}])],
}, {
}])
many2manys = Many2Many.search([
('targets', '=', "Target"),
])
self.assertListEqual(many2manys, [many2many])
@with_transaction()
def test_search_non_equals(self):
"Test search many2many non equals"
@@ -85,6 +100,21 @@ class CommonTestCaseMixin:
self.assertListEqual(many2manys, [many2many1])
@with_transaction()
def test_search_non_equals_no_link(self):
"Test search many2many non equals without link"
Many2Many = self.Many2Many()
many2many, no_link = Many2Many.create([{
'targets': [('create', [{'name': "Target"}])],
}, {
}])
many2manys = Many2Many.search([
('targets', '!=', "Target"),
])
self.assertListEqual(many2manys, [no_link])
@with_transaction()
def test_search_in(self):
"Test search many2many in"
+30
View File
@@ -101,6 +101,21 @@ class CommonTestCaseMixin:
self.assertListEqual(one2manys, [one2many])
@with_transaction()
def test_search_equals_no_link(self):
"Test search one2many equals without link"
One2Many = self.One2Many()
one2many, no_link = One2Many.create([{
'targets': [('create', [{'name': "Target"}])],
}, {
}])
one2manys = One2Many.search([
('targets', '=', "Target"),
])
self.assertListEqual(one2manys, [one2many])
@with_transaction()
def test_search_non_equals(self):
"Test search one2many non equals"
@@ -147,6 +162,21 @@ class CommonTestCaseMixin:
self.assertListEqual(one2manys, [one2many1])
@with_transaction()
def test_search_non_equals_no_link(self):
"Test search one2many non equals without link"
One2Many = self.One2Many()
one2many, no_link = One2Many.create([{
'targets': [('create', [{'name': "Target"}])],
}, {
}])
one2manys = One2Many.search([
('targets', '!=', "Target"),
])
self.assertListEqual(one2manys, [no_link])
@with_transaction()
def test_search_in(self):
"Test search one2many in"