From 0938878e67fa69a654cd064957fd9687b10c70ea Mon Sep 17 00:00:00 2001 From: Andrey Smakotin Date: Tue, 20 Jan 2026 23:20:55 +0300 Subject: [PATCH] =?UTF-8?q?fix(inventory):=20=D1=83=D1=87=D0=B8=D1=82?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D1=82=D1=8C=20=D1=81=D0=BA=D0=B8=D0=B4=D0=BA?= =?UTF-8?q?=D1=83=20=D0=BF=D1=80=D0=B8=20=D1=80=D0=B0=D1=81=D1=87=D1=91?= =?UTF-8?q?=D1=82=D0=B5=20=D1=86=D0=B5=D0=BD=D1=8B=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B4=D0=B0=D0=B6=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Внесены изменения в SaleProcessor и сигнал создания продажи для корректного расчёта цены с учётом скидки на товар. Теперь при наличии discount_amount производится пересчёт цены за единицу товара с учётом скидки перед конвертацией в базовые единицы измерения. Это исправляет ошибку, при которой скидка не учитывалась в итоговой цене продажи. --- myproject/inventory/services/sale_processor.py | 10 ++++++++-- myproject/inventory/signals.py | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) 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(