~romaindeheele/openobject-addons/extra-trunk

« back to all changes in this revision

Viewing changes to l10n_pe_toponyms/partner.py

  • Committer: Yury Tello
  • Date: 2012-06-21 19:40:45 UTC
  • Revision ID: ytello@cubicerp.com-20120621194045-9tdebiglll7s3g2i
[ADD] delivery_routes and l10n_pe_toponyms

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2011 Cubic ERP - Teradata SAC (<http://cubicerp.com>).
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as
 
9
#    published by the Free Software Foundation, either version 3 of the
 
10
#    License, or (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
from osv import fields, osv
 
23
 
 
24
class res_partner_address(osv.osv):
 
25
    _inherit = 'res.partner.address'
 
26
    _name = 'res.partner.address'
 
27
 
 
28
    _columns = {
 
29
        'province_id': fields.many2one("res.country.province", 'Province', domain="[('state_id','=',state_id)]"),
 
30
        'district_id': fields.many2one("res.country.district", 'District', domain="[('province_id','=',province_id)]"),
 
31
        'address_ref' : fields.char('Address Reference', size=256, help="One or more points used as reference to locate the address"),
 
32
    }
 
33
 
 
34
    def name_get(self, cr, user, ids, context=None):
 
35
        if context is None:
 
36
            context = {}
 
37
        if not len(ids):
 
38
            return []
 
39
        res = []
 
40
        for r in self.read(cr, user, ids, ['name','zip','country_id', 'city','partner_id', 'street','state_id','province_id','district_id','address_ref','street2']):
 
41
            if context.get('contact_display', 'contact')=='partner' and r['partner_id']:
 
42
                res.append((r['id'], r['partner_id'][1]))
 
43
            else:
 
44
                # make a comma-separated list with the following non-empty elements
 
45
                elems = [r['name'], r['street'], r['street2'], r['district_id'] and r['district_id'][1], r['province_id'] and r['province_id'][1], r['address_ref'] ]
 
46
                addr = ', '.join(filter(bool, elems))
 
47
                if (context.get('contact_display', 'contact')=='partner_address') and r['partner_id']:
 
48
                    res.append((r['id'], "%s: %s" % (r['partner_id'][1], addr or '/')))
 
49
                else:
 
50
                    res.append((r['id'], addr or '/'))
 
51
        return res
 
52
 
 
53
res_partner_address()
 
54