Обновления и новые функции: изменение шаблона клиента, обновление сигналов инвентаря, добавление снимков наборов и элементов заказа, обновление моделей заказов и продуктов

This commit is contained in:
2025-12-18 00:14:24 +03:00
parent 56725e8092
commit 7b32cdcebf
9 changed files with 547 additions and 87 deletions

View File

@@ -257,6 +257,50 @@ class ProductKit(BaseProductEntity):
"""Полное удаление из БД (необратимо!)"""
super().delete()
def create_snapshot(self):
"""
Создает снимок текущего состояния комплекта.
Используется при добавлении комплекта в заказ для сохранения истории.
Returns:
KitSnapshot: Созданный снимок с компонентами
"""
from orders.models import KitSnapshot, KitItemSnapshot
# Создаем снимок комплекта
snapshot = KitSnapshot.objects.create(
original_kit=self,
name=self.name,
sku=self.sku or '',
description=self.description or '',
base_price=self.base_price,
price=self.price,
sale_price=self.sale_price,
price_adjustment_type=self.price_adjustment_type,
price_adjustment_value=self.price_adjustment_value,
is_temporary=self.is_temporary,
)
# Создаем снимки компонентов
for item in self.kit_items.select_related('product', 'variant_group'):
product_price = Decimal('0')
if item.product:
product_price = item.product.actual_price or Decimal('0')
elif item.variant_group:
product_price = item.variant_group.price or Decimal('0')
KitItemSnapshot.objects.create(
kit_snapshot=snapshot,
original_product=item.product, # Сохраняем ссылку для резервирования
product_name=item.product.name if item.product else '',
product_sku=item.product.sku if item.product else '',
product_price=product_price,
variant_group_name=item.variant_group.name if item.variant_group else '',
quantity=item.quantity or Decimal('1'),
)
return snapshot
class KitItem(models.Model):
"""