From e1af54b9c60c37e4ea8f00c85ca1b06a40c8c51d Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Wed, 7 Jan 2015 12:52:14 +0100 Subject: [PATCH 1/2] [ADD] support more search operands when search for relations --- partner_relations/i18n/nl.po | 6 ++++ partner_relations/model/res_partner.py | 46 +++++++++++++++++++------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/partner_relations/i18n/nl.po b/partner_relations/i18n/nl.po index 0997a6345..07fcc753f 100644 --- a/partner_relations/i18n/nl.po +++ b/partner_relations/i18n/nl.po @@ -244,6 +244,12 @@ msgstr "De rechterrelatie is niet geldig voor dit type koppeling." msgid "The starting date cannot be after the ending date." msgstr "De begindatum mag niet na de einddatum liggen." +#. module: partner_relations +#: code:addons/partner_relations/model/res_partner_relation.py:260 +#, python-format +msgid "Unsupported search operand \"%s\"" +msgstr "Operator \"%s\" is niet ondersteund" + #. module: partner_relations #: code:addons/partner_relations/model/res_partner_relation.py:260 #, python-format diff --git a/partner_relations/model/res_partner.py b/partner_relations/model/res_partner.py index f265bb452..68b744442 100644 --- a/partner_relations/model/res_partner.py +++ b/partner_relations/model/res_partner.py @@ -21,8 +21,9 @@ ############################################################################## import time from openerp.osv import orm, fields -from openerp.osv.expression import is_leaf +from openerp.osv.expression import is_leaf, OR, FALSE_LEAF from openerp.tools import DEFAULT_SERVER_DATE_FORMAT +from openerp.tools.translate import _ class ResPartner(orm.Model): @@ -78,19 +79,40 @@ class ResPartner(orm.Model): result = [] for arg in args: if isinstance(arg, tuple) and arg[0] == name: - if arg[1] != '=': - continue + if arg[1] not in ['=', 'like', 'not like', 'ilike', + 'not ilike', 'in', 'not in']: + raise orm.except_orm( + _('Error'), + _('Unsupported search operand "%s"') % arg[1]) - type_id, is_inverse = self\ - .pool['res.partner.relation.type.selection']\ - .get_type_from_selection_id(cr, uid, arg[2]) + relation_type_selection_ids = [] + relation_type_selection = self\ + .pool['res.partner.relation.type.selection'] - result.extend([ - '&', - ('relation_all_ids.type_id', '=', type_id), - ('relation_all_ids.record_type', '=', - 'b' if is_inverse else 'a') - ]) + if arg[1] == '=' and isinstance(arg[2], (long, int)): + relation_type_selection_ids.append(arg[2]) + else: + relation_type_selection_ids = relation_type_selection\ + .search(cr, uid, [('name', arg[1], arg[2])], + context=context) + + if not relation_type_selection_ids: + result = OR([result, FALSE_LEAF]) + + for relation_type_selection_id in relation_type_selection_ids: + type_id, is_inverse = relation_type_selection\ + .get_type_from_selection_id( + cr, uid, relation_type_selection_id) + + result = OR([ + result, + [ + '&', + ('relation_all_ids.type_id', '=', type_id), + ('relation_all_ids.record_type', '=', + 'b' if is_inverse else 'a') + ], + ]) return result From 76c13500a204d945477301c0459fa867157f9b86 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Mon, 19 Jan 2015 09:12:31 +0100 Subject: [PATCH 2/2] [ADD] update pot file --- partner_relations/i18n/partner_relations.pot | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/partner_relations/i18n/partner_relations.pot b/partner_relations/i18n/partner_relations.pot index fb9a8249a..df3c5b428 100644 --- a/partner_relations/i18n/partner_relations.pot +++ b/partner_relations/i18n/partner_relations.pot @@ -251,6 +251,12 @@ msgstr "" msgid "The starting date cannot be after the ending date." msgstr "" +#. module: partner_relations +#: code:addons/partner_relations/model/res_partner_relation.py:260 +#, python-format +msgid "Unsupported search operand \"%s\"" +msgstr "" + #. module: partner_relations #: field:res.partner.relation,type_id:0 #: field:res.partner.relation,type_selection_id:0