[FIX] base: partner view improvement
Improve the partner view by reorganising the city/state/zip row, making the order of the fields dependant of the country address_format. This is done to ease the use of these view for our users by displaying a format they are already used to. Task id #3138441 X-original-commit: c646f7bb80cb7f9af689082752608b554f1a648b Part-of: odoo/odoo#111324
This commit is contained in:
@@ -48,6 +48,7 @@ class FormatAddressMixin(models.AbstractModel):
|
||||
def _view_get_address(self, arch):
|
||||
# consider the country of the user, not the country of the partner we want to display
|
||||
address_view_id = self.env.company.country_id.address_view_id.sudo()
|
||||
address_format = self.env.company.country_id.address_format
|
||||
if address_view_id and not self._context.get('no_address_format') and (not address_view_id.model or address_view_id.model == self._name):
|
||||
#render the partner address accordingly to address_view_id
|
||||
for address_node in arch.xpath("//div[hasclass('o_address_format')]"):
|
||||
@@ -61,6 +62,31 @@ class FormatAddressMixin(models.AbstractModel):
|
||||
except ValueError:
|
||||
return arch
|
||||
address_node.getparent().replace(address_node, sub_arch)
|
||||
elif address_format and not self._context.get('no_address_format'):
|
||||
# For the zip, city and state fields we need to move them around in order to follow the country address format.
|
||||
# The purpose of this is to help the user by following a format he is used to.
|
||||
city_line = [line.split(' ') for line in address_format.split('\n') if 'city' in line]
|
||||
if city_line:
|
||||
field_order = [field.replace('%(', '').replace(')s', '') for field in city_line[0]]
|
||||
for address_node in arch.xpath("//div[hasclass('o_address_format')]"):
|
||||
concerned_fields = {'zip', 'city', 'state_id'} - {field_order[0]}
|
||||
current_field = address_node.find(f".//field[@name='{field_order[0]}']")
|
||||
# First loop into the fields displayed in the address_format, and order them.
|
||||
for field in field_order[1:]:
|
||||
if field in ('state_code', 'state_name'):
|
||||
field = 'state_id'
|
||||
previous_field = current_field
|
||||
current_field = address_node.find(f".//field[@name='{field}']")
|
||||
if previous_field is not None and current_field is not None:
|
||||
previous_field.addnext(current_field)
|
||||
concerned_fields -= {field}
|
||||
# Add the remaining fields in 'concerned_fields' at the end, after the others
|
||||
for field in concerned_fields:
|
||||
previous_field = current_field
|
||||
current_field = address_node.find(f".//field[@name='{field}']")
|
||||
if previous_field is not None and current_field is not None:
|
||||
previous_field.addnext(current_field)
|
||||
|
||||
return arch
|
||||
|
||||
@api.model
|
||||
|
||||
Reference in New Issue
Block a user