From 6c959dc4ef708185568c2d5859dd11947f38a8e0 Mon Sep 17 00:00:00 2001 From: thenav56 Date: Thu, 22 Aug 2024 17:16:46 +0545 Subject: [PATCH] Add support for duration adjustment for reporting --- apps/track/admin.py | 1 + .../0014_timeentry_duration_adjustment.py | 22 +++++++++++++++++++ apps/track/models.py | 20 +++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 apps/track/migrations/0014_timeentry_duration_adjustment.py diff --git a/apps/track/admin.py b/apps/track/admin.py index 296ab90..5124ec1 100644 --- a/apps/track/admin.py +++ b/apps/track/admin.py @@ -89,6 +89,7 @@ class TimeEntryAdmin(admin.ModelAdmin): "type", "date", "duration", + "duration_adjustment", "status", ) diff --git a/apps/track/migrations/0014_timeentry_duration_adjustment.py b/apps/track/migrations/0014_timeentry_duration_adjustment.py new file mode 100644 index 0000000..1d76caf --- /dev/null +++ b/apps/track/migrations/0014_timeentry_duration_adjustment.py @@ -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, + ), + ), + ] diff --git a/apps/track/models.py b/apps/track/models.py index edfe145..0a36855 100644 --- a/apps/track/models.py +++ b/apps/track/models.py @@ -1,3 +1,4 @@ +from django.core.exceptions import ValidationError from django.db import models from django.utils.translation import gettext_lazy as _ @@ -71,6 +72,13 @@ 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 @@ -78,3 +86,15 @@ class Status(models.IntegerChoices): 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"))