Skip to content

Commit

Permalink
Add support for duration adjustment for reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
thenav56 committed Aug 22, 2024
1 parent 2353801 commit 6c959dc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/track/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class TimeEntryAdmin(admin.ModelAdmin):
"type",
"date",
"duration",
"duration_adjustment",
"status",
)

Expand Down
22 changes: 22 additions & 0 deletions apps/track/migrations/0014_timeentry_duration_adjustment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.15 on 2024-08-22 11:29

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("track", "0013_contract_description"),
]

operations = [
migrations.AddField(
model_name="timeentry",
name="duration_adjustment",
field=models.SmallIntegerField(
blank=True,
help_text="Minutes. Used to keep track of reported minutes. This will be used as duration (+- duration_adjustment)",
null=True,
),
),
]
20 changes: 20 additions & 0 deletions apps/track/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -71,10 +72,29 @@ class Status(models.IntegerChoices):
blank=True,
help_text=_("Minutes"),
)
duration_adjustment = models.SmallIntegerField(
null=True,
blank=True,
help_text=_(
"Minutes. Used to keep track of reported minutes. This will be used as duration (+- duration_adjustment)"
),
)

user_id: int
task_id: int

class Meta: # type: ignore[reportIncompatibleVariab]
verbose_name = _("time entry")
verbose_name_plural = _("time entries")

def clean(self):
super().clean()

# Make sure duration is defined before having duration_adjustment
if self.duration_adjustment is not None and self.duration is None:
raise ValidationError(_("Duration needs to be defined before using Duration (Adjustment)"))

# Make sure duration + duration_adjustment doesn't have negative value
if self.duration is not None and self.duration_adjustment is not None:
if self.duration_adjustment + self.duration < 0:
raise ValidationError(_("Duration adjustment shouldn't generate negative duration"))

0 comments on commit 6c959dc

Please sign in to comment.