Skip to content

Bugfix change field type work hours to duration field#254

Merged
kbeker merged 8 commits intomasterfrom
bugfix-change-field-type-work-hours-to-duration-field
May 29, 2019
Merged

Bugfix change field type work hours to duration field#254
kbeker merged 8 commits intomasterfrom
bugfix-change-field-type-work-hours-to-duration-field

Conversation

@kbeker
Copy link
Contributor

@kbeker kbeker commented May 29, 2019

Resolves #213

@kbeker kbeker added the bug Something isn't working label May 29, 2019
@kbeker kbeker added this to the Next release milestone May 29, 2019
@kbeker kbeker self-assigned this May 29, 2019
Copy link
Contributor

@dybi dybi left a comment

Choose a reason for hiding this comment

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

Seems pretty good. Anyway, as it touches quaite a delicate part of the system, I would insist on having another senior's review before merging.
miyagi_approves

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):
Copy link
Contributor

Choose a reason for hiding this comment

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

and isinstance(self.work_hours, timedelta) seems unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

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)

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, why not :) Done

@kbeker kbeker force-pushed the bugfix-change-field-type-work-hours-to-duration-field branch from 1f0052b to 8b243d3 Compare May 29, 2019 14:06
@kbeker kbeker force-pushed the bugfix-change-field-type-work-hours-to-duration-field branch from 8b243d3 to 02af6cd Compare May 29, 2019 14:23
@kbeker kbeker merged commit 02af6cd into master May 29, 2019
@kbeker kbeker deleted the bugfix-change-field-type-work-hours-to-duration-field branch May 29, 2019 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change the field type of work_hours to DurationField

2 participants