Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] cb_maintenance: add maneger_id in maintence_plan_form #149

Merged
merged 1 commit into from
Jan 31, 2024
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
3 changes: 3 additions & 0 deletions cb_maintenance/models/maintenance_equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
technician_id = maintenance_plan.technician_id or False
category_id = self.category_id if self else False
category_id = maintenance_plan.category_id or category_id
manager_id = maintenance_plan.manager_id
if technician_id:
res.update({"technician_id": technician_id.id})
if manager_id:
res.update({"manager_id": manager_id.id})

Check warning on line 37 in cb_maintenance/models/maintenance_equipment.py

View check run for this annotation

Codecov / codecov/patch

cb_maintenance/models/maintenance_equipment.py#L37

Added line #L37 was not covered by tests
if category_id:
res.update({"category_id": category_id.id})
return res
Expand Down
22 changes: 21 additions & 1 deletion cb_maintenance/models/maintenance_plan.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2020 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import api, fields, models


class MaintenancePlan(models.Model):
Expand All @@ -12,3 +12,23 @@
"res.partner", domain="[('is_maintenance_technician', '=', True)]"
)
category_id = fields.Many2one("maintenance.equipment.category")

manager_id = fields.Many2one("res.users", string="Manager", default=False)

maintenance_team_id_member_ids = fields.Many2many(
"res.users",
compute="_compute_maintenance_team_id_member_ids",
)

@api.depends("maintenance_team_id")
def _compute_maintenance_team_id_member_ids(self):
for record in self:
if record.maintenance_team_id:
users = (

Check warning on line 27 in cb_maintenance/models/maintenance_plan.py

View check run for this annotation

Codecov / codecov/patch

cb_maintenance/models/maintenance_plan.py#L27

Added line #L27 was not covered by tests
self.env["maintenance.team"]
.search([("id", "child_of", record.maintenance_team_id.id)])
.mapped("member_ids")
)
record.maintenance_team_id_member_ids = [(6, 0, users.ids)]

Check warning on line 32 in cb_maintenance/models/maintenance_plan.py

View check run for this annotation

Codecov / codecov/patch

cb_maintenance/models/maintenance_plan.py#L32

Added line #L32 was not covered by tests
else:
record.maintenance_team_id_member_ids = False

Check warning on line 34 in cb_maintenance/models/maintenance_plan.py

View check run for this annotation

Codecov / codecov/patch

cb_maintenance/models/maintenance_plan.py#L34

Added line #L34 was not covered by tests
6 changes: 6 additions & 0 deletions cb_maintenance/views/maintenance_plan.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
name="technician_id"
options="{'no_open': True, 'no_create': True}"
/>
<field
name="manager_id"
options="{'no_open': True, 'no_create': True}"
domain="[('id', 'in', maintenance_team_id_member_ids)]"
/>
<field name="maintenance_team_id_member_ids" invisible="1" />
<field
name="category_id"
options="{'no_open': True, 'no_create': True, 'child_selection_field': 'name'}"
Expand Down
Loading