fix: sync multi-day work hours accounting
Aggregate task work-hour rows into travel-cost calculations and monthly servicer reporting, and keep the frontend calendar aligned with the task work-hours source.
This commit is contained in:
@@ -24,8 +24,9 @@ from modules.fleet.models import (
|
||||
GeneratedFleetArchive,
|
||||
VehicleNotification,
|
||||
)
|
||||
from modules.task_management.models import Task
|
||||
from modules.task_management.models import Task, TaskWorkHoursTable
|
||||
from modules.fleet.tasks import build_monthly_archive_cached_task
|
||||
from modules.fleet.views import _build_monthly_servicer_report_rows
|
||||
|
||||
|
||||
def create_test_image(filename='test.jpg', size=(40, 40), color='red'):
|
||||
@@ -467,6 +468,73 @@ class WorkOrderImagesEndpointTests(TestCase):
|
||||
self.assertIn('MT150726.work-order.pdf', names)
|
||||
self.assertTrue(any(name.startswith('Racuni/MT150726/') for name in names), names)
|
||||
|
||||
def test_work_order_pdf_travel_expense_uses_task_work_hours_table(self):
|
||||
TaskWorkHoursTable.objects.create(
|
||||
task=self.task,
|
||||
data={
|
||||
'rows': [
|
||||
{
|
||||
'date': '24.12.2033',
|
||||
'work_time_from': '08:00',
|
||||
'work_time_to': '16:00',
|
||||
'travel_hours': '2',
|
||||
'work_hours': '6',
|
||||
},
|
||||
{
|
||||
'date': '25.12.2033',
|
||||
'work_time_from': '09:00',
|
||||
'work_time_to': '15:00',
|
||||
'travel_hours': '1,5',
|
||||
'work_hours': '4',
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
response = self.client.get(f'/api/fleet/work-orders/{self.work_order.pk}/pdf/')
|
||||
self.assertEqual(response.status_code, 200, response.content)
|
||||
self.assertEqual(response['Content-Type'], 'application/pdf')
|
||||
|
||||
reader = PdfReader(BytesIO(response.content))
|
||||
text = '\n'.join((page.extract_text() or '') for page in reader.pages)
|
||||
self.assertIn('24.12.2033.', text)
|
||||
self.assertIn('25.12.2033.', text)
|
||||
self.assertIn('13,5', text)
|
||||
self.assertIn('0,6', text)
|
||||
|
||||
def test_monthly_servicer_report_rows_use_task_work_hours_table_hours(self):
|
||||
TaskWorkHoursTable.objects.create(
|
||||
task=self.task,
|
||||
data={
|
||||
'rows': [
|
||||
{
|
||||
'date': '24.12.2033',
|
||||
'work_time_from': '08:00',
|
||||
'work_time_to': '16:00',
|
||||
'travel_hours': '2',
|
||||
'work_hours': '6',
|
||||
},
|
||||
{
|
||||
'date': '25.12.2033',
|
||||
'work_time_from': '09:00',
|
||||
'work_time_to': '15:00',
|
||||
'travel_hours': '1,5',
|
||||
'work_hours': '4',
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
rows = _build_monthly_servicer_report_rows(self.user, 2033, 12)
|
||||
row_by_date = {row['date']: row for row in rows if row['source'] == 'task'}
|
||||
self.assertIn(date(2033, 12, 24), row_by_date)
|
||||
self.assertIn(date(2033, 12, 25), row_by_date)
|
||||
self.assertEqual(row_by_date[date(2033, 12, 24)]['redovan_rad'], '8')
|
||||
self.assertEqual(row_by_date[date(2033, 12, 24)]['prekovremeni'], '8')
|
||||
self.assertEqual(row_by_date[date(2033, 12, 25)]['redovan_rad'], '8')
|
||||
self.assertEqual(row_by_date[date(2033, 12, 25)]['prekovremeni'], '5.5')
|
||||
|
||||
|
||||
def test_monthly_service_tasks_archive_request_creates_ready_download_with_notification(self):
|
||||
response = self.client.post(
|
||||
'/api/fleet/reports/monthly-service-tasks-archive-request/',
|
||||
|
||||
Reference in New Issue
Block a user