fix(pos): сохранение изменённой цены товара при создании витринного комплекта
При изменении цены товара в корзине через модалку, витринный комплект теперь сохраняется с правильной ценой, а не с ценой из каталога: - terminal.js: передача unit_price при создании витринного комплекта - views.py: обработка и сохранение unit_price из корзины в KitItem - kits.py: использование item.unit_price в ProductKit.save() при расчёте base_price
This commit is contained in:
@@ -2379,7 +2379,8 @@ document.getElementById('confirmCreateTempKit').onclick = async () => {
|
||||
if (item.type === 'product') {
|
||||
items.push({
|
||||
product_id: item.id,
|
||||
quantity: item.qty
|
||||
quantity: item.qty,
|
||||
unit_price: item.price // Передаём изменённую цену из корзины
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1163,15 +1163,20 @@ def create_temp_kit_to_showcase(request):
|
||||
}, status=400)
|
||||
|
||||
# Агрегируем дубликаты (если один товар добавлен несколько раз)
|
||||
# Сохраняем также цену из корзины (unit_price)
|
||||
aggregated_items = {}
|
||||
for item in items:
|
||||
product_id = item['product_id']
|
||||
quantity = Decimal(str(item['quantity']))
|
||||
|
||||
unit_price = item.get('unit_price') # Цена из корзины (может быть изменена пользователем)
|
||||
|
||||
if product_id in aggregated_items:
|
||||
aggregated_items[product_id] += quantity
|
||||
aggregated_items[product_id]['quantity'] += quantity
|
||||
else:
|
||||
aggregated_items[product_id] = quantity
|
||||
aggregated_items[product_id] = {
|
||||
'quantity': quantity,
|
||||
'unit_price': Decimal(str(unit_price)) if unit_price is not None else None
|
||||
}
|
||||
|
||||
# Создаём временный комплект и резервируем на витрину
|
||||
with transaction.atomic():
|
||||
@@ -1189,15 +1194,17 @@ def create_temp_kit_to_showcase(request):
|
||||
)
|
||||
|
||||
# 2. Создаём KitItem для каждого товара из корзины
|
||||
for product_id, quantity in aggregated_items.items():
|
||||
for product_id, item_data in aggregated_items.items():
|
||||
product = products[product_id]
|
||||
# Используем цену из корзины, если передана, иначе из каталога
|
||||
final_price = item_data['unit_price'] if item_data['unit_price'] is not None else product.actual_price
|
||||
KitItem.objects.create(
|
||||
kit=kit,
|
||||
product=product,
|
||||
quantity=quantity,
|
||||
unit_price=product.actual_price # Фиксируем цену для временного комплекта
|
||||
quantity=item_data['quantity'],
|
||||
unit_price=final_price # Фиксируем цену из корзины (с учётом изменений пользователя)
|
||||
)
|
||||
|
||||
|
||||
# 3. Пересчитываем цену комплекта
|
||||
kit.recalculate_base_price()
|
||||
|
||||
@@ -1264,7 +1271,7 @@ def create_temp_kit_to_showcase(request):
|
||||
f' Название: {request.POST.get("kit_name")}\n'
|
||||
f' Витрина ID: {request.POST.get("showcase_id")}\n'
|
||||
f' Товары: {request.POST.get("items")}\n'
|
||||
f' Пользователь: {request.user.username}\n'
|
||||
f' Пользователь: {str(request.user)}\n'
|
||||
f' Ошибка: {str(e)}',
|
||||
exc_info=True
|
||||
)
|
||||
|
||||
@@ -230,7 +230,11 @@ class ProductKit(BaseProductEntity):
|
||||
qty = item.quantity or Decimal('1')
|
||||
total += actual_price * qty
|
||||
elif item.product:
|
||||
actual_price = item.product.actual_price or Decimal('0')
|
||||
# Используем зафиксированную цену (unit_price) если задана, иначе актуальную цену товара
|
||||
if item.unit_price is not None:
|
||||
actual_price = item.unit_price
|
||||
else:
|
||||
actual_price = item.product.actual_price or Decimal('0')
|
||||
qty = item.quantity or Decimal('1')
|
||||
total += actual_price * qty
|
||||
elif item.variant_group:
|
||||
|
||||
Reference in New Issue
Block a user