"""Ledger Correction model tests.""" from datetime import datetime from decimal import Decimal from moneyhub.models.ledger_correction import LedgerCorrection from tests.unit.conftest import insert_mock_data def test_get_ledger_corrections_by_account_and_contract(): """Test to get ledger corrections for a specified account.""" account_id = 1235 contract_id = 4343 insert_mock_data({ 'account': {'account_id': account_id}, 'reference_payment_entity': {'reference_payment_entity_id': 1}, 'reference_sap_profit_center': { 'reference_sap_profit_center_id': 1, 'profit_center': 'UK1234', 'company_code': '1234', 'business_group': 'ORC' }, 'reference_signing_entity': { 'reference_signing_entity_id': 1, 'reference_payment_entity_id': 1, 'reference_sap_profit_center_id': 1, 'company_code': '1234', 'tax_entity_company_code': '1234', 'legal_name': 'Company', 'vat_number': '12341234', 'company_registration_number': '12341234', 'address': None, }, 'contract': { 'contract_id': contract_id, 'reference_signing_entity_id': 1, }, 'statement_period': [ {'statement_period_id': 12, 'statement_period_status': 'closed'}, {'statement_period_id': 10, 'statement_period_status': 'closed'}, ], 'abacus_event': [ {'abacus_event_id': 1, 'statement_period_id': 12}, ], 'worksheet_correction': [ { 'worksheet_correction_id': 1, 'account_id': account_id, 'contract_id': contract_id, 'statement_period_id': 12, 'correction_statement_period_id': 10 }, ], 'ledger_correction': [ { 'account_id': account_id, 'contract_id': contract_id, 'abacus_event_id': 1, 'ledger_correction_id': 1, 'worksheet_correction_id': 1, 'statement_period_id': 12, 'correction_statement_period_id': 10, 'correction_type': 'royalty_correction', 'currency_code': 'USD', 'gross_revenue': '1023.90', 'net_revenue': '67347.08', 'distribution_fee': '101.12', 'mechanical_deduction_total': '50.00', 'mechanical_deduction_admin_fee_total': '5.00', 'created_at': datetime(2010, 9, 8, 7, 6, 5), 'created_by': 'me', 'last_modified': datetime(2022, 12, 17, 22, 2, 42), 'last_modified_by': 'me', 'note': 'ledger correction' }] }) res = LedgerCorrection.get_for_account(account_id, contract_id)[0].to_dict() assert res['gross_revenue'] == Decimal('1023.90') assert res['net_revenue'] == Decimal('67347.08') assert res['distribution_fee'] == Decimal('101.12') assert res['mechanical_deduction_total'] == Decimal('50.00') assert res['mechanical_deduction_admin_fee_total'] == Decimal('5.00')