Добавлена поддержка единиц продажи в POS checkout

- При создании OrderItem теперь передаётся sales_unit из данных корзины

- Это позволяет корректно рассчитывать total_amount для товаров с единицами продажи

- Исправлена ошибка когда сумма заказа была 0 при использовании единиц продажи
This commit is contained in:
2026-01-02 17:51:01 +03:00
parent eab4f8a4ae
commit f0327b264c

View File

@@ -1475,12 +1475,23 @@ def pos_checkout(request):
if item_type == 'product': if item_type == 'product':
product = Product.objects.get(id=item_id) product = Product.objects.get(id=item_id)
# Получаем sales_unit_id если передан
sales_unit_id = item_data.get('sales_unit_id')
sales_unit = None
if sales_unit_id:
from products.models import ProductSalesUnit
try:
sales_unit = ProductSalesUnit.objects.get(id=sales_unit_id, product=product)
except ProductSalesUnit.DoesNotExist:
pass
OrderItem.objects.create( OrderItem.objects.create(
order=order, order=order,
product=product, product=product,
quantity=quantity, quantity=quantity,
price=price, price=price,
is_custom_price=False is_custom_price=False,
sales_unit=sales_unit
) )
elif item_type == 'kit': elif item_type == 'kit':
# Обычный комплект (не витринный) # Обычный комплект (не витринный)
@@ -1529,6 +1540,8 @@ def pos_checkout(request):
raise ValidationError(result['message']) raise ValidationError(result['message'])
# 3. Пересчитываем итоговую стоимость # 3. Пересчитываем итоговую стоимость
# Обновляем объект заказа из БД, чтобы получить все связанные товары
order.refresh_from_db()
order.calculate_total() order.calculate_total()
# 4. Проводим платежи # 4. Проводим платежи