From edab5adf54595db1ef02c35f4e609d2abbc70f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 5 Apr 2015 23:39:57 +0200 Subject: [PATCH] Fix search_rec_name for negative operator In case of negative operator, each subclause must be composed with 'AND'. issue4559 review13111003 --- account.py | 18 +++++++++++++++--- fiscalyear.py | 6 +++++- journal.py | 6 +++++- move.py | 6 +++++- period.py | 6 +++++- tax.py | 6 +++++- 6 files changed, 40 insertions(+), 8 deletions(-) diff --git a/account.py b/account.py index d728447e2d..7f78c69d47 100644 --- a/account.py +++ b/account.py @@ -433,7 +433,11 @@ class AccountTemplate(ModelSQL, ModelView): @classmethod def search_rec_name(cls, name, clause): - return ['OR', + if clause[1].startswith('!') or clause[1].startswith('not '): + bool_op = 'AND' + else: + bool_op = 'OR' + return [bool_op, ('code',) + tuple(clause[1:]), (cls._rec_name,) + tuple(clause[1:]), ] @@ -851,7 +855,11 @@ class Account(ModelSQL, ModelView): @classmethod def search_rec_name(cls, name, clause): - return ['OR', + if clause[1].startswith('!') or clause[1].startswith('not '): + bool_op = 'AND' + else: + bool_op = 'OR' + return [bool_op, ('code',) + tuple(clause[1:]), (cls._rec_name,) + tuple(clause[1:]), ] @@ -1032,7 +1040,11 @@ class AccountDeferral(ModelSQL, ModelView): @classmethod def search_rec_name(cls, name, clause): - return ['OR', + if clause[1].startswith('!') or clause[1].startswith('not '): + bool_op = 'AND' + else: + bool_op = 'OR' + return [bool_op, ('account.rec_name',) + tuple(clause[1:]), ('fiscalyear.rec_name',) + tuple(clause[1:]), ] diff --git a/fiscalyear.py b/fiscalyear.py index 66bad627a9..0eafef845c 100644 --- a/fiscalyear.py +++ b/fiscalyear.py @@ -317,7 +317,11 @@ class FiscalYear(ModelSQL, ModelView): @classmethod def search_rec_name(cls, name, clause): - return ['OR', + if clause[1].startswith('!') or clause[1].startswith('not '): + bool_op = 'AND' + else: + bool_op = 'OR' + return [bool_op, ('code',) + tuple(clause[1:]), (cls._rec_name,) + tuple(clause[1:]), ] diff --git a/journal.py b/journal.py index 42324eb835..39e3a26c07 100644 --- a/journal.py +++ b/journal.py @@ -170,7 +170,11 @@ class Journal(ModelSQL, ModelView): @classmethod def search_rec_name(cls, name, clause): - return ['OR', + if clause[1].startswith('!') or clause[1].startswith('not '): + bool_op = 'AND' + else: + bool_op = 'OR' + return [bool_op, ('code',) + tuple(clause[1:]), (cls._rec_name,) + tuple(clause[1:]), ] diff --git a/move.py b/move.py index 9d677dbaa2..3ad1d2be76 100644 --- a/move.py +++ b/move.py @@ -231,7 +231,11 @@ class Move(ModelSQL, ModelView): @classmethod def search_rec_name(cls, name, clause): - return ['OR', + if clause[1].startswith('!') or clause[1].startswith('not '): + bool_op = 'AND' + else: + bool_op = 'OR' + return [bool_op, ('post_number',) + tuple(clause[1:]), (cls._rec_name,) + tuple(clause[1:]), ] diff --git a/period.py b/period.py index 5df0dbd848..b8cc16f331 100644 --- a/period.py +++ b/period.py @@ -324,7 +324,11 @@ class Period(ModelSQL, ModelView): @classmethod def search_rec_name(cls, name, clause): - return ['OR', + if clause[1].startswith('!') or clause[1].startswith('not '): + bool_op = 'AND' + else: + bool_op = 'OR' + return [bool_op, ('code',) + tuple(clause[1:]), (cls._rec_name,) + tuple(clause[1:]), ] diff --git a/tax.py b/tax.py index b00772069a..38b772a7a0 100644 --- a/tax.py +++ b/tax.py @@ -235,7 +235,11 @@ class TaxCode(ModelSQL, ModelView): @classmethod def search_rec_name(cls, name, clause): - return ['OR', + if clause[1].startswith('!') or clause[1].startswith('not '): + bool_op = 'AND' + else: + bool_op = 'OR' + return [bool_op, ('code',) + tuple(clause[1:]), (cls._rec_name,) + tuple(clause[1:]), ]