[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
This commit is contained in:
@@ -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 = """
|
||||
<div>
|
||||
<field name="country_enforce_cities" invisible="1"/>
|
||||
<field name='city' placeholder="%s" attrs="{'invisible': [('country_enforce_cities', '=', True), ('city_id', '!=', False)], 'readonly': [('type', '=', 'contact'), ('parent_id', '!=', False)]}"/>
|
||||
<field name='city_id' placeholder="%s" attrs="{'invisible': [('country_enforce_cities', '=', False)], 'readonly': [('type', '=', 'contact'), ('parent_id', '!=', False)]}" context="{'default_country_id': country_id}" domain="[('country_id', '=', country_id)]"/>
|
||||
<field name='city' placeholder="%(placeholder)s"
|
||||
attrs="{
|
||||
'invisible': [('country_enforce_cities', '=', True), ('city_id', '!=', False)],
|
||||
'readonly': [('type', '=', 'contact')%(parent_condition)s]
|
||||
}"
|
||||
/>
|
||||
<field name='city_id' placeholder="%(placeholder)s"
|
||||
context="{'default_country_id': country_id}"
|
||||
domain="[('country_id', '=', country_id)]"
|
||||
attrs="{
|
||||
'invisible': [('country_enforce_cities', '=', False)],
|
||||
'readonly': [('type', '=', 'contact')%(parent_condition)s]
|
||||
}"
|
||||
/>
|
||||
</div>
|
||||
""" % (_('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
|
||||
|
||||
Reference in New Issue
Block a user