summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2016-01-29 15:44:27 +0100
committerNicolas Lempereur <nle@odoo.com>2016-03-21 14:38:16 +0100
commitfae65a36e7c93bad72dcc9c1b64bc4f46d3fcfec (patch)
treec9308b9eca29802c713e31152e46d474b6da70e0
parent8e1c74766610a8551f07e7d237807ed8433782d0 (diff)
[FIX] web: css for address format based on country
In 9.0's 05adb7f the `<div class="address_format"/>` wrapping an address city, state_id and zip fields was removed. There is a hack on fields_view_get which transform this block depending on the company country, so without the block the feature isn't enabled. This commit adds a class on the new block `<div class="address_format"/>` used to wrap the whole address which will change the sizing of the city, state_id and zip fields as it was before version 9. To fully follow what was done previously, the zip is aldo moved before the city if the address format needs it. Thus we now have as before the three format as follows: [default format] city state zip [format .o_city_state (brazil)] city state zip [format .o_zip_city (belgium, netherlands, ...)] zip city state Another change is brought by this commit, before most element attributes from city, state_id and zip fields were lost whilst doing the hack, now they are all kept. closes #10692 opw-666567
-rw-r--r--addons/web/static/src/less/enterprise_compatibility.less43
-rw-r--r--openerp/addons/base/res/res_partner.py52
2 files changed, 58 insertions, 37 deletions
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': """
- <div class="address_format">
- <field name="city" placeholder="%(city)s" style="width: 50%%"/>
- <field name="state_id" class="oe_no_button" placeholder="%(state)s" style="width: 47%%" options='{"no_open": true}'/>
- <br/>
- <field name="zip" placeholder="%(zip)s"/>
- </div>
- """,
- '%(zip)s %(city)s': """
- <div class="address_format">
- <field name="zip" placeholder="%(zip)s" style="width: 40%%"/>
- <field name="city" placeholder="%(city)s" style="width: 57%%"/>
- <br/>
- <field name="state_id" class="oe_no_button" placeholder="%(state)s" options='{"no_open": true}'/>
- </div>
- """,
- '%(city)s\n%(state_name)s\n%(zip)s': """
- <div class="address_format">
- <field name="city" placeholder="%(city)s"/>
- <field name="state_id" class="oe_no_button" placeholder="%(state)s" options='{"no_open": true}'/>
- <field name="zip" placeholder="%(zip)s"/>
- </div>
- """
+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