diff --git a/openerp/addons/base/base_data.xml b/openerp/addons/base/base_data.xml
index c5f2a4e4344..3d7e1d0f08c 100644
--- a/openerp/addons/base/base_data.xml
+++ b/openerp/addons/base/base_data.xml
@@ -85,6 +85,7 @@
Australia
au
+
Aruba
@@ -109,6 +110,7 @@
Belgium
be
+
Burkina Faso
@@ -145,6 +147,7 @@
Brazil
br
+
Bahamas
@@ -173,6 +176,7 @@
Canada
ca
+
Cocos (Keeling) Islands
@@ -254,6 +258,7 @@
Germany
de
+
Djibouti
@@ -298,6 +303,7 @@
Spain
es
+
Ethiopia
@@ -326,6 +332,7 @@
France
fr
+
Gabon
@@ -434,6 +441,7 @@
India
in
+
British Indian Ocean Territory
@@ -917,6 +925,7 @@
United Kingdom
+
gb
@@ -926,6 +935,7 @@
United States
us
+
Uruguay
diff --git a/openerp/addons/base/res/res_country.py b/openerp/addons/base/res/res_country.py
index 99e12a96f78..3897065da73 100644
--- a/openerp/addons/base/res/res_country.py
+++ b/openerp/addons/base/res/res_country.py
@@ -31,6 +31,13 @@ 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', help="""You can state here the usual format to use for the \
+addresses belonging to this country.\n\nYou can use the python-style string patern with all the field of the address \
+(for example, use '%(street)s' to display the field 'street') plus
+ \n%(state_name)s: the name of the state
+ \n%(state_code)s: the code of the state
+ \n%(country_name)s: the name of the country
+ \n%(country_code)s: the code of the country"""),
}
_sql_constraints = [
('name_uniq', 'unique (name)',
@@ -38,6 +45,9 @@ class Country(osv.osv):
('code_uniq', 'unique (code)',
'The code of the country must be unique !')
]
+ _defaults = {
+ 'address_format': "%(street)s\n%(street2)s\n%(city)s,%(state_code)s %(zip)s",
+ }
def name_search(self, cr, user, name='', args=None, operator='ilike',
context=None, limit=100):
diff --git a/openerp/addons/base/res/res_country_view.xml b/openerp/addons/base/res/res_country_view.xml
index 36b3c6f875f..5c2464ae6f8 100644
--- a/openerp/addons/base/res/res_country_view.xml
+++ b/openerp/addons/base/res/res_country_view.xml
@@ -26,6 +26,7 @@
diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py
index 3f0edb5821f..32b5e08d7b6 100644
--- a/openerp/addons/base/res/res_partner.py
+++ b/openerp/addons/base/res/res_partner.py
@@ -356,6 +356,32 @@ 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, 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_address()
class res_partner_category(osv.osv):
diff --git a/openerp/report/report_sxw.py b/openerp/report/report_sxw.py
index 379d8b5cca9..9b317bb0954 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: