Files
odoo_source/addons/web_hierarchy/models/models.py
T
Xavier Bol (xbo) f009f19fc5 [FIX] web_hierarchy,hr_org_chart: remove highlight on focus record
Before this commit, the highlight added on a focus record, that styling
added was useful when we displayed only the first result in the search
to be able to build a tree but since now all the records found with
the search made by the user are shown without building a tree if it
is not possible then it is no longer needed to highlight the records
found.

This commit removes the highlight added on the focused record, the one
found by the search since it is not really needed.

task-3556262

closes odoo/odoo#138803

Signed-off-by: Sofie Gvaladze (sgv) <sgv@odoo.com>
2023-10-18 15:26:33 +00:00

43 lines
1.7 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models
class Base(models.AbstractModel):
_inherit = 'base'
@api.model
def hierarchy_read(self, domain, fields, parent_field, child_field=None):
if parent_field not in fields:
fields.append(parent_field)
records = self.search(domain)
focus_record = self.env[self._name]
fetch_child_ids_for_all_records = False
if len(records) == 1:
domain = [(parent_field, '=', records.id), ('id', '!=', records.id)]
if records[parent_field]:
focus_record = records
records += focus_record[parent_field]
domain = [('id', 'not in', records.ids), (parent_field, 'in', records.ids)]
records += self.search(domain)
elif not records:
records = self.search([(parent_field, '=', False)])
else:
fetch_child_ids_for_all_records = True
children_ids_per_record_id = {}
if not child_field:
children_ids_per_record_id = {
record.id: child_ids
for record, child_ids in self._read_group(
[(parent_field, 'in', records.ids if fetch_child_ids_for_all_records else (records - records[parent_field]).ids)],
(parent_field,),
('id:array_agg',),
)
}
result = records.read(fields)
if children_ids_per_record_id:
for record_data in result:
if record_data['id'] in children_ids_per_record_id:
record_data['__child_ids__'] = children_ids_per_record_id[record_data['id']]
return result