Negate the origin expression of Many2Many with 'not where' operator
issue11425 review403401002
This commit is contained in:
1 parent
522ecac031
commit
ef181c33dd
3 files changed
+34
-2
No files matched your search
@@ -460,7 +460,7 @@ class Many2Many(Field):
|
||||
relation_domain.append(
|
||||
(self.origin, 'like', Model.__name__ + ',%'))
|
||||
else:
|
||||
relation_domain = [self.target, operator, value]
|
||||
relation_domain = [self.target, 'where', value]
|
||||
rule_domain = Rule.domain_get(Relation.__name__, mode='read')
|
||||
if rule_domain:
|
||||
relation_domain = [relation_domain, rule_domain]
|
||||
@@ -477,7 +477,9 @@ class Many2Many(Field):
|
||||
query_table = convert_from(None, relation_tables)
|
||||
query = query_table.select(origin, where=expression)
|
||||
expression = table.id.in_(query)
|
||||
if operator.startswith('!') or operator.startswith('not '):
|
||||
if operator == 'not where':
|
||||
expression = ~expression
|
||||
elif operator.startswith('!') or operator.startswith('not '):
|
||||
expression |= ~table.id.in_(relation.select(origin))
|
||||
return expression
|
||||
|
||||
|
||||
@@ -243,6 +243,21 @@ class CommonTestCaseMixin:
|
||||
|
||||
self.assertListEqual(many2manys, [])
|
||||
|
||||
@with_transaction()
|
||||
def test_search_not_where_others(self):
|
||||
"Test search many2many not where with others"
|
||||
Many2Many = self.Many2Many()
|
||||
many2many, = Many2Many.create([{
|
||||
'targets': [('create', [
|
||||
{'name': "Target"}, {'name': "Foo"}])],
|
||||
}])
|
||||
|
||||
many2manys = Many2Many.search([
|
||||
('targets', 'not where', [('name', '=', "Target")]),
|
||||
])
|
||||
|
||||
self.assertListEqual(many2manys, [])
|
||||
|
||||
@with_transaction()
|
||||
def test_write_write(self):
|
||||
"Test write many2many write"
|
||||
|
||||
@@ -305,6 +305,21 @@ class CommonTestCaseMixin:
|
||||
|
||||
self.assertListEqual(one2manys, [])
|
||||
|
||||
@with_transaction()
|
||||
def test_search_not_where_others(self):
|
||||
"Test search one2many not where with others"
|
||||
One2Many = self.One2Many()
|
||||
one2many, = One2Many.create([{
|
||||
'targets': [('create', [
|
||||
{'name': "Target"}, {'name': "Foo"}])],
|
||||
}])
|
||||
|
||||
one2manys = One2Many.search([
|
||||
('targets', 'not where', [('name', '=', "Target")]),
|
||||
])
|
||||
|
||||
self.assertListEqual(one2manys, [])
|
||||
|
||||
@with_transaction()
|
||||
def test_write_write(self):
|
||||
"Test write one2many write"
|
||||
|
||||
Reference in new issue
Block a user