Skip to content

[17.0][IMP] maintenance_location: Add inverse relation and equipment count to locations#546

Open
cgarcia-solvos wants to merge 1 commit intoOCA:17.0from
solvosci:17.0-imp-maintenance_location-equipments
Open

[17.0][IMP] maintenance_location: Add inverse relation and equipment count to locations#546
cgarcia-solvos wants to merge 1 commit intoOCA:17.0from
solvosci:17.0-imp-maintenance_location-equipments

Conversation

@cgarcia-solvos
Copy link

Currently, the maintenance_location addon allows assigning a specific location to a maintenance.equipment. However, there is no quick way to check this relationship from the location's perspective.

This introduces the inverse relationship in the maintenance.location model.

maintenance.location model:

Added equipment_ids (One2many) to establish the inverse relation with maintenance.equipment.

Added equipment_count (Computed Integer) to count the number of equipments in a given location.Views:

Views:

Tree view: Added the equipment_count field so users can see the number of devices in each location.

tree_view

Form view: Added the equipment_ids field (using the many2many_tags widget) to display the specific equipments assigned to the location.

form_view

@cgarcia-solvos cgarcia-solvos force-pushed the 17.0-imp-maintenance_location-equipments branch from 29846e8 to 8b73ad8 Compare March 12, 2026 07:43
@cgarcia-solvos cgarcia-solvos changed the title [IMP] maintenance_location: Add inverse relation and equipment count to locations [17.0][IMP] maintenance_location: Add inverse relation and equipment count to locations Mar 12, 2026
@cgarcia-solvos cgarcia-solvos force-pushed the 17.0-imp-maintenance_location-equipments branch 2 times, most recently from de6dfa4 to 80ce1fb Compare March 12, 2026 07:55
@cgarcia-solvos
Copy link
Author

@luisDIXMIT @christian-ramos-tecnativa could you review? Thanks!!

@dalonsod
Copy link
Contributor

@cgarcia-solvos one one suggestion, not blocking. Since equipments as many2many_tags at location form view could be a field with certain size, could you move it to a currently missing right column here?

imagen

@api.depends("equipment_ids")
def _compute_equipment_count(self):
res = self.env["maintenance.equipment"].read_group(
domain=[("location_id", "in", self.ids)],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should count equipments in sublocations too

Suggested change
domain=[("location_id", "in", self.ids)],
domain=[("location_id", "child_of", self.ids)],

Also may be good idea adding a child_equipment_ids or similar as a readonly computable, or adding a sublocations field with the count in a tree view. Otherwise the user will see that there are 5 equipments in the location but just 3 equipments are displayed

@cgarcia-solvos cgarcia-solvos force-pushed the 17.0-imp-maintenance_location-equipments branch 2 times, most recently from 84d521c to dc75d7e Compare March 12, 2026 12:16
Copy link
Contributor

@luisDIXMIT luisDIXMIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on runboat and LGTM!

Copy link
Contributor

@luisDIXMIT luisDIXMIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I skipped a controversial problem. With this development, an equipment can be assigned to several locations, and this is not correct.

@luisDIXMIT
Copy link
Contributor

Sorry, ignore the last comment. I realized that it can be chosen and is automatically moved to the new location. LGTM!

@cgarcia-solvos cgarcia-solvos force-pushed the 17.0-imp-maintenance_location-equipments branch 2 times, most recently from 85b43dc to b4d03ab Compare March 13, 2026 08:53
Copy link
Contributor

@christian-ramos-tecnativa christian-ramos-tecnativa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cgarcia-solvos cgarcia-solvos force-pushed the 17.0-imp-maintenance_location-equipments branch 2 times, most recently from d1b5dbd to 598066b Compare March 13, 2026 10:14
@cgarcia-solvos cgarcia-solvos force-pushed the 17.0-imp-maintenance_location-equipments branch from 598066b to 5e1f68d Compare March 13, 2026 10:15
@cgarcia-solvos
Copy link
Author

@dalonsod I've updated the form view to follow your suggestion. Does it look better this way?

imagen

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants