From fa64c13138543aa9bfcc61d9579b0cb3de715793 Mon Sep 17 00:00:00 2001 From: "Bhumika (OpenERP)" Date: Mon, 27 Feb 2012 15:35:30 +0530 Subject: [PATCH] [IMP]base/res: Move display_address method in res.partner bzr revid: sbh@tinyerp.com-20120227100530-8xg61062982kyf97 --- openerp/addons/base/res/res_partner.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py index 70ac3cf9e9f..3fb32e47038 100644 --- a/openerp/addons/base/res/res_partner.py +++ b/openerp/addons/base/res/res_partner.py @@ -331,6 +331,32 @@ class res_partner(osv.osv): model_data.search(cr, uid, [('module','=','base'), ('name','=','main_partner')])[0], ).res_id + + def _display_address(self, cr, uid, address, context=None): + ''' + The purpose of this function is to build and return an address formatted accordingly to the + standards of the country where it belongs. + + :param address: browse record of the res.partner.address to format + :returns: the address formatted in a display that fit its country habits (or the default ones + if not country is specified) + :rtype: string + ''' + # get the address format + address_format = address.country_id and address.country_id.address_format or \ + '%(street)s\n%(street2)s\n%(city)s,%(state_code)s %(zip)s' + # get the information that will be injected into the display format + args = { + 'state_code': address.state_id and address.state_id.code or '', + 'state_name': address.state_id and address.state_id.name or '', + 'country_code': address.country_id and address.country_id.code or '', + 'country_name': address.country_id and address.country_id.name or '', + } + address_field = ['title', 'street', 'street2', 'zip', 'city'] + for field in address_field : + args[field] = getattr(address, field) or '' + + return address_format % args res_partner()