Browse Source

Merge pull request #76 from hbrunn/7.0-partner_relations

[ADD] support more search operators when search for relations
pull/91/head
Pedro M. Baeza 10 years ago
parent
commit
b63c7aaed3
  1. 6
      partner_relations/i18n/nl.po
  2. 6
      partner_relations/i18n/partner_relations.pot
  3. 46
      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."
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

6
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

46
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

Loading…
Cancel
Save