This commit is contained in:
@@ -22,10 +22,16 @@ class RegistryView(LoginRequiredMixin, ListView):
|
||||
context_object_name = 'items'
|
||||
|
||||
def get_queryset(self):
|
||||
# Позже здесь добавим: .filter(machine__in=request.user.profile.machines.all())
|
||||
# Сортируем: сначала статус (по алфавиту или логике choices),
|
||||
# затем по дате (свежие сверху), по станку и по номеру сделки
|
||||
return Item.objects.all().order_by('status', '-date', 'machine__name', 'deal__number')
|
||||
# Оптимизируем запросы, подгружая связанные данные сразу
|
||||
queryset = Item.objects.select_related('task', 'task__deal', 'task__material', 'machine').all()
|
||||
|
||||
# Если это оператор, показываем только задания для его станков
|
||||
if hasattr(self.request.user, 'profile') and self.request.user.profile.role == 'operator':
|
||||
user_machines = self.request.user.profile.machines.all()
|
||||
if user_machines.exists():
|
||||
queryset = queryset.filter(machine__in=user_machines)
|
||||
|
||||
return queryset.order_by('status', '-date', 'machine__name', 'task__deal__number')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
@@ -38,10 +44,11 @@ class RegistryView(LoginRequiredMixin, ListView):
|
||||
class ItemUpdateView(LoginRequiredMixin, UpdateView):
|
||||
model = Item
|
||||
template_name = 'shiftflow/item_detail.html'
|
||||
# Перечисляем поля, которые можно редактировать (укажи нужные)
|
||||
# Перечисляем поля, которые можно редактировать в сменке
|
||||
fields = [
|
||||
'drawing_name', 'machine', 'quantity_plan', 'quantity_fact',
|
||||
'material', 'size_value', 'status', 'is_synced_1c', 'extra_drawing'
|
||||
'machine', 'quantity_plan', 'quantity_fact',
|
||||
'status', 'is_synced_1c',
|
||||
'material_taken', 'usable_waste', 'scrap_weight'
|
||||
]
|
||||
context_object_name = 'item'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user