Добавлена поддержка единиц продажи в POS checkout
- При создании OrderItem теперь передаётся sales_unit из данных корзины - Это позволяет корректно рассчитывать total_amount для товаров с единицами продажи - Исправлена ошибка когда сумма заказа была 0 при использовании единиц продажи
This commit is contained in:
@@ -1475,12 +1475,23 @@ def pos_checkout(request):
|
||||
|
||||
if item_type == 'product':
|
||||
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(
|
||||
order=order,
|
||||
product=product,
|
||||
quantity=quantity,
|
||||
price=price,
|
||||
is_custom_price=False
|
||||
is_custom_price=False,
|
||||
sales_unit=sales_unit
|
||||
)
|
||||
elif item_type == 'kit':
|
||||
# Обычный комплект (не витринный)
|
||||
@@ -1529,6 +1540,8 @@ def pos_checkout(request):
|
||||
raise ValidationError(result['message'])
|
||||
|
||||
# 3. Пересчитываем итоговую стоимость
|
||||
# Обновляем объект заказа из БД, чтобы получить все связанные товары
|
||||
order.refresh_from_db()
|
||||
order.calculate_total()
|
||||
|
||||
# 4. Проводим платежи
|
||||
|
||||
Reference in New Issue
Block a user