From 906bf16a7617a86455547e3ebc08485cc80458df Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 25 Jan 2016 18:41:28 +0100 Subject: [PATCH] [8.0][FIX] Make on_change in address_format divs work To reproduce the bug: - Create a partner. - Set it state "Alaska". - Country becomes "United States". - Set a country for YourCompany, such as Spain. - Create a partner. - Set it state "Alaska". - Country remains blank. Also, `node.xpath("//field")` was running over every `` in the view, not just those inside the `
`. Now it only traverses the right nodes, which renders every affected view faster. --- openerp/addons/base/res/res_partner.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py index 061344b9ae3..c5da0974dc0 100644 --- a/openerp/addons/base/res/res_partner.py +++ b/openerp/addons/base/res/res_partner.py @@ -67,10 +67,12 @@ class format_address(object): 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"): - if child.attrib.get('modifiers'): - for field in tree.xpath("//field[@name='%s']" % child.attrib.get('name')): + 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) arch = etree.tostring(doc) break