Skip to content
Open
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
13 changes: 11 additions & 2 deletions beesdoo_shift/models/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,19 @@ def _nb_worker_max(self):
)
)

@api.constrains("start_time", "end_time")
def _check_real_hour(self):
for rec in self:
if not (-0.001 < rec.start_time < 24) or not (
-0.001 < rec.end_time < 24
):
raise UserError(
_("Start time and End time need to be between 0 and 23:59")
)

@api.onchange("start_time", "end_time")
def _get_duration(self):
if self.start_time and self.end_time:
self.duration = self.end_time - self.start_time
self.duration = (self.end_time or 0.0) - (self.start_time or 0.0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd rather return False when start_time or end_time instead of these weird values.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
self.duration = (self.end_time or 0.0) - (self.start_time or 0.0)
if self.start_time and self.end_time:
self.duration = self.end_time - self.start_time
else:
self.duration = False


@api.onchange("duration")
def _set_duration(self):
Expand Down