Подправил реестр сменных заданий, права опрератора, добавил поле для хранения сколько сделано (для оператора) подправил ui в окне карточки сменного задания
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:
@@ -562,9 +562,9 @@ class RegistryView(LoginRequiredMixin, ListView):
|
||||
workitems = list(work_qs.order_by('-date', 'deal__number', 'id')[:2000])
|
||||
for wi in workitems:
|
||||
plan = int(wi.quantity_plan or 0)
|
||||
done = int(wi.quantity_done or 0)
|
||||
reported = int(getattr(wi, 'quantity_reported', 0) or 0)
|
||||
if plan > 0:
|
||||
pct = int(round(done * 100 / plan))
|
||||
pct = int(round(reported * 100 / plan))
|
||||
else:
|
||||
pct = 0
|
||||
wi.fact_pct = pct
|
||||
@@ -770,7 +770,7 @@ class PaintingPlanAddView(LoginRequiredMixin, View):
|
||||
class WorkItemUpdateView(LoginRequiredMixin, View):
|
||||
def post(self, request, *args, **kwargs):
|
||||
profile = getattr(request.user, 'profile', None)
|
||||
roles = get_user_roles(request.user)
|
||||
roles = get_user_group_roles(request.user)
|
||||
role = primary_role(roles)
|
||||
is_readonly = bool(getattr(profile, 'is_readonly', False)) if profile else False
|
||||
|
||||
@@ -828,7 +828,8 @@ class WorkItemUpdateView(LoginRequiredMixin, View):
|
||||
return redirect(next_url)
|
||||
|
||||
qty_plan = parse_int(request.POST.get('quantity_plan'))
|
||||
qty_done = parse_int(request.POST.get('quantity_done'))
|
||||
qty_reported = parse_int(request.POST.get('quantity_reported'))
|
||||
qty_done = parse_int(request.POST.get('quantity_done')) if role in ['admin', 'technologist'] else None
|
||||
workshop_id = parse_int(request.POST.get('workshop_id'))
|
||||
machine_id = parse_int(request.POST.get('machine_id'))
|
||||
date_raw = (request.POST.get('date') or '').strip()
|
||||
@@ -871,15 +872,14 @@ class WorkItemUpdateView(LoginRequiredMixin, View):
|
||||
wi.quantity_plan = qty_plan
|
||||
changed_fields.append('quantity_plan')
|
||||
|
||||
if qty_done is not None and qty_done >= 0:
|
||||
# Комментарий: факт не должен превышать план по строке, иначе ломается «доступно к покраске».
|
||||
if qty_reported is not None and qty_reported >= 0:
|
||||
plan_val = int((qty_plan if qty_plan is not None else wi.quantity_plan) or 0)
|
||||
if plan_val > 0 and qty_done > plan_val:
|
||||
messages.error(request, f'Факт ({qty_done}) не может быть больше плана ({plan_val}).')
|
||||
if plan_val > 0 and qty_reported > plan_val:
|
||||
messages.error(request, f'Прогресс ({qty_reported}) не может быть больше плана ({plan_val}).')
|
||||
return redirect(next_url)
|
||||
|
||||
wi.quantity_done = qty_done
|
||||
changed_fields.append('quantity_done')
|
||||
wi.quantity_reported = qty_reported
|
||||
changed_fields.append('quantity_reported')
|
||||
|
||||
if machine_id is not None and role in ['admin', 'technologist', 'master']:
|
||||
wi.machine_id = machine_id
|
||||
@@ -1399,17 +1399,18 @@ class WorkItemDetailView(LoginRequiredMixin, TemplateView):
|
||||
template_name = 'shiftflow/workitem_detail.html'
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
roles = get_user_roles(request.user)
|
||||
roles = get_user_group_roles(request.user)
|
||||
if not has_any_role(roles, ['admin', 'technologist', 'master', 'clerk', 'operator', 'observer', 'prod_head', 'director']):
|
||||
return redirect('registry')
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
ctx = 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')
|
||||
roles = get_user_group_roles(self.request.user)
|
||||
role = primary_role(roles)
|
||||
ctx['user_role'] = role
|
||||
ctx['can_edit_entity'] = role in ['admin', 'technologist']
|
||||
ctx['user_roles'] = sorted(roles)
|
||||
ctx['can_edit_entity'] = has_any_role(roles, ['admin', 'technologist'])
|
||||
|
||||
wi = get_object_or_404(
|
||||
WorkItem.objects.select_related(
|
||||
|
||||
Reference in New Issue
Block a user