Ввел логику сделок через партии, дополнение 2
All checks were successful
Deploy MES Core / deploy (push) Successful in 12s
All checks were successful
Deploy MES Core / deploy (push) Successful in 12s
This commit is contained in:
@@ -2022,6 +2022,30 @@ class DealPlanningView(LoginRequiredMixin, TemplateView):
|
||||
deal = get_object_or_404(Deal.objects.select_related('company'), pk=self.kwargs['pk'])
|
||||
context['deal'] = deal
|
||||
|
||||
missing_ctx = None
|
||||
raw_missing = self.request.session.get('sf_missing_tech_process')
|
||||
if raw_missing and int(raw_missing.get('deal_id') or 0) == int(deal.id):
|
||||
entity_ids = [int(x) for x in (raw_missing.get('entity_ids') or []) if str(x).isdigit() or isinstance(x, int)]
|
||||
qs = ProductEntity.objects.filter(id__in=entity_ids).order_by('entity_type', 'drawing_number', 'name', 'id')
|
||||
items = []
|
||||
for e in qs:
|
||||
items.append({
|
||||
'entity': e,
|
||||
'url': f"{reverse_lazy('product_info', kwargs={'pk': int(e.id)})}?next={self.request.get_full_path()}" ,
|
||||
})
|
||||
|
||||
missing_ctx = {
|
||||
'items': items,
|
||||
'details_url': str(reverse_lazy('deal_missing_tech_process', kwargs={'pk': int(deal.id)})),
|
||||
'autoshow': not bool(raw_missing.get('shown')),
|
||||
}
|
||||
|
||||
if not bool(raw_missing.get('shown')):
|
||||
raw_missing['shown'] = True
|
||||
self.request.session['sf_missing_tech_process'] = raw_missing
|
||||
|
||||
context['missing_tech_process'] = missing_ctx
|
||||
|
||||
di = list(
|
||||
DealItem.objects.select_related('entity', 'entity__assembly_passport')
|
||||
.filter(deal=deal)
|
||||
@@ -2252,6 +2276,42 @@ class DealPlanningView(LoginRequiredMixin, TemplateView):
|
||||
return redirect('planning_deal', pk=deal_id)
|
||||
|
||||
|
||||
class DealMissingTechProcessView(LoginRequiredMixin, TemplateView):
|
||||
template_name = 'shiftflow/missing_techprocess.html'
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
roles = get_user_roles(request.user)
|
||||
if not has_any_role(roles, ['admin', 'technologist', 'prod_head']):
|
||||
return redirect('registry')
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
roles = get_user_roles(self.request.user)
|
||||
ctx['user_roles'] = sorted(roles)
|
||||
ctx['user_role'] = primary_role(roles)
|
||||
|
||||
deal = get_object_or_404(Deal.objects.select_related('company'), pk=int(self.kwargs['pk']))
|
||||
ctx['deal'] = deal
|
||||
|
||||
raw = self.request.session.get('sf_missing_tech_process')
|
||||
entity_ids = []
|
||||
if raw and int(raw.get('deal_id') or 0) == int(deal.id):
|
||||
entity_ids = [int(x) for x in (raw.get('entity_ids') or []) if str(x).isdigit() or isinstance(x, int)]
|
||||
|
||||
qs = ProductEntity.objects.filter(id__in=entity_ids).order_by('entity_type', 'drawing_number', 'name', 'id')
|
||||
rows = []
|
||||
next_url = str(reverse_lazy('planning_deal', kwargs={'pk': int(deal.id)}))
|
||||
for e in qs:
|
||||
rows.append({
|
||||
'entity': e,
|
||||
'url': f"{reverse_lazy('product_info', kwargs={'pk': int(e.id)})}?next={next_url}",
|
||||
})
|
||||
|
||||
ctx['items'] = rows
|
||||
return ctx
|
||||
|
||||
|
||||
class TaskItemsView(LoginRequiredMixin, TemplateView):
|
||||
template_name = 'shiftflow/task_items.html'
|
||||
|
||||
@@ -3442,18 +3502,16 @@ class DealBatchActionView(LoginRequiredMixin, View):
|
||||
return redirect(next_url)
|
||||
except ExplosionValidationError as ev:
|
||||
if getattr(ev, 'missing_route_entity_ids', None):
|
||||
bad = list(
|
||||
ProductEntity.objects.filter(id__in=list(ev.missing_route_entity_ids)).values_list('id', 'drawing_number', 'name')
|
||||
missing_ids = sorted({int(x) for x in (ev.missing_route_entity_ids or [])})
|
||||
request.session['sf_missing_tech_process'] = {
|
||||
'deal_id': int(deal_id),
|
||||
'entity_ids': missing_ids,
|
||||
'shown': False,
|
||||
}
|
||||
messages.error(
|
||||
request,
|
||||
'Нельзя запустить в производство: у части позиций отсутствует техпроцесс (операция seq=1).',
|
||||
)
|
||||
if bad:
|
||||
preview = ", ".join([f"/products/{eid}/info/ — {dn or '—'} {nm}" for eid, dn, nm in bad[:5]])
|
||||
more = '' if len(bad) <= 5 else f" и ещё {len(bad)-5}"
|
||||
messages.error(
|
||||
request,
|
||||
f'Нельзя запустить в производство: нет техпроцесса (операция seq=1) у: {preview}{more}. Добавь техпроцесс и повтори запуск.',
|
||||
)
|
||||
else:
|
||||
messages.error(request, 'Нельзя запустить в производство: у части позиций отсутствует техпроцесс. Добавь техпроцесс и повтори запуск.')
|
||||
return redirect(next_url)
|
||||
|
||||
bad = list(ProductEntity.objects.filter(id__in=list(getattr(ev, 'missing_material_ids', []) or [])).values_list('drawing_number', 'name'))
|
||||
|
||||
Reference in New Issue
Block a user