Fix: количество — только целое 0–99 (модели, формы, JS)
Made-with: Cursor
This commit is contained in:
@@ -13,22 +13,32 @@ from django.forms import inlineformset_factory
|
||||
|
||||
|
||||
class CustomerOrderItemForm(forms.ModelForm):
|
||||
quantity = forms.IntegerField(
|
||||
min_value=0,
|
||||
max_value=99,
|
||||
widget=forms.NumberInput(attrs={"size": 3, "min": 0, "max": 99, "step": 1, "style": "width: 4ch"}),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = CustomerOrderItem
|
||||
fields = ("product", "price", "currency", "quantity")
|
||||
widgets = {
|
||||
"price": forms.TextInput(attrs={"inputmode": "decimal", "class": "ws-price-input"}),
|
||||
"quantity": forms.NumberInput(attrs={"size": 3, "min": 0, "max": 99, "style": "width: 4ch"}),
|
||||
}
|
||||
|
||||
|
||||
class SupplierOrderItemForm(forms.ModelForm):
|
||||
quantity = forms.IntegerField(
|
||||
min_value=0,
|
||||
max_value=99,
|
||||
widget=forms.NumberInput(attrs={"size": 3, "min": 0, "max": 99, "step": 1, "style": "width: 4ch"}),
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = SupplierOrderItem
|
||||
fields = ("product", "price", "currency", "quantity")
|
||||
widgets = {
|
||||
"price": forms.TextInput(attrs={"inputmode": "decimal", "class": "ws-price-input"}),
|
||||
"quantity": forms.NumberInput(attrs={"size": 3, "min": 0, "max": 99, "style": "width: 4ch"}),
|
||||
}
|
||||
|
||||
|
||||
|
||||
25
app/documents/migrations/0003_quantity_integer_0_99.py
Normal file
25
app/documents/migrations/0003_quantity_integer_0_99.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Generated by Django 5.2.11 on 2026-02-26 15:47
|
||||
|
||||
import django.core.validators
|
||||
from decimal import Decimal
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('documents', '0002_add_customer_order_links'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customerorderitem',
|
||||
name='quantity',
|
||||
field=models.DecimalField(decimal_places=0, default=Decimal('1'), max_digits=18, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(99)], verbose_name='Количество'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='supplierorderitem',
|
||||
name='quantity',
|
||||
field=models.DecimalField(decimal_places=0, default=Decimal('1'), max_digits=18, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(99)], verbose_name='Количество'),
|
||||
),
|
||||
]
|
||||
@@ -3,6 +3,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
|
||||
|
||||
class CustomerOrder(models.Model):
|
||||
@@ -43,7 +44,13 @@ class CustomerOrderItem(models.Model):
|
||||
product = models.ForeignKey(Product, on_delete=models.PROTECT, verbose_name="Товар")
|
||||
price = models.DecimalField("Цена", max_digits=18, decimal_places=2, default=Decimal("0"))
|
||||
currency = models.ForeignKey(Currency, on_delete=models.PROTECT, verbose_name="Валюта", null=True, blank=True)
|
||||
quantity = models.DecimalField("Количество", max_digits=18, decimal_places=4, default=Decimal("1"))
|
||||
quantity = models.DecimalField(
|
||||
"Количество",
|
||||
max_digits=18,
|
||||
decimal_places=0,
|
||||
default=Decimal("1"),
|
||||
validators=[MinValueValidator(0), MaxValueValidator(99)],
|
||||
)
|
||||
amount = models.DecimalField("Стоимость", max_digits=18, decimal_places=2, default=Decimal("0"), editable=False)
|
||||
class Meta:
|
||||
verbose_name = "Строка заказа клиента"
|
||||
@@ -77,7 +84,13 @@ class SupplierOrderItem(models.Model):
|
||||
product = models.ForeignKey(Product, on_delete=models.PROTECT, verbose_name="Товар")
|
||||
price = models.DecimalField("Цена", max_digits=18, decimal_places=2, default=Decimal("0"))
|
||||
currency = models.ForeignKey(Currency, on_delete=models.PROTECT, verbose_name="Валюта", null=True, blank=True)
|
||||
quantity = models.DecimalField("Количество", max_digits=18, decimal_places=4, default=Decimal("1"))
|
||||
quantity = models.DecimalField(
|
||||
"Количество",
|
||||
max_digits=18,
|
||||
decimal_places=0,
|
||||
default=Decimal("1"),
|
||||
validators=[MinValueValidator(0), MaxValueValidator(99)],
|
||||
)
|
||||
amount = models.DecimalField("Стоимость", max_digits=18, decimal_places=2, default=Decimal("0"), editable=False)
|
||||
class Meta:
|
||||
verbose_name = "Строка заказа поставщику"
|
||||
|
||||
Reference in New Issue
Block a user