from decimal import Decimal from roborto_accounting.persistence.base import Base from roborto_accounting.persistence.db import make_engine,make_session_factory from roborto_accounting.services.currency import capture_currency_value def test_currency_snapshot_preserves_applied_historical_rate(): e=make_engine("sqlite://");Base.metadata.create_all(e);s=make_session_factory(e)() snapshot=capture_currency_value(s,record_type="expense",record_id=1,field_name="actual_amount", original_amount=Decimal("100"),original_currency="usd",exchange_rate=Decimal("0.923456")) later_rate=Decimal("0.800000") assert snapshot.original_currency=="USD" and snapshot.exchange_rate==Decimal("0.923456") assert snapshot.eur_amount==Decimal("92.345600") and snapshot.eur_amount!=Decimal("100")*later_rate s.close();e.dispose()