"""Ledger Adjustment Detail Applied model tests.""" from datetime import date from decimal import Decimal from moneyhub.models.ledger_adjustment_detail_applied import LedgerAdjustmentDetailApplied from tests.unit.conftest import insert_mock_data def test_get_detail_adjustments_by_account_and_statement_periods(): """Test to get adjustments detail for a specified account.""" account_id = 1235 contract_id = 4343 statement_period_id = 123 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': statement_period_id, 'statement_period_status': 'closed'}, { 'statement_period_id': statement_period_id + 1, 'statement_period_status': 'current' }, ], 'abacus_event': [ {'abacus_event_id': 1, 'statement_period_id': statement_period_id}, {'abacus_event_id': 2, 'statement_period_id': statement_period_id}, {'abacus_event_id': 3, 'statement_period_id': statement_period_id + 1}, ], 'reference_adjustment_type': [ { 'reference_adjustment_type_id': 1, 'type_name': 'Label Earnings' }, { 'reference_adjustment_type_id': 100, 'type_name': 'Mechanicals' }, { 'reference_adjustment_type_id': 65, 'type_name': 'Account Expense' } ], 'statement_period_adjustment_file': { 'statement_period_adjustment_file_id': 1, 'statement_period_id': statement_period_id, }, 'worksheet_adjustment': [ { 'account_id': account_id, 'contract_id': contract_id, 'abacus_event_id': 1, 'statement_period_adjustment_file_id': 1, 'worksheet_adjustment_id': 1, 'activity_statement_period_id': statement_period_id, 'adjustment_amount': 1010.00, 'adjustment_currency_code': 'USD', 'apply_to_statement_period_id': statement_period_id, 'reference_adjustment_type_id': 1, 'note': 'mock adjustment' }, { 'account_id': account_id, 'contract_id': contract_id, 'abacus_event_id': 2, 'statement_period_adjustment_file_id': 1, 'worksheet_adjustment_id': 2, 'activity_statement_period_id': statement_period_id, 'adjustment_amount': 1010.00, 'adjustment_currency_code': 'USD', 'apply_to_statement_period_id': statement_period_id, 'reference_adjustment_type_id': 65, 'note': 'mock adjustment' }, { 'account_id': account_id, 'contract_id': contract_id, 'abacus_event_id': 3, 'statement_period_adjustment_file_id': 1, 'worksheet_adjustment_id': 3, 'activity_statement_period_id': statement_period_id + 1, 'adjustment_amount': 1010.00, 'adjustment_currency_code': 'USD', 'apply_to_statement_period_id': statement_period_id + 1, 'reference_adjustment_type_id': 100, 'note': 'mock adjustment' }, ], 'worksheet_adjustment_detail': [ { 'worksheet_adjustment_detail_id': 1, 'worksheet_adjustment_id': 1, 'statement_period_adjustment_file_id': 1, 'account_id': account_id, 'contract_id': contract_id, 'activity_statement_period_id': statement_period_id, 'amount': '1000.00', 'apply_to_statement_period_id': statement_period_id, 'currency_code': 'USD', 'created_at': date(2022, 1, 1), 'created_by': 'someone', 'distribution_type': 'digital', 'last_modified': date(2022, 5, 1), 'last_modified_by': 'someone', 'reference_adjustment_type_id': 1, 'note': 'mock adjustment', 'upc': '87654321' }, { 'worksheet_adjustment_detail_id': 2, 'worksheet_adjustment_id': 2, 'statement_period_adjustment_file_id': 1, 'account_id': account_id, 'contract_id': contract_id, 'activity_statement_period_id': statement_period_id, 'amount': '1000.00', 'apply_to_statement_period_id': statement_period_id, 'currency_code': 'USD', 'created_at': date(2022, 1, 1), 'created_by': 'someone', 'distribution_type': 'digital', 'last_modified': date(2022, 5, 1), 'last_modified_by': 'someone', 'reference_adjustment_type_id': 1, 'note': 'mock adjustment', 'upc': '12345678' }, { 'worksheet_adjustment_detail_id': 3, 'worksheet_adjustment_id': 3, 'statement_period_adjustment_file_id': 1, 'account_id': account_id, 'contract_id': contract_id, 'activity_statement_period_id': statement_period_id + 1, 'amount': '1000.00', 'apply_to_statement_period_id': statement_period_id + 1, 'currency_code': 'USD', 'created_at': date(2022, 1, 1), 'created_by': 'someone', 'distribution_type': 'digital', 'last_modified': date(2022, 5, 1), 'last_modified_by': 'someone', 'reference_adjustment_type_id': 1, 'note': 'mock adjustment', 'upc': '87654321' } ], 'ledger_adjustment_detail_applied': [ { 'ledger_adjustment_detail_applied_id': 1, 'ledger_adjustment_detail_id': 1, 'worksheet_adjustment_detail_id': 1, 'adjustment_amount': 1010.00, 'adjustment_currency_code': 'USD', 'adjustment_amount_payee_currency': Decimal('1290.99'), 'adjustment_payee_currency_code': 'AUD' }, { 'ledger_adjustment_detail_applied_id': 2, 'ledger_adjustment_detail_id': 2, 'worksheet_adjustment_detail_id': 2, 'adjustment_amount': 110.00, 'adjustment_currency_code': 'USD', 'adjustment_amount_payee_currency': Decimal('110.99'), 'adjustment_payee_currency_code': 'AUD' }, ], }) result = LedgerAdjustmentDetailApplied.get_expenses_by_account_and_statement_periods( account_id, [statement_period_id], contract_id) assert float(result[0].adjustment_amount_payee_currency) == 1401.98 assert result[0]['adjustment_payee_currency_code'] == 'AUD' assert result[0]['reference_adjustment_type_id'] == 1 assert result[0]['reference_adjustment_type_name'] == 'Label Earnings'