fix: dohvat mjesecnih racuna za troskove
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

Uklanja ovisnost o workOrders.invoices i dohvaća račune direktno kroz API filtriran po mjesecu. Dodaje i display code putnog naloga u serializer kako bi prikaz u izvještaju ostao potpun.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
mariomitte
2026-07-31 17:05:56 +02:00
parent 3a33751012
commit 882e255523
4 changed files with 70 additions and 25 deletions

View File

@@ -3126,16 +3126,30 @@ class WorkOrderInvoiceViewSet(viewsets.ModelViewSet):
def get_queryset(self):
user = self.request.user
work_order_id = self.request.query_params.get('work_order_id')
year = self.request.query_params.get('year')
month = self.request.query_params.get('month')
qs = WorkOrderInvoice.objects.select_related('work_order', 'work_order__vehicle', 'created_by').filter(is_active=True)
if year and month:
try:
year_value = int(year)
month_value = int(month)
except (TypeError, ValueError):
year_value = None
month_value = None
if year_value and month_value and 1 <= month_value <= 12:
qs = qs.filter(
work_order__work_order_tasks__scheduled_date__year=year_value,
work_order__work_order_tasks__scheduled_date__month=month_value,
)
if user.is_staff:
if work_order_id:
qs = qs.filter(work_order_id=work_order_id)
return qs
return qs.distinct()
allowed_orders = _work_orders_queryset_for_user(user).values('id')
qs = qs.filter(work_order_id__in=allowed_orders)
if work_order_id:
qs = qs.filter(work_order_id=work_order_id)
return qs
return qs.distinct()
def get_serializer_context(self):
context = super().get_serializer_context()