Feature: справочник Статусы заказов, поле Статус в заказе клиента, оформление в списке (зелёный/песочный)

Made-with: Cursor
This commit is contained in:
2026-02-26 16:44:39 +00:00
parent 9d1bfadb96
commit 29cf44e278
15 changed files with 151 additions and 4 deletions

View File

@@ -82,7 +82,7 @@ SupplierOrderItemFormSetUpdate = inlineformset_factory(
class CustomerOrderForm(forms.ModelForm):
class Meta:
model = CustomerOrder
fields = ("date", "number", "order_kind", "organization", "client")
fields = ("date", "number", "order_kind", "organization", "client", "status")
widgets = {
"date": forms.DateInput(attrs={"type": "date"}, format="%Y-%m-%d"),
"number": forms.TextInput(attrs={"size": 15, "maxlength": 15}),

View File

@@ -0,0 +1,20 @@
# Generated by Django 5.2.11 on 2026-02-26 16:42
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('documents', '0003_quantity_integer_0_99'),
('references', '0002_order_status'),
]
operations = [
migrations.AddField(
model_name='customerorder',
name='status',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='customer_orders', to='references.orderstatus', verbose_name='Статус заказа'),
),
]

View File

@@ -4,7 +4,7 @@ from decimal import Decimal
from django.db import models
from django.db.models import Sum
from django.core.validators import MinValueValidator, MaxValueValidator
from references.models import Currency, OrderKind, Client, Organization, Supplier, Employee, CashAccount, Product
from references.models import Currency, OrderKind, Client, Organization, Supplier, Employee, CashAccount, Product, OrderStatus
class CustomerOrder(models.Model):
date = models.DateField("Дата")
@@ -12,6 +12,14 @@ class CustomerOrder(models.Model):
order_kind = models.ForeignKey(OrderKind, on_delete=models.PROTECT, verbose_name="Вид заказа")
organization = models.ForeignKey(Organization, on_delete=models.PROTECT, verbose_name="Организация")
client = models.ForeignKey(Client, on_delete=models.PROTECT, verbose_name="Клиент")
status = models.ForeignKey(
OrderStatus,
on_delete=models.PROTECT,
verbose_name="Статус заказа",
null=True,
blank=True,
related_name="customer_orders",
)
total_amount = models.DecimalField("Стоимость заказа", max_digits=18, decimal_places=2, default=Decimal("0"), editable=False)
author = models.ForeignKey(Employee, on_delete=models.SET_NULL, null=True, blank=True, verbose_name="Автор", related_name="customer_orders")
class Meta:

View File

@@ -8,7 +8,7 @@ from django.contrib import messages
from django.http import HttpResponseRedirect
from users.utils import get_author_employee
from references.models import Employee
from references.models import Employee, OrderStatus
from .models import (
CustomerOrder,
SupplierOrder,
@@ -67,6 +67,14 @@ class CustomerOrderCreate(LoginRequiredMixin, CreateView):
template_name = "documents/order_form.html"
success_url = reverse_lazy("documents:customer_order_list")
def get_initial(self):
initial = super().get_initial()
if not initial.get("status"):
in_progress = OrderStatus.objects.filter(name="В работе").first()
if in_progress:
initial["status"] = in_progress
return initial
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
ctx["formset"] = CustomerOrderItemFormSet(instance=self.object) if self.object and self.object.pk else CustomerOrderItemFormSet()