Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions maintenance_plan/models/maintenance_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ class MaintenancePlan(models.Model):

@api.model
def _search_search_equipment(self, operator, value):
if operator != "=" or (not value and not isinstance(value, models.NewId)):
if operator not in ("=", "in") or (
not value and not isinstance(value, models.NewId)
):
raise ValueError(self.env._("Unsupported search operator"))
plans = self.search([("generate_with_domain", "=", True)])
plan_ids = []
Expand All @@ -113,7 +115,7 @@ def _search_search_equipment(self, operator, value):
)
):
plan_ids.append(plan.id)
return ["|", ("equipment_id", "=", value), ("id", "in", plan_ids)]
return ["|", ("equipment_id", operator, value), ("id", "in", plan_ids)]

@api.depends("equipment_id")
def _compute_search_equipment(self):
Expand Down
1 change: 1 addition & 0 deletions maintenance_plan/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
- Enric Tobella \<<enric.tobella@dixmit.com>\>
- Alexei Rivera \<<arivera@archeti.com>\>
- Yann Papouin \<<ypa@decgroupe.com>\>
- Yannick Payot \<<yannick.payot@acsone.eu>\>
1 change: 1 addition & 0 deletions maintenance_plan/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import test_maintenance_plan
from . import test_maintenance_plan_domain
from . import test_equipment_count
87 changes: 87 additions & 0 deletions maintenance_plan/tests/test_equipment_count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright 2026 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from .common import TestMaintenanceBase


class TestEquipmentCount(TestMaintenanceBase):
"""Test _compute_search_maintenance_plan_count in maintenance.equipment"""

def test_search_maintenance_plan_count_zero(self):
"""Test search_maintenance_plan_count when no plans exist"""
# Create a new equipment with no maintenance plans
equipment = self.MaintenanceEquipment.create(
{
"name": "Equipment No Plans",
}
)
equipment._compute_search_maintenance_plan_count()
self.assertEqual(
equipment.search_maintenance_plan_count,
0,
"search_maintenance_plan_count should be 0 when no plans exist",
)

def test_search_maintenance_plan_count_one(self):
"""Test search_maintenance_plan_count with one active plan"""
# Create a maintenance plan for the equipment
self.MaintenancePlan.create(
{
"equipment_id": self.equipment.id,
"maintenance_kind_id": self.maintenance_kind.id,
}
)
self.equipment._compute_search_maintenance_plan_count()
self.assertGreaterEqual(
self.equipment.search_maintenance_plan_count,
1,
"search_maintenance_plan_count should be at least 1 when plan exists",
)

def test_search_maintenance_plan_count_multiple(self):
"""Test search_maintenance_plan_count with multiple plans"""
# Create a second maintenance kind
kind2 = self.MaintenanceKind.create(
{
"name": "Second Kind",
"code": "SECOND_KIND",
"priority": "optional",
}
)
# Create multiple maintenance plans for the equipment with different kinds
self.MaintenancePlan.create(
[
{
"equipment_id": self.equipment.id,
"maintenance_kind_id": self.maintenance_kind.id,
},
{
"equipment_id": self.equipment.id,
"maintenance_kind_id": kind2.id,
},
]
)

self.equipment._compute_search_maintenance_plan_count()
self.assertGreaterEqual(
self.equipment.search_maintenance_plan_count,
2,
"search_maintenance_plan_count should be at least 2 when multiple plans exist",
)

def test_search_maintenance_plan_count_with_inactive(self):
"""Test search_maintenance_plan_count includes inactive plans"""
# Create an inactive plan
self.MaintenancePlan.create(
{
"equipment_id": self.equipment.id,
"maintenance_kind_id": self.maintenance_kind.id,
"active": False,
}
)
self.equipment._compute_search_maintenance_plan_count()
self.assertGreaterEqual(
self.equipment.search_maintenance_plan_count,
1,
"search_maintenance_plan_count should include inactive plans",
)
Loading