fix: omoguci rucni unos vremena u mjesecnom izvjestaju
Some checks failed
ERP CI/CD Pipeline / test (push) Has been cancelled
ERP CI/CD Pipeline / Deploy (server git pull + compose) (push) Has been cancelled

Dodaje uredski unos pocetka i kraja rada u sidebaru mjesecnog izvjestaja servisera i automatski racuna redovan rad iz unesenog raspona. Zadrzava postojece predpopunjavanje za rad u uredu i validira neispravan vremenski raspon.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
mariomitte
2026-07-31 17:37:44 +02:00
parent 882e255523
commit 51a65f9b80
3 changed files with 169 additions and 50 deletions

View File

@@ -748,25 +748,47 @@ class MonthlyServicerDayEntry(BaseModel):
def __str__(self):
return f"{self.user_id} @ {self.entry_date} ({self.entry_type})"
def _calculate_regular_hours(self, start_time, end_time):
if start_time is None or end_time is None:
return Decimal('8.00')
start_minutes = (start_time.hour * 60) + start_time.minute + (start_time.second / 60)
end_minutes = (end_time.hour * 60) + end_time.minute + (end_time.second / 60)
if end_minutes <= start_minutes:
raise ValidationError({
'end_time': _('Kraj rada mora biti nakon početka rada.'),
})
hours = Decimal(str((end_minutes - start_minutes) / 60)).quantize(Decimal('0.01'))
return hours
def apply_defaults(self):
start_time = self.start_time
end_time = self.end_time
if self.entry_type == 'office':
self.description = 'Rad u uredu'
self.location = 'Zagreb (ured)'
self.start_time = time(8, 0)
self.end_time = time(16, 0)
self.regular_hours = Decimal('8.00')
self.overtime_hours = Decimal('0.00')
return
if self.entry_type == 'vacation':
self.description = 'Godišnji odmor'
if not self.description:
self.description = 'Rad u uredu'
if not self.location:
self.location = 'Zagreb (ured)'
if start_time is None:
start_time = time(8, 0)
if end_time is None:
end_time = time(16, 0)
elif self.entry_type == 'vacation':
if not self.description:
self.description = 'Godišnji odmor'
self.location = self.location or ''
elif self.entry_type == 'sick_leave':
self.description = 'Bolovanje'
if not self.description:
self.description = 'Bolovanje'
self.location = self.location or ''
else:
self.location = self.location or ''
self.location = ''
self.start_time = None
self.end_time = None
self.regular_hours = Decimal('8.00')
self.start_time = start_time
self.end_time = end_time
self.regular_hours = self._calculate_regular_hours(start_time, end_time)
self.overtime_hours = Decimal('0.00')
def clean(self):

View File

@@ -250,8 +250,6 @@ class MonthlyServicerDayEntrySerializer(serializers.ModelSerializer):
'id',
'description',
'location',
'start_time',
'end_time',
'regular_hours',
'overtime_hours',
'created_at',