~serpent-consulting-services/openerp-usa/shipping_api_6-1

« back to all changes in this revision

Viewing changes to partner_address_zipsearch_us/partner_address_zip.py

  • Committer: npgllc
  • Date: 2012-08-02 17:13:27 UTC
  • Revision ID: npgllc-20120802171327-2xgyyjjb5d1kx26y
Removed all the 6.0 compatible modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#
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>)
7
 
#
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.
12
 
#
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.
17
 
#
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/>
20
 
#
21
 
##############################################################################
22
 
 
23
 
from osv import fields,osv
24
 
from tools.translate import _
25
 
 
26
 
class res_partner_address(osv.osv):
27
 
    '''
28
 
        New localtion fields and zip field as a many2one
29
 
    '''
30
 
    _description ='Partner Addresses'
31
 
    _inherit='res.partner.address'
32
 
    
33
 
    _columns = {
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),
38
 
        }
39
 
 
40
 
    def on_change_zip(self,cr,uid,id,zip, context={}):
41
 
        '''
42
 
            location details from new zip field (many2one)
43
 
        '''
44
 
        company_obj = self.pool.get('res.users').browse(cr, uid, uid,context=context).company_id
45
 
        if not company_obj.lzipmatch:
46
 
            return {'value': {}}
47
 
        if not zip:
48
 
            return {'value': {'zip' : ''}}
49
 
 
50
 
        zip = self.pool.get('address.zip').browse(cr, uid, zip, context=context)
51
 
        vals = {
52
 
            'longitude': zip.longitude,
53
 
            'latitude': zip.latitude,
54
 
            'city': zip.city,
55
 
            'state_id': zip.state_id.id,
56
 
            'country_id': zip.state_id.country_id.id,
57
 
            'zip': zip.zipcode,
58
 
            }
59
 
        return {'value': vals}
60
 
 
61
 
    def create(self, cr, uid, vals, context=None):
62
 
        if 'zip' in vals:
63
 
            zipcode = vals['zip']
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
66
 
            if zip_id:
67
 
                if not 'zip_id' in vals:
68
 
                    zip = self.pool.get('address.zip').browse(cr, uid, zip_id, context=context)
69
 
                    vals.update({
70
 
                        'longitude': zip.longitude,
71
 
                        'latitude': zip.latitude,
72
 
                        'city': zip.city,
73
 
                        'state_id': zip.state_id.id,
74
 
                        'country_id': zip.state_id.country_id.id,
75
 
                        'zip_id': zip_id
76
 
                        })
77
 
                    return super(res_partner_address, self).create(cr, uid, vals, context)
78
 
        return super(res_partner_address, self).create(cr, uid, vals, context)
79
 
    
80
 
res_partner_address()
81
 
 
82
 
 
83
 
 
84
 
    # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: