~camptocamp/c2c-rd-addons/8.0a

« back to all changes in this revision

Viewing changes to c2c_partner_address_label/partner.py

  • Committer: ferdinand
  • Date: 2011-04-30 20:34:01 UTC
  • Revision ID: office@chricar.at-20110430203401-eqfv4au4tv3faj93
[ADD] initial

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) 2004-2010 Tiny SPRL (<http://tiny.be>).
 
6
#    Copyright (C) 2010-2010 Camptocamp Austria (<http://www.camptocamp.at>)
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU Affero General Public License as
 
10
#    published by the Free Software Foundation, either version 3 of the
 
11
#    License, or (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 Affero General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU Affero 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
import tools
 
25
import pooler
 
26
from tools.translate import _
 
27
 
 
28
#----------------------------------------------------------
 
29
#  Country
 
30
#----------------------------------------------------------
 
31
 
 
32
class Country(osv.osv):
 
33
    _inherit = 'res.country'
 
34
    _columns = {
 
35
        'zip_position' : fields.selection([('before','Before'),('after','After'),('below','Below')], string="Zip Position", help="Zip position relative to city name"),
 
36
    }
 
37
 
 
38
    _defaults = {
 
39
        'zip_position': lambda *a: 'before',
 
40
    }
 
41
 
 
42
    def init(self, cr):
 
43
        # set reasonable values 
 
44
        cr.execute("""update res_country
 
45
                         set zip_position = 'after'
 
46
                       where code in ('US')
 
47
                         and zip_position is null""")
 
48
        cr.execute("""update res_country
 
49
                         set zip_position = 'below'
 
50
                       where code in ('GB')
 
51
                         and zip_position is null""")
 
52
Country()
 
53
 
 
54
#----------------------------------------------------------
 
55
#  Company
 
56
#----------------------------------------------------------
 
57
 
 
58
class res_company(osv.osv):
 
59
    _inherit = 'res.company'
 
60
    _columns = {
 
61
        'address_label_position' : fields.selection([('left','Left'),('rigth','Right')], string="Address Window Position", help="Position of address window on standard company enevlops. Many reports do not use this yet"),
 
62
    }
 
63
    _defaults = {
 
64
        'address_label_position': lambda *a: 'right',
 
65
    }
 
66
 
 
67
res_company()
 
68
 
 
69
#----------------------------------------------------------
 
70
#  Address
 
71
#----------------------------------------------------------
 
72
class res_partner_address(osv.osv):
 
73
    _inherit = 'res.partner.address'
 
74
 
 
75
    def _address_label(self, cr, uid, ids, name, arg, context=None):
 
76
        res = {}
 
77
        lf ='\x0A'
 
78
#        lf ='\x0D\x0A'
 
79
        for a in self.browse(cr, uid, ids, context=context):
 
80
             l = a.partner_id.name or ''
 
81
             if a.partner_id.title:
 
82
                  l = l + ' ' + a.partner_id.title.name
 
83
             t = ''
 
84
             if a.title:
 
85
                  t = a.title.name + ' ' or ''
 
86
             if a.name:
 
87
                  t = t + a.name
 
88
             if t:
 
89
                  l = l + lf + t
 
90
             if a.street:
 
91
                  l = l + lf + a.street
 
92
             if a.street2:
 
93
                  l = l + lf + a.street2
 
94
             z = ''
 
95
             if a.city:
 
96
                  z = a.city
 
97
             if a.zip:
 
98
                  zip_position='before'
 
99
                  if a.country_id.zip_position:
 
100
                      zip_position = a.country_id.zip_position
 
101
                  if zip_position == 'before':
 
102
                      z = a.zip + ' ' + z
 
103
                  if zip_position == 'after':
 
104
                      if a.state_id.code:
 
105
                          z = z + ', ' + a.state_id.code +', '+ a.zip
 
106
                      else:
 
107
                          z = z + ', ' + a.zip
 
108
                  if zip_position == 'below':
 
109
                      z = z + lf + a.zip
 
110
             if z:
 
111
                  l = l +lf + z
 
112
             if a.state_id:
 
113
                  l = l + lf + a.state_id.name
 
114
             if a.country_id:
 
115
                  l = l + lf + a.country_id.name
 
116
             res[a.id] = l
 
117
        return res
 
118
 
 
119
 
 
120
    _columns = {
 
121
        'address_label': fields.function(_address_label, type='text', method = True, string="Address Label"),
 
122
    }
 
123
    
 
124
res_partner_address()