fix(inventory): учитывать скидку при расчёте цены продажи
Внесены изменения в SaleProcessor и сигнал создания продажи для корректного расчёта цены с учётом скидки на товар. Теперь при наличии discount_amount производится пересчёт цены за единицу товара с учётом скидки перед конвертацией в базовые единицы измерения. Это исправляет ошибку, при которой скидка не учитывалась в итоговой цене продажи.
This commit is contained in:
@@ -36,11 +36,17 @@ class SaleProcessor:
|
|||||||
# Определяем цену продажи из заказа или из товара
|
# Определяем цену продажи из заказа или из товара
|
||||||
if order and reservation.order_item:
|
if order and reservation.order_item:
|
||||||
item = 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:
|
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:
|
else:
|
||||||
sale_price = item.price
|
sale_price = price_with_discount
|
||||||
else:
|
else:
|
||||||
# Цена из товара
|
# Цена из товара
|
||||||
sale_price = reservation.product.actual_price or Decimal('0')
|
sale_price = reservation.product.actual_price or Decimal('0')
|
||||||
|
|||||||
@@ -480,11 +480,18 @@ def create_sale_on_order_completion(sender, instance, created, **kwargs):
|
|||||||
f"Используем quantity_in_base_units: {sale_quantity}"
|
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:
|
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:
|
else:
|
||||||
base_price = Decimal(str(item.price))
|
base_price = price_with_discount
|
||||||
|
|
||||||
# Создаем Sale (с автоматическим FIFO-списанием)
|
# Создаем Sale (с автоматическим FIFO-списанием)
|
||||||
sale = SaleProcessor.create_sale(
|
sale = SaleProcessor.create_sale(
|
||||||
|
|||||||
Reference in New Issue
Block a user