diff --git a/myproject/pos/views.py b/myproject/pos/views.py index 199ca12..07f7507 100644 --- a/myproject/pos/views.py +++ b/myproject/pos/views.py @@ -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. Проводим платежи