feat(pos): enhance product kit price handling and UI interaction
- Updated price aggregation logic in update_product_kit to include unit prices. - Improved terminal.js to allow inline editing of product prices in the kit. - Added parsePrice function for consistent price parsing across the application. - Ensured that the correct price is saved when creating or updating product kits.
This commit is contained in:
@@ -1371,12 +1371,19 @@ def update_product_kit(request, kit_id):
|
||||
if len(products) != len(product_ids):
|
||||
return JsonResponse({'success': False, 'error': 'Некоторые товары не найдены'}, status=400)
|
||||
|
||||
# Агрегируем количества
|
||||
# Агрегируем количества и цены
|
||||
aggregated_items = {}
|
||||
for item in items:
|
||||
product_id = item['product_id']
|
||||
quantity = Decimal(str(item['quantity']))
|
||||
aggregated_items[product_id] = aggregated_items.get(product_id, Decimal('0')) + quantity
|
||||
unit_price = item.get('unit_price')
|
||||
if product_id in aggregated_items:
|
||||
aggregated_items[product_id]['quantity'] += quantity
|
||||
else:
|
||||
aggregated_items[product_id] = {
|
||||
'quantity': quantity,
|
||||
'unit_price': Decimal(str(unit_price)) if unit_price is not None else None
|
||||
}
|
||||
|
||||
with transaction.atomic():
|
||||
# Получаем старый состав для сравнения
|
||||
@@ -1397,7 +1404,7 @@ def update_product_kit(request, kit_id):
|
||||
|
||||
for product_id in all_product_ids:
|
||||
old_qty = old_items.get(product_id, Decimal('0'))
|
||||
new_qty = aggregated_items.get(product_id, Decimal('0'))
|
||||
new_qty = aggregated_items.get(product_id, {}).get('quantity', Decimal('0'))
|
||||
diff = new_qty - old_qty
|
||||
|
||||
if diff > 0 and showcase:
|
||||
@@ -1436,13 +1443,15 @@ def update_product_kit(request, kit_id):
|
||||
|
||||
# Обновляем состав
|
||||
kit.kit_items.all().delete()
|
||||
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
|
||||
)
|
||||
|
||||
kit.recalculate_base_price()
|
||||
|
||||
Reference in New Issue
Block a user