"""Unit tests for Ledger Reserve Taken model.""" from decimal import Decimal from ledger.models.ledger_reserve_taken import LedgerReserveTaken from tests.utils.factories import LedgerReserveTakenFactory def test_create_ledger_reserve_taken(mock_event_fixtures): """Test to create a Ledger Reserve Taken.""" LedgerReserveTaken.create( abacus_event_id=1, contract_reserve_id=1, accounting_run_id=1, statement_period_id=1, currency_code='USD', gross_sales=710.03, gross_returns=Decimal('659.31'), net_revenue=Decimal('50.22'), reserve_amount=Decimal('23.00'), net_revenue_after_reserve=Decimal('27.22'), ) records = LedgerReserveTaken.query.all() assert len(records) == 1 assert records[0].ledger_reserve_taken_id == 1 def test_get_by_abacus_events_accounting_runs_contract_reserves(mock_event_fixtures): """Test getting entries by abacus_events, accounting_runs, and contract_reserves.""" abacus_event_ids = [1, 2, 3] accounting_run_ids = [1, 2, 3] contract_reserve_ids = [1, 2, 3] ledger_reserve_taken = LedgerReserveTakenFactory.create( abacus_event_id=1, accounting_run_id=3, contract_reserve_id=2 ) res = LedgerReserveTaken.get_by_abacus_events_accounting_runs_contract_reserves( abacus_event_ids, accounting_run_ids, contract_reserve_ids ) assert len(res) == 1 assert ledger_reserve_taken in res assert res[0].abacus_event_id == ledger_reserve_taken.abacus_event_id assert res[0].accounting_run_id == ledger_reserve_taken.accounting_run_id assert res[0].contract_reserve_id == ledger_reserve_taken.contract_reserve_id assert res[0].abacus_event_id in abacus_event_ids assert res[0].accounting_run_id in accounting_run_ids assert res[0].contract_reserve_id in contract_reserve_ids def test_get_by_accounting_run(mock_event_fixtures): """Test to get Ledger Reserve Taken entries by accounting_run_id.""" accounting_run_id = 1 ledger_reserve_taken = LedgerReserveTakenFactory.create() LedgerReserveTakenFactory.create(accounting_run_id=2) params = {'accounting_run_id': accounting_run_id, 'limit': 10, 'offset': 0} items, total_count = LedgerReserveTaken.get_by_accounting_run(**params) assert total_count == 1 assert ( items[0].ledger_reserve_taken_id == ledger_reserve_taken.ledger_reserve_taken_id )