feat(pos): фиксировать цены товаров в витринных комплектах

- Добавлено поле KitItem.unit_price для хранения зафиксированной цены
- Витринные комплекты больше не обновляются при изменении цен товаров
- Добавлен красный индикатор на карточке если цена неактуальна
- Добавлен warning в модалке редактирования с кнопкой "Актуализировать"

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-19 15:59:44 +03:00
parent 392471ff06
commit 2778796118
6 changed files with 195 additions and 19 deletions

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.0.10 on 2026-01-19 12:05
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('products', '0003_remove_unit_from_sales_unit'),
]
operations = [
migrations.AddField(
model_name='kititem',
name='unit_price',
field=models.DecimalField(blank=True, decimal_places=2, help_text='Если задана, используется эта цена вместо актуальной цены товара. Применяется для временных витринных комплектов.', max_digits=10, null=True, verbose_name='Цена за единицу (зафиксированная)'),
),
]

View File

@@ -162,13 +162,17 @@ class ProductKit(BaseProductEntity):
total = Decimal('0')
for item in self.kit_items.all():
qty = item.quantity or Decimal('1')
if item.product:
actual_price = item.product.actual_price or Decimal('0')
qty = item.quantity or Decimal('1')
total += actual_price * qty
# Используем зафиксированную цену если есть, иначе актуальную цену товара
if item.unit_price is not None:
unit_price = item.unit_price
else:
unit_price = item.product.actual_price or Decimal('0')
total += unit_price * qty
elif item.variant_group:
# Для variant_group unit_price не используется (только для продуктов)
actual_price = item.variant_group.price or Decimal('0')
qty = item.quantity or Decimal('1')
total += actual_price * qty
self.base_price = total
@@ -395,6 +399,14 @@ class KitItem(models.Model):
verbose_name="Группа вариантов"
)
quantity = models.DecimalField(max_digits=10, decimal_places=3, null=True, blank=True, verbose_name="Количество")
unit_price = models.DecimalField(
max_digits=10,
decimal_places=2,
null=True,
blank=True,
verbose_name="Цена за единицу (зафиксированная)",
help_text="Если задана, используется эта цена вместо актуальной цены товара. Применяется для временных витринных комплектов."
)
class Meta:
verbose_name = "Компонент комплекта"

View File

@@ -111,6 +111,10 @@ def make_kit_permanent(kit: ProductKit) -> bool:
kit.is_temporary = False
kit.order = None # Отвязываем от заказа
kit.save()
# Очищаем зафиксированные цены - теперь будет использоваться актуальная цена товаров
kit.kit_items.update(unit_price=None)
return True