~vauxoo/openerp-venezuela-localization/truiz-yml-1068950

« back to all changes in this revision

Viewing changes to l10n_ve_topology/module/res_partner.py

  • Committer: Miguel Delgado
  • Author(s): VAUXOO
  • Date: 2012-10-21 21:34:08 UTC
  • mfrom: (753.1.1 miguel_l10n_ve_topology)
  • Revision ID: miguel.delgado07@gmail.com-20121021213408-5bzaf6y5eeq7f6o9
 
[MERGE] Improved the module structure
> [ADD] was added to module, the data of most sectors in the country 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- encoding: utf-8 -*-
 
3
###########################################################################
 
4
#    Module Writen to OpenERP, Open Source Management Solution
 
5
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
 
6
#    All Rights Reserved
 
7
###############Credits######################################################
 
8
#    Coded by: Vauxoo C.A.           
 
9
#    Planified by: Nhomar Hernandez
 
10
#    Audited by: Vauxoo C.A.
 
11
#############################################################################
 
12
#    This program is free software: you can redistribute it and/or modify
 
13
#    it under the terms of the GNU Affero General Public License as published by
 
14
#    the Free Software Foundation, either version 3 of the License, or
 
15
#    (at your option) any later version.
 
16
#
 
17
#    This program is distributed in the hope that it will be useful,
 
18
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
#    GNU Affero General Public License for more details.
 
21
#
 
22
#    You should have received a copy of the GNU Affero General Public License
 
23
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
24
################################################################################
 
25
 
 
26
from osv import osv
 
27
from osv import fields
 
28
from tools.translate import _
 
29
 
 
30
class res_partner_address(osv.osv):
 
31
    
 
32
    def _get_city_name(self, cr, uid, ids, field_name, arg, context=None):
 
33
        if context is None:
 
34
            context={}
 
35
        res={}
 
36
        for obj in self.browse(cr,uid,ids):
 
37
            if obj.city_id:
 
38
                res[obj.id] = obj.city_id.name
 
39
            else:
 
40
                res[obj.id] = ''
 
41
        return res
 
42
 
 
43
    _inherit='res.partner.address'
 
44
    _columns = {
 
45
        'municipality_id':fields.many2one('res.municipality','Municipality', help="In this field enter the name of the municipality which is associated with the parish", domain= "[('state_id','=',state_id)]"),
 
46
        'parish_id':fields.many2one('res.parish','Parish',help="In this field you enter the parish to which the sector is associated",domain= "[('municipalities_id','=',municipality_id)]" ),
 
47
        'sector_id':fields.many2one('res.sector',string='Sector',required=False,help="in this field select the Sector associated with this Municipality",domain= "[('state_id','=',state_id)]"),
 
48
        'city_id':fields.many2one('res.city',string='City',domain= "[('state_id','=',state_id)]",help="in this field select the city associated with this State"),
 
49
        'city':fields.function(_get_city_name, method=True, type='char', string='City', size=256, domain= "[('state_id','=',state_id)]",store=True),
 
50
    }
 
51
 
 
52
    def name_get(self, cr, user, ids, context=None):
 
53
        if context is None:
 
54
            context = {}
 
55
        if not len(ids):
 
56
            return []
 
57
        res = super(res_partner_address,self).name_get(cr, user, ids, context=context)
 
58
        res = []
 
59
        for r in self.read(cr, user, ids, ['name','country_id','state_id','city','municipality_id','parish_id','sector_id','street','street2','partner_id']):
 
60
            if context.get('contact_display', 'contact')=='partner' and r['partner_id']:
 
61
                res.append((r['id'], r['partner_id'][1]))
 
62
            else:
 
63
                # make a comma-separated list with the following non-empty elements
 
64
                elems = [r['name'], r['country_id'] and r['country_id'][1],r['state_id'] and r['state_id'][1], r['city'], r['municipality_id'] and r['municipality_id'][1],r['parish_id'] and r['parish_id'][1],r['sector_id'] and r['sector_id'][1], r['street'], r['street2'],r['partner_id'] and r['partner_id'][1]]
 
65
                addr = ', '.join(filter(bool, elems))
 
66
                if (context.get('contact_display', 'contact')=='partner_address') and r['partner_id']:
 
67
                    res.append((r['id'], "%s: %s" % (r['partner_id'][1], addr or '/')))
 
68
                else:
 
69
                    res.append((r['id'], addr or '/'))
 
70
        return res
 
71
 
 
72
res_partner_address()