fix: add total rows to service-record hours tables
Add a final 'Ukupno' row to the exported work-hours tables so PDF and DOCX service records include both work and travel totals. This keeps the generated reports aligned with the underlying task data. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -497,6 +497,67 @@ class WorkOrderImagesEndpointTests(TestCase):
|
||||
self.assertIn('MT170726', text)
|
||||
self.assertNotIn('MT150726', text)
|
||||
|
||||
def test_service_records_docx_includes_work_and_travel_total_row(self):
|
||||
TaskWorkHoursTable.objects.create(
|
||||
task=self.task,
|
||||
data={
|
||||
'rows': [{
|
||||
'day': 'PON',
|
||||
'date': '01.12.2033',
|
||||
'work_time_from': '08:00',
|
||||
'work_time_to': '12:30',
|
||||
'travel_time_from': '07:00',
|
||||
'travel_time_to': '08:00',
|
||||
'break_hours': '0,5',
|
||||
'work_hours': '4,0',
|
||||
'travel_hours': '1,0',
|
||||
'departure_place': 'Zagreb',
|
||||
'arrival_place': 'Split',
|
||||
'vehicle_km': '120',
|
||||
}]
|
||||
},
|
||||
)
|
||||
|
||||
response = self.client.get(f"/api/fleet/work-orders/{self.work_order.pk}/service-records-docx/?task_id={self.task.pk}")
|
||||
self.assertEqual(response.status_code, 200, response.content)
|
||||
|
||||
archive = zipfile.ZipFile(BytesIO(response.content))
|
||||
document_xml = archive.read('word/document.xml').decode('utf-8', errors='ignore')
|
||||
self.assertIn('Ukupno', document_xml)
|
||||
self.assertIn('4,0', document_xml)
|
||||
self.assertIn('1,0', document_xml)
|
||||
|
||||
def test_service_records_pdf_includes_work_and_travel_total_row(self):
|
||||
TaskWorkHoursTable.objects.create(
|
||||
task=self.task,
|
||||
data={
|
||||
'rows': [{
|
||||
'day': 'PON',
|
||||
'date': '01.12.2033',
|
||||
'work_time_from': '08:00',
|
||||
'work_time_to': '12:30',
|
||||
'travel_time_from': '07:00',
|
||||
'travel_time_to': '08:00',
|
||||
'break_hours': '0,5',
|
||||
'work_hours': '4,0',
|
||||
'travel_hours': '1,0',
|
||||
'departure_place': 'Zagreb',
|
||||
'arrival_place': 'Split',
|
||||
'vehicle_km': '120',
|
||||
}]
|
||||
},
|
||||
)
|
||||
|
||||
response = self.client.get(f"/api/fleet/work-orders/{self.work_order.pk}/service-records-pdf/?task_id={self.task.pk}")
|
||||
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('UKUPNO', text)
|
||||
self.assertIn('4,0', text)
|
||||
self.assertIn('1,0', text)
|
||||
|
||||
def test_monthly_service_tasks_archive_returns_zip_with_task_docx(self):
|
||||
response = self.client.get('/api/fleet/reports/monthly-service-tasks-archive/?year=2033&month=12')
|
||||
self.assertEqual(response.status_code, 200, response.content)
|
||||
|
||||
Reference in New Issue
Block a user