-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpartner_relation.py
executable file
·71 lines (63 loc) · 2.82 KB
/
partner_relation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import fields,osv
class res_partner_relation(osv.osv):
_description='Partner Relation'
_name = "res.partner.relation"
_columns = {
'name': fields.selection( [ ('default','Default'),('invoice','Invoice'), ('delivery','Delivery'), ('contact','Contact'), ('other','Other') ],'Relation Type', required=True),
'partner_id': fields.many2one('res.partner', 'Main Partner', required=True, ondelete='cascade'),
'relation_id': fields.many2one('res.partner', 'Relation Partner', required=True, ondelete='cascade')
}
_defaults = {
'name' : lambda *a: 'invoice',
}
res_partner_relation()
class res_partner(osv.osv):
_inherit = "res.partner"
_columns = {
'relation_ids': fields.one2many('res.partner.relation', 'partner_id', 'Relations')
}
def _is_related_to(self, cr, uid, ids, toid):
related=[]
for id in ids:
cr.execute("select id from res_partner_relation where (partner_id=%s and relation_id=%s) or (partner_id=%s and relation_id=%s)" % (id,toid,toid,id))
res=cr.fetchone()
if res and len(res):
related.append(True)
else:
related.append(False)
return related
def address_get(self, cr, uid, ids, adr_pref=['default']):
todo = []
result = {}
cr.execute('select name,relation_id from res_partner_relation where partner_id in ('+','.join(map(str,ids))+')')
adrs = dict(cr.fetchall())
for adr in adr_pref:
if adr in adrs:
adr_prov = super(res_partner, self).address_get(cr, uid, [adrs[adr]], [adr]).values()[0]
result[adr] = adr_prov
else:
todo.append(adr)
if len(todo):
result.update(super(res_partner, self).address_get(cr, uid, ids, todo))
return result
res_partner()