Skip to content

Commit 88611e3

Browse files
committed
[FIX] beesdoo_shift: forbid illegal hour
It was possible to encode shift that start at negative hour or hour bigger then 24. Of course this lead to some error at the moment we generate the planning for a given date - Add a constraint on start_time and end_time - Fix onchange on duration: duration was not computed properly when the start or end time was 00:00
1 parent c2fc019 commit 88611e3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

beesdoo_shift/models/planning.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,19 @@ def _nb_worker_max(self):
214214
)
215215
)
216216

217+
@api.constrains("start_time", "end_time")
218+
def _check_real_hour(self):
219+
for rec in self:
220+
if not (-0.001 < rec.start_time < 24) or not (-0.001 < rec.end_time < 24):
221+
raise UserError(
222+
_(
223+
"Start time and End time need to be between 0 and 23:59"
224+
)
225+
)
226+
217227
@api.onchange("start_time", "end_time")
218228
def _get_duration(self):
219-
if self.start_time and self.end_time:
220-
self.duration = self.end_time - self.start_time
229+
self.duration = (self.end_time or 0.0) - (self.start_time or 0.0)
221230

222231
@api.onchange("duration")
223232
def _set_duration(self):

0 commit comments

Comments
 (0)