diff --git a/openerp/addons/base/res/res_country.py b/openerp/addons/base/res/res_country.py index aa98c3995a0..7272c4e34f7 100644 --- a/openerp/addons/base/res/res_country.py +++ b/openerp/addons/base/res/res_country.py @@ -31,7 +31,7 @@ class Country(osv.osv): 'code': fields.char('Country Code', size=2, help='The ISO country code in two chars.\n' 'You can use this field for quick search.', required=True), - 'address_format': fields.text('Address Format') + 'address_format': fields.text('Address Format'), } _sql_constraints = [ ('name_uniq', 'unique (name)', diff --git a/openerp/addons/base/res/res_country_view.xml b/openerp/addons/base/res/res_country_view.xml index af2a72a5b40..5c2464ae6f8 100644 --- a/openerp/addons/base/res/res_country_view.xml +++ b/openerp/addons/base/res/res_country_view.xml @@ -26,9 +26,7 @@
diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py index b783e507152..fb04c10bf5a 100644 --- a/openerp/addons/base/res/res_partner.py +++ b/openerp/addons/base/res/res_partner.py @@ -356,24 +356,30 @@ class res_partner_address(osv.osv): def get_city(self, cr, uid, id): return self.browse(cr, uid, id).city - def display_address(self, cr, uid, context, address_obj): #,field_list=[]): -# if isinstance(address_id, list): -# address_id = address_id[0] -# address_obj = self.browse(cr, uid, address_id) - - address_field = ['title','street','street2','zip','city'] - args = {} - for field in address_field : -# args[field] = field_list and field in field_list and getattr(address_obj,field) or getattr(address_obj,field) or '' - args[field] = getattr(address_obj,field) and getattr(address_obj,field) or '' - #TODO - args['state_code'] = address_obj.state_id and address_obj.state_id.code or '' - args['state_name'] = address_obj.state_id and address_obj.state_id.name or '' - args['country_code'] = address_obj.country_id and address_obj.country_id.code or '' - args['country_name'] = address_obj.country_id and address_obj.country_id.name or '' - # If no country is defined - just in case - address_format = address_obj.country_id and address_obj.country_id.address_format or \ + def display_address(self, cr, uid, address): + ''' + 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_address() diff --git a/openerp/report/report_sxw.py b/openerp/report/report_sxw.py index 379d8b5cca9..050c53b7456 100644 --- a/openerp/report/report_sxw.py +++ b/openerp/report/report_sxw.py @@ -170,6 +170,7 @@ class rml_parse(object): 'setHtmlImage' : self.set_html_image, 'strip_name' : self._strip_name, 'time' : time, + 'display_address': self.display_address, # more context members are setup in setCompany() below: # - company_id # - logo @@ -313,6 +314,9 @@ class rml_parse(object): res='%s %s'%(currency_obj.symbol, res) return res + def display_address(self, address_browse_record): + return self.pool.get('res.partner.address').display_address(self.cr, self.uid, address_browse_record) + def repeatIn(self, lst, name,nodes_parent=False): ret_lst = [] for id in lst: