Skip to content

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

Merged
OCA-git-bot merged 1 commit intoOCA:17.0from
solvosci:17.0-imp-maintenance_location-equipments
Apr 29, 2026
Merged

[17.0][IMP] maintenance_location: Add inverse relation and equipment count to locations#546
OCA-git-bot merged 1 commit intoOCA:17.0from
solvosci:17.0-imp-maintenance_location-equipments

Conversation

@cgarcia-solvos
Copy link
Copy Markdown

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
Copy Markdown
Author

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

@dalonsod
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 3 times, most recently from 598066b to 5e1f68d Compare March 13, 2026 10:15
@cgarcia-solvos
Copy link
Copy Markdown
Author

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

imagen

@OCA-git-bot
Copy link
Copy Markdown
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). 🤖

@cgarcia-solvos
Copy link
Copy Markdown
Author

@pedrobaeza Is this ready to be merged? Thanks!

@pedrobaeza pedrobaeza added this to the 17.0 milestone Apr 29, 2026
Copy link
Copy Markdown
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

Please don't add extra empty lines in between.

@cgarcia-solvos cgarcia-solvos force-pushed the 17.0-imp-maintenance_location-equipments branch from 5e1f68d to 83e40a4 Compare April 29, 2026 11:36
@OCA-git-bot OCA-git-bot added mod:maintenance_location Module maintenance_location series:17.0 labels Apr 29, 2026
@cgarcia-solvos
Copy link
Copy Markdown
Author

@pedrobaeza Fixed, thanks!

Copy link
Copy Markdown
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

/ocabot merge minor

@OCA-git-bot
Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 17.0-ocabot-merge-pr-546-by-pedrobaeza-bump-minor, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 56904ae into OCA:17.0 Apr 29, 2026
7 checks passed
@OCA-git-bot
Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at a0d7e0a. Thanks a lot for contributing to OCA. ❤️

@dalonsod dalonsod deleted the 17.0-imp-maintenance_location-equipments branch April 29, 2026 13:35
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.

6 participants