Bugfix change field type work hours to duration field#254
Merged
Conversation
dybi
approved these changes
May 29, 2019
employees/models.py
Outdated
| and self.author.report_set.get_report_work_hours_sum_for_date(self.date, self.pk) + self.work_hours > 24 | ||
| ): | ||
| raise ValidationError( | ||
| if hasattr(self, "author") and isinstance(self.work_hours, timedelta): |
Contributor
There was a problem hiding this comment.
and isinstance(self.work_hours, timedelta) seems unnecessary
Contributor
Author
There was a problem hiding this comment.
Actually, it has to be, but it substituted with validation error if instance does not match
| def decimal_to_hours(data: Decimal) -> str: | ||
| return str(data).replace(".", ":") | ||
| def duration_field_to_string(data: timedelta) -> str: | ||
| return "{:02d}:{:02d}".format((data.seconds // 3600), (data.seconds % 3600) // 60) |
Contributor
There was a problem hiding this comment.
duplicates:
@property
def work_hours_str(self) -> str:
return self.work_hours.to_eng_string().replace(".", ":")
return "{:02d}:{:02d}".format((self.work_hours.seconds // 3600), (self.work_hours.seconds % 3600) // 60)
Contributor
Author
There was a problem hiding this comment.
Moved to common file
| def test_report_model_work_hours_field_should_not_accept_decimal_value_exceeding_set_maximum(self): | ||
| self.field_should_not_accept_input( | ||
| "work_hours", ReportModelConstants.MAX_WORK_HOURS_DECIMAL_VALUE.value + Decimal("0.01") | ||
| "work_hours", ReportModelConstants.MIN_WORK_HOURS.value - datetime.timedelta(seconds=59) |
Contributor
There was a problem hiding this comment.
maybe
Suggested change
| "work_hours", ReportModelConstants.MIN_WORK_HOURS.value - datetime.timedelta(seconds=59) | |
| "work_hours", ReportModelConstants.MIN_WORK_HOURS.value - datetime.timedelta(seconds=1) |
?
Contributor
Author
There was a problem hiding this comment.
Sure, why not :) Done
1f0052b to
8b243d3
Compare
8b243d3 to
02af6cd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Resolves #213