Do not save non-durations as manual
Django CI/CD / test (push) Successful in 1m13s Details
Django CI/CD / build-and-push (push) Successful in 2m22s Details

This commit is contained in:
Lukáš Kucharczyk 2024-07-22 08:36:36 +02:00
parent e174850262
commit ffc4edb1e0
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
1 changed files with 4 additions and 1 deletions

View File

@ -203,7 +203,7 @@ class Session(models.Model):
def duration_seconds(self) -> timedelta:
manual = timedelta(0)
calculated = timedelta(0)
if self.is_manual():
if self.is_manual() and isinstance(self.is_manual, timedelta):
manual = self.duration_manual
if self.timestamp_end != None and self.timestamp_start != None:
calculated = self.timestamp_end - self.timestamp_start
@ -226,6 +226,9 @@ class Session(models.Model):
else:
self.duration_calculated = timedelta(0)
if not isinstance(self.duration_manual, timedelta):
self.duration_manual = timedelta(0)
if not self.device:
default_device, _ = Device.objects.get_or_create(
type=Device.UNKNOWN, defaults={"name": "Unknown"}