fix w kalkulacji last price

This commit is contained in:
Mateusz Gruszczyński
2026-07-14 13:43:27 +02:00
parent d2f0077e86
commit 6f46508da4
4 changed files with 73 additions and 16 deletions
+22
View File
@@ -12,3 +12,25 @@ def calculate_costs(gross, vat_rate=23, vat_deduction_percent=50):
deductible_vat = vat * deduction
return {"gross": money(gross), "net": money(net), "vat": money(vat),
"deductible_vat": money(deductible_vat), "final_cost": money(gross - deductible_vat)}
def calculate_net_price_costs(net_price, vat_rate=23, vat_deduction_percent=50):
"""Return per-unit invoice and effective costs for a net fuel price.
A 50% VAT deduction means the company bears half of the VAT, not a 50% VAT rate.
"""
net = Decimal(str(net_price))
rate = Decimal(str(vat_rate)) / Decimal("100")
deduction = Decimal(str(vat_deduction_percent)) / Decimal("100")
deduction = min(max(deduction, Decimal("0")), Decimal("1"))
vat = net * rate
invoice_gross = net + vat
deductible_vat = vat * deduction
effective_cost = invoice_gross - deductible_vat
return {
"net": net,
"vat": vat,
"invoice_gross": invoice_gross,
"deductible_vat": deductible_vat,
"effective_cost": effective_cost,
}