[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
This commit is contained in:
Nicolas Lempereur
2016-03-21 14:38:16 +01:00
parent 8e1c747666
commit fae65a36e7
2 changed files with 58 additions and 37 deletions
@@ -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%;
}
}
}
}
+15 -37
View File
@@ -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