From e538f73d4f4bf06696bd5483ec23de417c37fd8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 11 Jul 2016 18:26:02 +0200 Subject: [PATCH] Improve search_vat_code - Use where clause to ensure to test code and type of the same record - Add party without code for clause that match with None issue5679 review28441002 --- party.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/party.py b/party.py index b7f7502e1b..b0fba1862d 100644 --- a/party.py +++ b/party.py @@ -136,10 +136,24 @@ class Party(ModelSQL, ModelView): @classmethod def search_vat_code(cls, name, clause): - return [ - ('identifiers.code',) + tuple(clause[1:]), - ('identifiers.type', 'in', cls._vat_types()), + _, operator, value = clause + domain = [ + ('identifiers', 'where', [ + ('code', operator, value), + ('type', 'in', cls._vat_types()), + ]), ] + # Add party without vat code + if ((operator == '=' and value is None) + or (operator == 'in' and None in value)): + domain = ['OR', + domain, [ + ('identifiers', 'not where', [ + ('type', 'in', cls._vat_types()), + ]), + ], + ] + return domain def get_full_name(self, name): return self.name