PayrollManagementSystem/backend/app/services/cost_rules.py

15 lines
610 B
Python
Raw Normal View History

"""含税单位指导成本到总成本的唯一换算,不改写已封存的成本快照。"""
from decimal import ROUND_HALF_UP, Decimal
def guided_total(quantity, guided_price, cost_amount=None):
if guided_price is None:
return Decimal(str(cost_amount)) if cost_amount is not None else None
total = (Decimal(str(quantity)) * Decimal(str(guided_price))).quantize(
Decimal("0.01"), rounding=ROUND_HALF_UP
)
if cost_amount is not None and Decimal(str(cost_amount)) != total:
raise ValueError("成本额与数量×含税单位指导成本不一致")
return total