From 6da1004cf514289103af8fb8a51790aa4d3388c1 Mon Sep 17 00:00:00 2001 From: "Dhara (OpenERP)" <> Date: Thu, 22 Sep 2011 15:08:23 -0700 Subject: [PATCH 1/4] [NEW] new address_format field for country bzr revid: dhara_openerp-20110922220823-qaghdh4urgjdtea0 --- openerp/addons/base/base_data.xml | 10 ++++++++++ openerp/addons/base/res/res_country.py | 4 ++++ openerp/addons/base/res/res_country_view.xml | 3 +++ openerp/addons/base/res/res_partner.py | 20 ++++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/openerp/addons/base/base_data.xml b/openerp/addons/base/base_data.xml index 00fb83a0796..0da83dbb1d2 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..aa98c3995a0 100644 --- a/openerp/addons/base/res/res_country.py +++ b/openerp/addons/base/res/res_country.py @@ -31,6 +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') } _sql_constraints = [ ('name_uniq', 'unique (name)', @@ -38,6 +39,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..af2a72a5b40 100644 --- a/openerp/addons/base/res/res_country_view.xml +++ b/openerp/addons/base/res/res_country_view.xml @@ -26,6 +26,9 @@
+ + +
diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py index 4b8f1279787..e4c0db75e8a 100644 --- a/openerp/addons/base/res/res_partner.py +++ b/openerp/addons/base/res/res_partner.py @@ -345,6 +345,26 @@ 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 \ + '%(street)s\n%(street2)s\n%(city)s,%(state_code)s %(zip)s' + return address_format % args + res_partner_address() class res_partner_category(osv.osv): From b2678acf993775e4a9a2c3d5741448468a8f6875 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 1 Dec 2011 15:40:55 +0100 Subject: [PATCH 2/4] [IMP] base: contry specific address format cleanup and improvements bzr revid: qdp-launchpad@openerp.com-20111201144055-htokze3jly7ent02 --- openerp/addons/base/res/res_country.py | 2 +- openerp/addons/base/res/res_country_view.xml | 4 +- openerp/addons/base/res/res_partner.py | 40 +++++++++++--------- openerp/report/report_sxw.py | 4 ++ 4 files changed, 29 insertions(+), 21 deletions(-) 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: From dd436b075bc9378d89163564b09107807e08c761 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 1 Dec 2011 15:50:52 +0100 Subject: [PATCH 3/4] [IMP] base: country specific address format small imp bzr revid: qdp-launchpad@openerp.com-20111201145052-onb2k2xp2pu94124 --- openerp/addons/base/res/res_country.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openerp/addons/base/res/res_country.py b/openerp/addons/base/res/res_country.py index 7272c4e34f7..ff710968473 100644 --- a/openerp/addons/base/res/res_country.py +++ b/openerp/addons/base/res/res_country.py @@ -31,7 +31,8 @@ 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', help="You can state here the usual format to use for the \ + addresses belonging to this country."), } _sql_constraints = [ ('name_uniq', 'unique (name)', @@ -41,7 +42,7 @@ class Country(osv.osv): ] _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): From c900059a3e94895e96294e9f1ffef769af5bdcd4 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Thu, 1 Dec 2011 17:27:47 +0100 Subject: [PATCH 4/4] [IMP] res_partner_address, display_address: improved help tooltip on address_format + made private the function _display_address as it's not usable through direct RPC requests + added context=None in the signature of this function, for future needs bzr revid: qdp-launchpad@openerp.com-20111201162747-gcbh995k1pu8ql7m --- openerp/addons/base/res/res_country.py | 9 +++++++-- openerp/addons/base/res/res_partner.py | 2 +- openerp/report/report_sxw.py | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/openerp/addons/base/res/res_country.py b/openerp/addons/base/res/res_country.py index ff710968473..3897065da73 100644 --- a/openerp/addons/base/res/res_country.py +++ b/openerp/addons/base/res/res_country.py @@ -31,8 +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."), + '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)', diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py index fb04c10bf5a..32b5e08d7b6 100644 --- a/openerp/addons/base/res/res_partner.py +++ b/openerp/addons/base/res/res_partner.py @@ -356,7 +356,7 @@ 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): + 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. diff --git a/openerp/report/report_sxw.py b/openerp/report/report_sxw.py index 050c53b7456..9b317bb0954 100644 --- a/openerp/report/report_sxw.py +++ b/openerp/report/report_sxw.py @@ -315,7 +315,7 @@ class rml_parse(object): 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) + 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 = []