1
# -*- encoding: utf-8 -*-
1
2
##############################################################################
3
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# $Id: partner.py 1007 2005-07-25 13:18:09Z kayhman $
7
# WARNING: This program as such is intended to be used by professional
8
# programmers who take the whole responsability of assessing all potential
9
# consequences resulting from its eventual inadequacies and bugs
10
# End users who are looking for a ready-to-use solution with commercial
11
# garantees and support are strongly adviced to contract a Free Software
14
# This program is Free Software; you can redistribute it and/or
15
# modify it under the terms of the GNU General Public License
16
# as published by the Free Software Foundation; either version 2
17
# of the License, or (at your option) any later version.
19
# This program is distributed in the hope that it will be useful,
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
# GNU General Public License for more details.
24
# You should have received a copy of the GNU General Public License
25
# along with this program; if not, write to the Free Software
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
28
21
##############################################################################
33
26
class res_partner_relation(osv.osv):
34
_description='The partner object'
35
_name = "res.partner.relation"
37
'name': fields.selection( [ ('default','Default'),('invoice','Invoice'), ('delivery','Delivery'), ('contact','Contact'), ('other','Other') ],'Relation Type', required=True),
38
'partner_id': fields.many2one('res.partner', 'Main Partner', required=True, ondelete='cascade'),
39
'relation_id': fields.many2one('res.partner', 'Relation Partner', required=True, ondelete='cascade')
42
'name' : lambda *a: 'invoice',
27
_description='The partner object'
28
_name = "res.partner.relation"
30
'name': fields.selection( [ ('default','Default'),('invoice','Invoice'), ('delivery','Delivery'), ('contact','Contact'), ('other','Other') ],'Relation Type', required=True),
31
'partner_id': fields.many2one('res.partner', 'Main Partner', required=True, ondelete='cascade'),
32
'relation_id': fields.many2one('res.partner', 'Relation Partner', required=True, ondelete='cascade')
35
'name' : lambda *a: 'invoice',
45
38
res_partner_relation()
48
41
class res_partner(osv.osv):
49
_inherit = "res.partner"
51
'relation_ids': fields.one2many('res.partner.relation', 'partner_id', 'Relations')
54
def _is_related_to(self, cr, uid, ids, toid):
57
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))
65
def address_get(self, cr, uid, ids, adr_pref=['default']):
68
cr.execute('select name,relation_id from res_partner_relation where partner_id in ('+','.join(map(str,ids))+')')
69
adrs = dict(cr.fetchall())
72
adr_prov = super(res_partner, self).address_get(cr, uid, [adrs[adr]], [adr]).values()[0]
73
result[adr] = adr_prov
77
result.update(super(res_partner, self).address_get(cr, uid, ids, todo))
42
_inherit = "res.partner"
44
'relation_ids': fields.one2many('res.partner.relation', 'partner_id', 'Relations')
46
def _is_related_to(self, cr, uid, ids, toid):
49
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))
57
def address_get(self, cr, uid, ids, adr_pref=['default']):
60
cr.execute('select name,relation_id from res_partner_relation where partner_id in ('+','.join(map(str,ids))+')')
61
adrs = dict(cr.fetchall())
64
adr_prov = super(res_partner, self).address_get(cr, uid, [adrs[adr]], [adr]).values()[0]
65
result[adr] = adr_prov
69
result.update(super(res_partner, self).address_get(cr, uid, ids, todo))
83
75
class PartnerAddress(osv.osv):
84
_inherit = 'res.partner.address'
86
def _where_calc(self, cursor, user, args, active_test=True, context=None):
87
partner_obj = self.pool.get('res.partner')
93
if args[i][0] == 'partner_id' and args[i][1] == '=':
94
partner = partner_obj.browse(cursor, user, args[i][2],
96
args[i] = ('partner_id', 'in', [args[i][2]] + [x.relation_id.id \
97
for x in partner.relation_ids])
99
return super(PartnerAddress, self)._where_calc(cursor, user, args,
100
active_test=active_test, context=context)
76
_inherit = 'res.partner.address'
77
def _where_calc(self, cursor, user, args, active_test=True, context=None):
80
partner_obj = self.pool.get('res.partner')
84
if type(args[i])==tuple:
86
if args[i][0] == 'partner_id' and args[i][1] == '=':
87
partner = partner_obj.browse(cursor, user, args[i][2],
89
args[i] = ('partner_id', 'in', [args[i][2]] + [x.relation_id.id \
90
for x in partner.relation_ids])
92
return super(PartnerAddress, self)._where_calc(cursor, user, args,
93
active_test=active_test, context=context)
95
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: