[IMP] base: contry specific address format cleanup and improvements

bzr revid: qdp-launchpad@openerp.com-20111201144055-htokze3jly7ent02
This commit is contained in:
Quentin (OpenERP) 2011-12-01 15:40:55 +01:00
parent f3a9c71a68
commit b2678acf99
4 changed files with 29 additions and 21 deletions

View File

@ -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)',

View File

@ -26,9 +26,7 @@
<form string="Country">
<field name="name" select="1"/>
<field name="code" select="1"/>
<field name="address_format" nolabel="1" colspan="4"/>
<separator colspan="4" string="Note"/>
<label align="0.0" colspan="4" width="900" string="" />
<field name="address_format" colspan="4" groups="base.group_extended"/>
</form>
</field>
</record>

View File

@ -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()

View File

@ -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: