Статус выполнеия задания на деталь, мастер может менять станки
All checks were successful
Deploy MES Core / deploy (push) Successful in 9s

This commit is contained in:
2026-04-02 08:21:09 +03:00
parent d0289f6aec
commit 7cb00792ca
4 changed files with 79 additions and 11 deletions

View File

@@ -262,7 +262,7 @@ class DealPlanningView(LoginRequiredMixin, TemplateView):
deal = get_object_or_404(Deal.objects.select_related('company'), pk=self.kwargs['pk'])
context['deal'] = deal
tasks = ProductionTask.objects.filter(deal=deal).select_related('material').annotate(
tasks_qs = ProductionTask.objects.filter(deal=deal).select_related('material').annotate(
done_qty=Coalesce(Sum('items__quantity_fact'), 0),
planned_qty=Coalesce(
Sum(
@@ -281,6 +281,27 @@ class DealPlanningView(LoginRequiredMixin, TemplateView):
)
).order_by('-id')
tasks = list(tasks_qs)
for t in tasks:
need = int(t.quantity_ordered or 0)
done_qty = int(t.done_qty or 0)
planned_qty = int(t.planned_qty or 0)
if need > 0:
done_pct = int(round(done_qty * 100 / need))
plan_pct = int(round(planned_qty * 100 / need))
else:
done_pct = 0
plan_pct = 0
done_width = max(0, min(100, done_pct))
plan_width = max(0, min(100 - done_width, plan_pct))
t.done_pct = done_pct
t.plan_pct = plan_pct
t.done_width = done_width
t.plan_width = plan_width
context['tasks'] = tasks
context['machines'] = Machine.objects.all()
return context
@@ -695,6 +716,13 @@ class ItemUpdateView(LoginRequiredMixin, UpdateView):
scrap_weight_raw = (request.POST.get('scrap_weight') or '').strip()
status = request.POST.get('status', self.object.status)
machine_changed = False
if role == 'master':
machine_id = request.POST.get('machine')
if machine_id and machine_id.isdigit():
self.object.machine_id = int(machine_id)
machine_changed = True
# Разрешаем мастеру редактировать операторские поля всегда,
# оператору — только в процессе закрытия
if role == 'operator' and self.object.status != 'work':
@@ -765,7 +793,10 @@ class ItemUpdateView(LoginRequiredMixin, UpdateView):
return redirect('registry')
# Если статус не менялся (или не 'work'), просто сохраняем поля
self.object.save(update_fields=['material_taken', 'usable_waste', 'scrap_weight'])
update_fields = ['material_taken', 'usable_waste', 'scrap_weight']
if machine_changed:
update_fields.append('machine')
self.object.save(update_fields=update_fields)
return redirect('registry')
if role == 'clerk':