"""Test Ledger Correction schema.""" from ledger.schemas.ledger_correction import ( LedgerCorrectionDetailSchema, LedgerCorrectionSchema, ) from tests.utils.factories import LedgerCorrectionFactory def test_ledger_correction_schema_dump(mock_event_fixtures, mock_worksheet_correction): """Test ledger_correction schema dumping.""" entity = LedgerCorrectionFactory.create() res = LedgerCorrectionSchema().dump(entity) assert res == { 'abacus_event_id': entity.abacus_event_id, 'worksheet_correction_id': entity.worksheet_correction_id, 'account_id': entity.account_id, 'contract_id': entity.contract_id, 'statement_period_id': entity.statement_period_id, 'correction_statement_period_id': entity.correction_statement_period_id, 'correction_type': entity.correction_type, 'currency_code': entity.currency_code, 'gross_revenue': str(entity.gross_revenue), 'distribution_fee': str(entity.distribution_fee), 'mechanical_deduction_total': None, 'mechanical_deduction_admin_fee_total': None, 'net_revenue': str(entity.net_revenue), 'note': entity.note, } def test_ledger_correction_detail_schema_dump( mock_event_fixtures, mock_worksheet_correction ): """Test ledger_correction detail schema dumping.""" entity = LedgerCorrectionFactory.create() res = LedgerCorrectionDetailSchema().dump(entity) assert res == { 'ledger_correction_id': entity.ledger_correction_id, 'abacus_event_id': entity.abacus_event_id, 'worksheet_correction_id': entity.worksheet_correction_id, 'account_id': entity.account_id, 'contract_id': entity.contract_id, 'statement_period_id': entity.statement_period_id, 'correction_statement_period_id': entity.correction_statement_period_id, 'correction_type': entity.correction_type, 'currency_code': entity.currency_code, 'gross_revenue': str(entity.gross_revenue), 'distribution_fee': str(entity.distribution_fee), 'mechanical_deduction_total': None, 'mechanical_deduction_admin_fee_total': None, 'net_revenue': str(entity.net_revenue), 'note': entity.note, } def test_ledger_correction_schema_with_mech_deduction_dump( mock_event_fixtures, mock_worksheet_correction ): """Test ledger_correction schema including mech deduction columns.""" entity = LedgerCorrectionFactory.create( mechanical_deduction_total='100.90', mechanical_deduction_admin_fee_total='45.10', ) res = LedgerCorrectionSchema().dump(entity) assert res == { 'abacus_event_id': entity.abacus_event_id, 'worksheet_correction_id': entity.worksheet_correction_id, 'account_id': entity.account_id, 'contract_id': entity.contract_id, 'statement_period_id': entity.statement_period_id, 'correction_statement_period_id': entity.correction_statement_period_id, 'correction_type': entity.correction_type, 'currency_code': entity.currency_code, 'gross_revenue': str(entity.gross_revenue), 'distribution_fee': str(entity.distribution_fee), 'mechanical_deduction_total': '100.90', 'mechanical_deduction_admin_fee_total': '45.10', 'net_revenue': str(entity.net_revenue), 'note': entity.note, }