Browse Source

[ADD] support more search operands when search for relations

pull/103/head
Holger Brunn 10 years ago
committed by Sandy Carter
parent
commit
cf547c5951
  1. 6
      partner_relations/i18n/nl.po
  2. 36
      partner_relations/model/res_partner.py

6
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." msgid "The starting date cannot be after the ending date."
msgstr "De begindatum mag niet na de einddatum liggen." 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 #. module: partner_relations
#: code:addons/partner_relations/model/res_partner_relation.py:260 #: code:addons/partner_relations/model/res_partner_relation.py:260
#, python-format #, python-format

36
partner_relations/model/res_partner.py

@ -21,8 +21,9 @@
############################################################################## ##############################################################################
import time import time
from openerp.osv import orm, fields 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 import DEFAULT_SERVER_DATE_FORMAT
from openerp.tools.translate import _
class ResPartner(orm.Model): class ResPartner(orm.Model):
@ -78,18 +79,39 @@ class ResPartner(orm.Model):
result = [] result = []
for arg in args: for arg in args:
if isinstance(arg, tuple) and arg[0] == name: 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([
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.type_id', '=', type_id),
('relation_all_ids.record_type', '=', ('relation_all_ids.record_type', '=',
'b' if is_inverse else 'a') 'b' if is_inverse else 'a')
],
]) ])
return result return result

Loading…
Cancel
Save