From 526bfca3afc2dc4bcc2565912705be4cf738267d Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Wed, 19 Sep 2018 15:44:34 +0000 Subject: [PATCH] [FIX] base_address_city: correct view_get with address fields Have a partner with children exceeding the limit of the kanban. Edit, Add a contact > save and quit Save the partner Before this commit, there was a traceback, because a check on parent_id was done to compute the modifier readonly of the city fields in subviews However, python onchange gets rid of parent_id because child_ids and parent_id are two faces of the same coin And if that check were not done, we would end up in an infinite recursion After this commit, there is no traceback, as we stop checking on parent_id in the case of paged subviews (list and kanban) because we literally know there is one OPW 1886320 closes odoo/odoo#27114 --- .../base_address_city/models/res_partner.py | 57 ++++++++++++++++--- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/addons/base_address_city/models/res_partner.py b/addons/base_address_city/models/res_partner.py index 2f43935b0c2..5b98ac65ef6 100644 --- a/addons/base_address_city/models/res_partner.py +++ b/addons/base_address_city/models/res_partner.py @@ -25,17 +25,58 @@ class Partner(models.Model): # render the partner address accordingly to address_view_id doc = etree.fromstring(arch) if doc.xpath("//field[@name='city_id']"): - return arch - for city_node in doc.xpath("//field[@name='city']"): - replacement_xml = """ + return arch + + replacement_xml = """
- - + +
- """ % (_('City'), _('City')) - city_id_node = etree.fromstring(replacement_xml) - city_node.getparent().replace(city_node, city_id_node) + """ + + replacement_data = { + 'placeholder': _('City'), + } + + def _arch_location(node): + in_subview = False + view_type = False + parent = node.getparent() + while parent is not None and (not view_type or not in_subview): + if parent.tag == 'field': + in_subview = True + elif parent.tag in ['list', 'tree', 'kanban', 'form']: + view_type = parent.tag + parent = parent.getparent() + return { + 'view_type': view_type, + 'in_subview': in_subview, + } + + for city_node in doc.xpath("//field[@name='city']"): + location = _arch_location(city_node) + replacement_data['parent_condition'] = '' + if location['view_type'] == 'form' or not location['in_subview']: + replacement_data['parent_condition'] = ", ('parent_id', '!=', False)" + + replacement_formatted = replacement_xml % replacement_data + for replace_node in etree.fromstring(replacement_formatted).getchildren(): + city_node.addprevious(replace_node) + parent = city_node.getparent() + parent.remove(city_node) arch = etree.tostring(doc, encoding='unicode') return arch