"""WorksheetAccountContractClosingBalance model tests.""" from decimal import Decimal from moneyhub.models import PaymentAllocation from tests.unit.conftest import insert_mock_data def test_get_payment_allocation_details(): """Test getting payment allocation details for a list of contracts and statement periods.""" insert_mock_data({ 'payment_allocation': [ { 'payment_allocation_id': 1, 'contract_id': 1, 'statement_period_id': 11, 'payment_allocation_type': 'flowthrough', }, { 'payment_allocation_id': 2, 'contract_id': 1, 'statement_period_id': 11, 'payment_allocation_type': 'flowthrough', } ], 'payment_allocation_ledger_adjustment': [ { 'payment_allocation_ledger_adjustment_id': 1, 'payment_allocation_id': 1, 'ledger_adjustment_applied_id': 1, }, { 'payment_allocation_ledger_adjustment_id': 2, 'payment_allocation_id': 1, 'ledger_adjustment_applied_id': 2, }, { 'payment_allocation_ledger_adjustment_id': 3, 'payment_allocation_id': 2, 'ledger_adjustment_applied_id': 3, }, ], 'ledger_adjustment_applied': [ { 'ledger_adjustment_applied_id': 1, 'ledger_adjustment_id': 1, 'worksheet_adjustment_id': 1, 'statement_period_id': 11, 'adjustment_amount': 361.30, 'adjustment_amount_payee_currency': 361.30, 'adjustment_currency_code': 'GBP', 'adjustment_payee_currency_code': 'GBP', 'abacus_event_id': 1, 'account_id': 1, }, { 'ledger_adjustment_applied_id': 2, 'ledger_adjustment_id': 2, 'worksheet_adjustment_id': 2, 'statement_period_id': 11, 'adjustment_amount': 36.13, 'adjustment_amount_payee_currency': 36.13, 'adjustment_currency_code': 'GBP', 'adjustment_payee_currency_code': 'GBP', 'abacus_event_id': 1, 'account_id': 1, }, { 'ledger_adjustment_applied_id': 3, 'ledger_adjustment_id': 3, 'worksheet_adjustment_id': 3, 'statement_period_id': 11, 'adjustment_amount': 40.00, 'adjustment_amount_payee_currency': 40.00, 'adjustment_currency_code': 'GBP', 'adjustment_payee_currency_code': 'GBP', 'abacus_event_id': 1, 'account_id': 1, }, ], 'worksheet_adjustment': [ { 'worksheet_adjustment_id': 1, 'contract_id': 1, 'activity_statement_period_id': 11, 'adjustment_amount': 361.30, 'adjustment_currency_code': 'GBP', 'apply_to_statement_period_id': 11, 'reference_adjustment_type_id': 1, 'abacus_event_id': 1, 'statement_period_adjustment_file_id': 1, 'account_id': 1, }, { 'worksheet_adjustment_id': 2, 'contract_id': 1, 'activity_statement_period_id': 11, 'adjustment_amount': 36.13, 'adjustment_currency_code': 'GBP', 'apply_to_statement_period_id': 11, 'reference_adjustment_type_id': 2, 'abacus_event_id': 1, 'statement_period_adjustment_file_id': 1, 'account_id': 1, }, { 'worksheet_adjustment_id': 3, 'contract_id': 1, 'activity_statement_period_id': 11, 'adjustment_amount': 40.00, 'adjustment_currency_code': 'GBP', 'apply_to_statement_period_id': 11, 'reference_adjustment_type_id': 1, 'abacus_event_id': 1, 'statement_period_adjustment_file_id': 1, 'account_id': 1, } ], 'reference_adjustment_type': [ { 'reference_adjustment_type_id': 1, 'type_name': 'Fake Flowthrough Adjustment', }, { 'reference_adjustment_type_id': 2, 'type_name': 'Vat', }, ], }) contract_ids = [1] statement_period_ids = [11] result = PaymentAllocation.get_flowthrough_details(contract_ids, statement_period_ids) result_mapped = list(map(lambda x: dict(x), result)) assert result_mapped == [ { 'reference_adjustment_type_id': 1, 'apply_to_statement_period_id': 11, 'reference_adjustment_type': 'Fake Flowthrough Adjustment', 'adjustment_amount': Decimal('401.300000000000011369'), 'currency_code': 'GBP', }, { 'reference_adjustment_type_id': 2, 'apply_to_statement_period_id': 11, 'reference_adjustment_type': 'Vat', 'adjustment_amount': Decimal('36.130000000000002558'), 'currency_code': 'GBP', }, ]