diff --git a/myproject/inventory/services/sale_processor.py b/myproject/inventory/services/sale_processor.py index 8900b1a..4991156 100644 --- a/myproject/inventory/services/sale_processor.py +++ b/myproject/inventory/services/sale_processor.py @@ -36,11 +36,17 @@ class SaleProcessor: # Определяем цену продажи из заказа или из товара if order and reservation.order_item: item = reservation.order_item + # Цена за единицу с учётом скидки + if item.discount_amount and item.quantity > 0: + subtotal = Decimal(str(item.price)) * Decimal(str(item.quantity)) + price_with_discount = (subtotal - Decimal(str(item.discount_amount))) / Decimal(str(item.quantity)) + else: + price_with_discount = Decimal(str(item.price)) # Пересчитываем цену в базовые единицы if item.sales_unit and item.conversion_factor_snapshot: - sale_price = Decimal(str(item.price)) * item.conversion_factor_snapshot + sale_price = price_with_discount * item.conversion_factor_snapshot else: - sale_price = item.price + sale_price = price_with_discount else: # Цена из товара sale_price = reservation.product.actual_price or Decimal('0') diff --git a/myproject/inventory/signals.py b/myproject/inventory/signals.py index f4ae3d1..5e032f3 100644 --- a/myproject/inventory/signals.py +++ b/myproject/inventory/signals.py @@ -480,11 +480,18 @@ def create_sale_on_order_completion(sender, instance, created, **kwargs): f"Используем quantity_in_base_units: {sale_quantity}" ) + # Цена за единицу с учётом скидки + if item.discount_amount and item.quantity > 0: + subtotal = Decimal(str(item.price)) * Decimal(str(item.quantity)) + price_with_discount = (subtotal - Decimal(str(item.discount_amount))) / Decimal(str(item.quantity)) + else: + price_with_discount = Decimal(str(item.price)) + # Пересчитываем цену в базовые единицы if item.sales_unit and item.conversion_factor_snapshot: - base_price = Decimal(str(item.price)) * item.conversion_factor_snapshot + base_price = price_with_discount * item.conversion_factor_snapshot else: - base_price = Decimal(str(item.price)) + base_price = price_with_discount # Создаем Sale (с автоматическим FIFO-списанием) sale = SaleProcessor.create_sale(