Watch
1
0
Fork
You've already forked Seyyed_arc
0
forked from hesabix/arc
Seyyed_arc/hesabixAPI/tests/test_invoice_cost_currency_basis.py
Seyyed 1a003e1758 fix(costing): support cost_currency_basis for cost_price (P01)
Split cost_price interpretation by explicit flag:
- 'base' (Native): cost_price is already in base currency; no FX.
- 'document' (Legacy, default): cost_price is in document currency;
  apply FX.

Fixes potential 10x valuation inflation when Native and Legacy
paths are mixed.

Backward compatible: absence of flag = 'document'.

Target tests: 38 passed (26 existing + 8 existing + 4 new).
Full test suite did not complete in 300s (hang on
test_ai_channel_stream.py, unrelated to this change). CI should run
full suite before merge.
2026-11-06 21:48:23 +03:30

28 lines
907 B
Python

from decimal import Decimal
from types import SimpleNamespace
import pytest
from app.core.responses import ApiError
from app.services.invoice_profit_costing import inventory_line_unit_cost_main_base
def _cost(basis):
info = {"cost_price": "100"}
if basis is not None:
info["cost_currency_basis"] = basis
return inventory_line_unit_cost_main_base(
SimpleNamespace(main_unit="unit"), info, Decimal("1"),
document_type="invoice_purchase", fx_rate=Decimal("10"),
)
@pytest.mark.parametrize("basis,expected", [(None, "1000"), ("document", "1000"), ("base", "100")])
def test_cost_currency_basis(basis, expected):
assert _cost(basis) == Decimal(expected)
def test_invalid_cost_currency_basis():
with pytest.raises(ApiError) as caught:
_cost("invalid")
assert (caught.value.code, caught.value.status_code) == ("INVALID_COST_CURRENCY_BASIS", 422)