diff --git a/myproject/pos/static/pos/js/terminal.js b/myproject/pos/static/pos/js/terminal.js index 52e6bac..8d94620 100644 --- a/myproject/pos/static/pos/js/terminal.js +++ b/myproject/pos/static/pos/js/terminal.js @@ -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 // Передаём изменённую цену из корзины }); } }); diff --git a/myproject/pos/views.py b/myproject/pos/views.py index c90da65..cdd39bf 100644 --- a/myproject/pos/views.py +++ b/myproject/pos/views.py @@ -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 ) diff --git a/myproject/products/models/kits.py b/myproject/products/models/kits.py index bdf0837..1494d64 100644 --- a/myproject/products/models/kits.py +++ b/myproject/products/models/kits.py @@ -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: