Теперь сделки на странице планирования
All checks were successful
Deploy MES Core / deploy (push) Successful in 10s
All checks were successful
Deploy MES Core / deploy (push) Successful in 10s
This commit is contained in:
@@ -232,7 +232,37 @@ class PlanningView(LoginRequiredMixin, TemplateView):
|
||||
role = profile.role if profile else ('admin' if self.request.user.is_superuser else 'operator')
|
||||
context['user_role'] = role
|
||||
|
||||
tasks = ProductionTask.objects.select_related('deal', 'material').annotate(
|
||||
status = (self.request.GET.get('status') or 'work').strip()
|
||||
allowed = {k for k, _ in Deal.STATUS_CHOICES}
|
||||
if status not in allowed:
|
||||
status = 'work'
|
||||
|
||||
context['selected_status'] = status
|
||||
context['deals'] = Deal.objects.select_related('company').filter(status=status).order_by('-id')
|
||||
context['companies'] = Company.objects.all().order_by('name')
|
||||
return context
|
||||
|
||||
|
||||
class DealPlanningView(LoginRequiredMixin, TemplateView):
|
||||
template_name = 'shiftflow/planning_deal.html'
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
profile = getattr(request.user, 'profile', None)
|
||||
role = profile.role if profile else ('admin' if request.user.is_superuser else 'operator')
|
||||
if role not in ['admin', 'technologist']:
|
||||
return redirect('registry')
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
profile = getattr(self.request.user, 'profile', None)
|
||||
role = profile.role if profile else ('admin' if self.request.user.is_superuser else 'operator')
|
||||
context['user_role'] = role
|
||||
|
||||
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(
|
||||
done_qty=Coalesce(Sum('items__quantity_fact'), 0),
|
||||
planned_qty=Coalesce(
|
||||
Sum(
|
||||
@@ -249,7 +279,7 @@ class PlanningView(LoginRequiredMixin, TemplateView):
|
||||
F('quantity_ordered') - F('done_qty') - F('planned_qty'),
|
||||
output_field=IntegerField(),
|
||||
)
|
||||
)
|
||||
).order_by('-id')
|
||||
|
||||
context['tasks'] = tasks
|
||||
context['machines'] = Machine.objects.all()
|
||||
@@ -284,6 +314,10 @@ class PlanningAddView(LoginRequiredMixin, View):
|
||||
is_synced_1c=False,
|
||||
)
|
||||
|
||||
next_url = request.POST.get('next') or ''
|
||||
if next_url.startswith('/planning/deal/'):
|
||||
return redirect(next_url)
|
||||
|
||||
return redirect('planning')
|
||||
|
||||
|
||||
@@ -292,6 +326,13 @@ class ProductionTaskCreateView(LoginRequiredMixin, FormView):
|
||||
form_class = ProductionTaskCreateForm
|
||||
success_url = reverse_lazy('planning')
|
||||
|
||||
def get_initial(self):
|
||||
initial = super().get_initial()
|
||||
deal_id = self.request.GET.get('deal')
|
||||
if deal_id and str(deal_id).isdigit():
|
||||
initial['deal'] = int(deal_id)
|
||||
return initial
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
profile = getattr(request.user, 'profile', None)
|
||||
role = profile.role if profile else ('admin' if request.user.is_superuser else 'operator')
|
||||
@@ -339,6 +380,7 @@ class DealDetailView(LoginRequiredMixin, View):
|
||||
return JsonResponse({
|
||||
'id': deal.id,
|
||||
'number': deal.number,
|
||||
'status': deal.status,
|
||||
'company_id': deal.company_id,
|
||||
'description': deal.description or '',
|
||||
})
|
||||
@@ -355,6 +397,7 @@ class DealUpsertView(LoginRequiredMixin, View):
|
||||
number = (request.POST.get('number') or '').strip()
|
||||
description = (request.POST.get('description') or '').strip()
|
||||
company_id = request.POST.get('company_id')
|
||||
status = (request.POST.get('status') or 'work').strip()
|
||||
|
||||
if not number:
|
||||
return JsonResponse({'error': 'number_required'}, status=400)
|
||||
@@ -365,6 +408,11 @@ class DealUpsertView(LoginRequiredMixin, View):
|
||||
else:
|
||||
deal, _ = Deal.objects.get_or_create(number=number)
|
||||
|
||||
allowed = {k for k, _ in Deal.STATUS_CHOICES}
|
||||
if status not in allowed:
|
||||
status = 'work'
|
||||
|
||||
deal.status = status
|
||||
deal.description = description
|
||||
if company_id and str(company_id).isdigit():
|
||||
deal.company_id = int(company_id)
|
||||
|
||||
Reference in New Issue
Block a user