~therp-nl/therp-addons/7.0_lp1219418

« back to all changes in this revision

Viewing changes to trp_report_address/res_partner_address.py

  • Committer: Ronald Portier
  • Date: 2014-03-28 13:12:43 UTC
  • mfrom: (81.5.17 therp-addons-7.0)
  • Revision ID: ronald@therp.nl-20140328131243-d06yj7u2o9fhshrw
[MERGE] Merge upstream changes
    - resolve text conflict in fetchmail_invoice.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
from osv import osv, fields
3
 
 
4
 
class res_partner_address(osv.osv):
5
 
    _inherit = 'res.partner.address'
6
 
 
7
 
    def _display_address_custom(self, cr, uid, address, company, context=None):
8
 
        '''
9
 
        This method is almost identical to the one in base/res/res_partner.py,
10
 
        but it does not print the country if this is equal to the company partner's
11
 
        country, unless we print the company partner's own address.
12
 
 
13
 
        Note that this method has a different signature than the original one,
14
 
        as it passes the company browse record.
15
 
 
16
 
        :param address: browse record of the res.partner.address to format
17
 
        :param company: browse record of the res.company
18
 
        :returns: the address formatted in a display that fit its country habits (or the default ones
19
 
            if not country is specified)
20
 
        :rtype: string
21
 
        '''
22
 
        # get the address format
23
 
        address_format = address.country_id and address.country_id.address_format or \
24
 
                                         '%(street)s\n%(street2)s\n%(city)s,%(state_code)s %(zip)s' 
25
 
        # get the information that will be injected into the display format
26
 
        args = {
27
 
            'state_code': address.state_id and address.state_id.code or '',
28
 
            'state_name': address.state_id and address.state_id.name or '',
29
 
            'country_code': address.country_id and address.country_id.code or '',
30
 
            'country_name': address.country_id and address.country_id.name or '',
31
 
        }
32
 
 
33
 
 
34
 
        # custom changes here
35
 
        if (address.country_id and company and company.partner_id.country and 
36
 
            company.partner_id.country.id ==  address.country_id.id and
37
 
            not (address.partner_id and 
38
 
                 address.partner_id.id == company.partner_id.id)
39
 
            ):
40
 
            args['country_name'] = ''
41
 
        # end of custom changes
42
 
 
43
 
        address_field = ['title', 'street', 'street2', 'zip', 'city']
44
 
        for field in address_field :
45
 
            args[field] = getattr(address, field) or ''
46
 
 
47
 
        return address_format % args
48
 
 
49
 
res_partner_address()