Implement flexible order status management system
Features: - Created OrderStatus model for managing statuses per tenant - Added system-level statuses: draft, new, confirmed, in_assembly, in_delivery, completed, return, cancelled - Implemented CRUD views for managing order statuses - Created OrderStatusService with status transitions and business logic hooks - Updated Order model to use ForeignKey to OrderStatus - Added is_returned flag for tracking returned orders - Updated filters to work with new OrderStatus model - Created management command for status initialization - Added HTML templates for status list, form, and confirmation - Fixed views.py to use OrderStatus instead of removed STATUS_CHOICES 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from django import forms
|
||||
from django.forms import inlineformset_factory
|
||||
from .models import Order, OrderItem, Address
|
||||
from .models import Order, OrderItem, Address, OrderStatus
|
||||
from customers.models import Customer
|
||||
from shops.models import Shop
|
||||
from products.models import Product, ProductKit
|
||||
@@ -281,6 +281,81 @@ OrderItemFormSet = inlineformset_factory(
|
||||
)
|
||||
|
||||
|
||||
# === СТАТУСЫ ЗАКАЗОВ ===
|
||||
|
||||
class OrderStatusForm(forms.ModelForm):
|
||||
"""Форма для создания и редактирования статусов заказов"""
|
||||
|
||||
class Meta:
|
||||
model = OrderStatus
|
||||
fields = [
|
||||
'name',
|
||||
'code',
|
||||
'label',
|
||||
'color',
|
||||
'description',
|
||||
'is_positive_end',
|
||||
'is_negative_end',
|
||||
]
|
||||
widgets = {
|
||||
'name': forms.TextInput(attrs={
|
||||
'class': 'form-control',
|
||||
'placeholder': 'Например: Выполнен, В процессе'
|
||||
}),
|
||||
'code': forms.TextInput(attrs={
|
||||
'class': 'form-control',
|
||||
'placeholder': 'Например: completed, in_progress'
|
||||
}),
|
||||
'label': forms.TextInput(attrs={
|
||||
'class': 'form-control',
|
||||
'placeholder': 'Метка для отображения (опционально)'
|
||||
}),
|
||||
'color': forms.TextInput(attrs={
|
||||
'class': 'form-control',
|
||||
'type': 'color'
|
||||
}),
|
||||
'description': forms.Textarea(attrs={
|
||||
'class': 'form-control',
|
||||
'rows': 3,
|
||||
'placeholder': 'Описание статуса (опционально)'
|
||||
}),
|
||||
'is_positive_end': forms.CheckboxInput(attrs={
|
||||
'class': 'form-check-input'
|
||||
}),
|
||||
'is_negative_end': forms.CheckboxInput(attrs={
|
||||
'class': 'form-check-input'
|
||||
}),
|
||||
}
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
|
||||
# Нельзя быть одновременно положительным и отрицательным концом
|
||||
if cleaned_data.get('is_positive_end') and cleaned_data.get('is_negative_end'):
|
||||
raise forms.ValidationError(
|
||||
"Статус не может быть одновременно положительным и отрицательным концом"
|
||||
)
|
||||
|
||||
# Системные статусы нельзя редактировать код
|
||||
if self.instance.pk and self.instance.is_system:
|
||||
original_code = OrderStatus.objects.get(pk=self.instance.pk).code
|
||||
new_code = cleaned_data.get('code')
|
||||
if original_code != new_code:
|
||||
raise forms.ValidationError(
|
||||
"Нельзя менять код системного статуса"
|
||||
)
|
||||
|
||||
return cleaned_data
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Если редактируем системный статус - делаем код readonly
|
||||
if self.instance.pk and self.instance.is_system:
|
||||
self.fields['code'].widget.attrs['readonly'] = True
|
||||
self.fields['code'].help_text = "Код системного статуса нельзя менять"
|
||||
|
||||
|
||||
# === ВРЕМЕННЫЕ КОМПЛЕКТЫ ===
|
||||
|
||||
class TemporaryKitForm(forms.ModelForm):
|
||||
|
||||
Reference in New Issue
Block a user