1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
6
# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
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/>
21
##############################################################################
23
from osv import fields,osv
24
from tools.translate import _
26
class res_partner_address(osv.osv):
28
New localtion fields and zip field as a many2one
30
_description ='Partner Addresses'
31
_inherit='res.partner.address'
34
'longitude':fields.char('Longitude', size=64,),
35
'latitude':fields.char('Latitude', size=64,),
36
'zip_id':fields.many2one("address.zip", "Zip"),
37
'zip': fields.char('ZIP', change_default=True, size=24),
40
def on_change_zip(self,cr,uid,id,zip, context={}):
42
location details from new zip field (many2one)
44
company_obj = self.pool.get('res.users').browse(cr, uid, uid,context=context).company_id
45
if not company_obj.lzipmatch:
48
return {'value': {'zip' : ''}}
50
zip = self.pool.get('address.zip').browse(cr, uid, zip, context=context)
52
'longitude': zip.longitude,
53
'latitude': zip.latitude,
55
'state_id': zip.state_id.id,
56
'country_id': zip.state_id.country_id.id,
59
return {'value': vals}
61
def create(self, cr, uid, vals, context=None):
64
zip_ids = self.pool.get('address.zip').search(cr, uid, [('zipcode', '=', zipcode)], context=context)
65
zip_id = zip_ids and zip_ids[0] or False
67
if not 'zip_id' in vals:
68
zip = self.pool.get('address.zip').browse(cr, uid, zip_id, context=context)
70
'longitude': zip.longitude,
71
'latitude': zip.latitude,
73
'state_id': zip.state_id.id,
74
'country_id': zip.state_id.country_id.id,
77
return super(res_partner_address, self).create(cr, uid, vals, context)
78
return super(res_partner_address, self).create(cr, uid, vals, context)
84
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: