"""Test Ledger Accounting Run VAT schema.""" from decimal import Decimal from ledger.schemas.ledger_accounting_run_vat import ( LedgerAccountingRunVatDetailSchema, LedgerAccountingRunVatSchema, ) from tests.utils.factories import LedgerAccountingRunVatFactory def test_ledger_accounting_run_vat_schema_load(): """Test Ledger Accounting Run VAT schema loading.""" test_data = [ { 'accounting_run_id': 1, 'abacus_event_id': 1, 'contract_id': 1, 'currency_code': 'GBP', 'country_of_tax_residence': 'GBR', 'gross_revenue': Decimal('2000'), 'net_revenue': Decimal('1800'), 'distribution_fee': Decimal('10'), 'gross_vat_rate': Decimal('20'), 'distribution_vat_rate': Decimal('20'), 'gross_vat': Decimal('200'), 'distribution_vat': Decimal('2'), 'adjusted_net_revenue': Decimal('1780'), 'exempt_reason': None, } ] entries = LedgerAccountingRunVatDetailSchema(many=True).load(test_data) assert entries[0] == test_data[0] def test_ledger_accounting_run_vat_schema_dump(mock_event_fixtures): """Test Ledger Accounting Run VAT schema dumping.""" entity = LedgerAccountingRunVatFactory.create(exempt_reason='Test') res = LedgerAccountingRunVatDetailSchema().dump(entity) assert res == { 'ledger_accounting_run_vat_id': entity.ledger_accounting_run_vat_id, 'accounting_run_id': entity.accounting_run_id, 'abacus_event_id': entity.abacus_event_id, 'contract_id': entity.contract_id, 'currency_code': entity.currency_code, 'country_of_tax_residence': entity.country_of_tax_residence, 'gross_revenue': str(entity.gross_revenue), 'net_revenue': str(entity.net_revenue), 'distribution_fee': str(entity.distribution_fee), 'gross_vat_rate': str(entity.gross_vat_rate), 'distribution_vat_rate': str(entity.distribution_vat_rate), 'gross_vat': str(entity.gross_vat), 'distribution_vat': str(entity.distribution_vat), 'adjusted_net_revenue': str(entity.adjusted_net_revenue), 'exempt_reason': entity.exempt_reason, } def test_ledger_accounting_run_vat_list_schema_dump(mock_event_fixtures): """Test Ledger Accounting Run VAT schema dumping.""" entity = LedgerAccountingRunVatFactory.create(exempt_reason='Test') entity.accounting_period_id = 1 res = LedgerAccountingRunVatSchema().dump(entity) assert res == { 'ledger_accounting_run_vat_id': entity.ledger_accounting_run_vat_id, 'accounting_period_id': entity.accounting_period_id, 'accounting_run_id': entity.accounting_run_id, 'abacus_event_id': entity.abacus_event_id, 'contract_id': entity.contract_id, 'currency_code': entity.currency_code, 'country_of_tax_residence': entity.country_of_tax_residence, 'gross_revenue': str(entity.gross_revenue), 'net_revenue': str(entity.net_revenue), 'distribution_fee': str(entity.distribution_fee), 'gross_vat_rate': str(entity.gross_vat_rate), 'distribution_vat_rate': str(entity.distribution_vat_rate), 'gross_vat': str(entity.gross_vat), 'distribution_vat': str(entity.distribution_vat), 'adjusted_net_revenue': str(entity.adjusted_net_revenue), 'exempt_reason': entity.exempt_reason, }