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

[FIX] beesdoo_shift: forbid illegal hour #292

Open
wants to merge 1 commit into
base: 12.0
Choose a base branch
from
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
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
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