Skip to content

Commit 9fd56c0

Browse files
committed
Merge PR #390 into 16.0
Signed-off-by pedrobaeza
2 parents 802ab72 + 55a4bf4 commit 9fd56c0

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

maintenance_timesheet/models/hr_timesheet.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ def onchange_maintenance_request_id(self):
1616
self.project_id = self.maintenance_request_id.project_id
1717
self.task_id = self.maintenance_request_id.task_id
1818

19-
@api.model
20-
def create(self, values):
21-
if values.get("maintenance_request_id"):
22-
self._check_request_done(values.get("maintenance_request_id"))
23-
return super().create(values)
19+
@api.model_create_multi
20+
def create(self, vals_list):
21+
maintenance_request_ids = [
22+
vals.get("maintenance_request_id")
23+
for vals in vals_list
24+
if vals.get("maintenance_request_id")
25+
]
26+
self._check_request_done(maintenance_request_ids)
27+
return super().create(vals_list)
2428

2529
def write(self, values):
2630
current_request = self.maintenance_request_id
@@ -32,15 +36,19 @@ def write(self, values):
3236
return super().write(values)
3337

3438
def unlink(self):
35-
for timesheet in self.filtered(lambda x: x.maintenance_request_id):
36-
self._check_request_done(timesheet.maintenance_request_id.id)
39+
self._check_request_done(
40+
self.filtered(lambda x: x.maintenance_request_id).maintenance_request_id.ids
41+
)
3742
return super().unlink()
3843

39-
def _check_request_done(self, request_id):
44+
def _check_request_done(self, request_id: int | list[int]):
4045
"""
4146
Editing a timesheet related to a finished request is forbidden.
4247
"""
43-
if self.env["maintenance.request"].browse(request_id).stage_id.done:
48+
request_ids = [request_id] if isinstance(request_id, int) else request_id
49+
if any(
50+
self.env["maintenance.request"].browse(request_ids).stage_id.mapped("done")
51+
):
4452
raise ValidationError(
4553
_(
4654
"Cannot save or delete a timesheet for "

0 commit comments

Comments
 (0)