Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Maintenance Location

Entity: maintenance.location

Compute Method: _compute_equipment_count

Inputs Method Outputs
all_locations = self.env["maintenance.location"].search(
            [("id", "child_of", self.ids)]
        )
equip_data = self.env["maintenance.equipment"].read_group(
            domain=[("location_id", "in", all_locations.ids)],
            fields=["location_id"],
            groupby=["location_id"],
        )
count_dict = {x["location_id"][0]: x["location_id_count"] for x in equip_data}
for location in self:
            descendant_ids = all_locations.filtered(
                lambda sub_loc, loc=location: sub_loc.parent_path
                and sub_loc.parent_path.startswith(loc.parent_path)
            ).ids

            location.equipment_count = sum(
                count_dict.get(d_id, 0) for d_id in descendant_ids
            )

Back to entity