diff --git a/addons/web/static/src/less/enterprise_compatibility.less b/addons/web/static/src/less/enterprise_compatibility.less index 7dc4238f684..74b5e99abf1 100644 --- a/addons/web/static/src/less/enterprise_compatibility.less +++ b/addons/web/static/src/less/enterprise_compatibility.less @@ -326,6 +326,27 @@ div.o_checkbox { > .o_address_zip { margin-right: 0; } + &.o_zip_city { + > .o_address_zip { + margin-right: 2%; + } + > .o_address_city { + margin-right: 0; + } + > .o_address_state { + clear: left; + margin-right: 0; + } + } + &.o_city_state { + > .o_address_state { + margin-right: 0; + } + > .o_address_zip { + clear: left; + margin-right: 0; + } + } } &.oe_form_editable .o_address_format { > .o_address_city { @@ -337,6 +358,28 @@ div.o_checkbox { > .o_address_zip { width: 25%; } + &.o_zip_city { + > .o_address_zip { + width: 38%; + } + > .o_address_city { + width: 60%; + } + > .o_address_state { + width: 100%; + } + } + &.o_city_state { + > .o_address_city { + width: 50%; + } + > .o_address_state { + width: 48%; + } + > .o_address_zip { + width: 100%; + } + } } } diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py index aca043f534d..03d83364d49 100644 --- a/openerp/addons/base/res/res_partner.py +++ b/openerp/addons/base/res/res_partner.py @@ -15,49 +15,27 @@ from openerp.osv.expression import get_unaccent_wrapper from openerp.tools.translate import _ from openerp.exceptions import UserError -ADDRESS_FORMAT_LAYOUTS = { - '%(city)s %(state_code)s\n%(zip)s': """ -
- - -
- -
- """, - '%(zip)s %(city)s': """ -
- - -
- -
- """, - '%(city)s\n%(state_name)s\n%(zip)s': """ -
- - - -
- """ +ADDRESS_FORMAT_CLASSES = { + '%(city)s %(state_code)s\n%(zip)s': 'o_city_state', + '%(zip)s %(city)s': 'o_zip_city' } - class format_address(object): @api.model def fields_view_get_address(self, arch): - fmt = self.env.user.company_id.country_id.address_format or '' - for k, v in ADDRESS_FORMAT_LAYOUTS.items(): - if k in fmt: + address_format = self.env.user.company_id.country_id.address_format or '' + for format_pattern, format_class in ADDRESS_FORMAT_CLASSES.iteritems(): + if format_pattern in address_format: doc = etree.fromstring(arch) - for node in doc.xpath("//div[@class='address_format']"): - tree = etree.fromstring(v % {'city': _('City'), 'zip': _('ZIP'), 'state': _('State')}) - for child in node.xpath(".//field"): - for field in tree.xpath("//field[@name='%s']" % child.attrib.get("name")): - if child.attrib.get("modifiers"): - field.attrib['modifiers'] = child.attrib.get('modifiers') - if child.attrib.get("on_change"): - field.attrib["on_change"] = child.attrib.get("on_change") - node.getparent().replace(node, tree) + for address_node in doc.xpath("//div[@class='o_address_format']"): + # add address format class to address block + address_node.attrib['class'] += ' ' + format_class + if format_class.startswith('o_zip'): + zip_fields = address_node.xpath("//field[@name='zip']") + city_fields = address_node.xpath("//field[@name='city']") + if zip_fields and city_fields: + # move zip field before city field + city_fields[0].addprevious(zip_fields[0]) arch = etree.tostring(doc) break return arch