"""Test LedgerAdjustmentAppliedItem.""" from decimal import Decimal from adjustments_apply.ledger_adjustment_applied_item import LedgerAdjustmentAppliedItem def test_ledger_adjustment_applied_item_values( mock_pending_adjustments, mock_exchange_rates ): """Test for correct calculated values of a LedgerAdjustmentAppliedItem.""" adjustment = mock_pending_adjustments[0] exchange_rate = mock_exchange_rates[0] item = LedgerAdjustmentAppliedItem( adjustment['account_id'], adjustment['contract_id'], adjustment['abacus_event_id'], adjustment['worksheet_adjustment_id'], adjustment['adjustment_currency_code'], adjustment['adjustment_amount'], adjustment['account_currency_code'], exchange_rate['rate'], adjustment['apply_to_flowthrough_payment'], adjustment['reference_adjustment_type_id'], adjustment['details'], ) assert item.adjustment_amount_by_exchange_rate == sum( detail.adjustment_amount_by_exchange_rate for detail in item.details ) assert item.adjustment_amount_payee_currency == sum( detail.adjustment_amount_payee_currency for detail in item.details ) assert item.adjustment_amount_remainder == sum( detail.adjustment_amount_remainder for detail in item.details ) assert item.adjustment_amount_by_exchange_rate == Decimal('1781.0845260') assert item.adjustment_amount_payee_currency == Decimal('1781.09') assert item.adjustment_amount_remainder == Decimal('-0.0054740') assert item.format_ledger_adjustment_applied_entry(1) == { 'abacus_event_id': item.abacus_event_id, 'statement_period_id': 1, 'account_id': item.account_id, 'contract_id': item.contract_id, 'worksheet_adjustment_id': item.worksheet_adjustment_id, 'adjustment_currency_code': item.adjustment_currency_code, 'adjustment_amount': str(item.adjustment_amount), 'adjustment_payee_currency_code': item.adjustment_payee_currency_code, 'adjustment_amount_payee_currency': str(item.adjustment_amount_payee_currency), 'apply_to_flowthrough_payment': item.apply_to_flowthrough_payment, 'details': [ { 'worksheet_adjustment_id': item.details[0].worksheet_adjustment_id, 'worksheet_adjustment_detail_id': item.details[ 0 ].worksheet_adjustment_detail_id, 'adjustment_currency_code': item.details[0].adjustment_currency_code, 'adjustment_amount': str(item.details[0].adjustment_amount), 'adjustment_payee_currency_code': item.details[ 0 ].adjustment_payee_currency_code, 'adjustment_amount_payee_currency': str( item.details[0].adjustment_amount_payee_currency ), 'apply_to_flowthrough_payment': item.details[ 0 ].apply_to_flowthrough_payment, }, { 'worksheet_adjustment_id': item.details[1].worksheet_adjustment_id, 'worksheet_adjustment_detail_id': item.details[ 1 ].worksheet_adjustment_detail_id, 'adjustment_currency_code': item.details[1].adjustment_currency_code, 'adjustment_amount': str(item.details[1].adjustment_amount), 'adjustment_payee_currency_code': item.details[ 1 ].adjustment_payee_currency_code, 'adjustment_amount_payee_currency': str( item.details[1].adjustment_amount_payee_currency ), 'apply_to_flowthrough_payment': item.details[ 1 ].apply_to_flowthrough_payment, }, ], } def test_format_ledger_adjustment_applied_entry( mock_pending_adjustments, mock_exchange_rates ): """Test format_ledger_adjustment_applied_entry method.""" adjustment = mock_pending_adjustments[0] exchange_rate = mock_exchange_rates[0] item = LedgerAdjustmentAppliedItem( adjustment['account_id'], adjustment['contract_id'], adjustment['abacus_event_id'], adjustment['worksheet_adjustment_id'], adjustment['adjustment_currency_code'], adjustment['adjustment_amount'], adjustment['account_currency_code'], exchange_rate['rate'], adjustment['apply_to_flowthrough_payment'], adjustment['reference_adjustment_type_id'], adjustment['details'], ) assert item.format_ledger_adjustment_applied_entry(1) == { 'abacus_event_id': adjustment['abacus_event_id'], 'statement_period_id': 1, 'account_id': adjustment['account_id'], 'contract_id': adjustment['contract_id'], 'worksheet_adjustment_id': adjustment['worksheet_adjustment_id'], 'adjustment_currency_code': adjustment['adjustment_currency_code'], 'adjustment_amount': adjustment['adjustment_amount'], 'adjustment_payee_currency_code': adjustment['account_currency_code'], 'adjustment_amount_payee_currency': str(item.adjustment_amount_payee_currency), 'apply_to_flowthrough_payment': adjustment['apply_to_flowthrough_payment'], 'details': [ { 'worksheet_adjustment_id': adjustment['details'][0][ 'worksheet_adjustment_id' ], 'worksheet_adjustment_detail_id': adjustment['details'][0][ 'worksheet_adjustment_detail_id' ], 'adjustment_currency_code': adjustment['details'][0]['currency_code'], 'adjustment_amount': adjustment['details'][0]['amount'], 'adjustment_payee_currency_code': item.details[ 0 ].adjustment_payee_currency_code, 'adjustment_amount_payee_currency': str( item.details[0].adjustment_amount_payee_currency ), 'apply_to_flowthrough_payment': item.details[ 0 ].apply_to_flowthrough_payment, }, { 'worksheet_adjustment_id': adjustment['details'][1][ 'worksheet_adjustment_id' ], 'worksheet_adjustment_detail_id': adjustment['details'][1][ 'worksheet_adjustment_detail_id' ], 'adjustment_currency_code': adjustment['details'][1]['currency_code'], 'adjustment_amount': adjustment['details'][1]['amount'], 'adjustment_payee_currency_code': item.details[ 1 ].adjustment_payee_currency_code, 'adjustment_amount_payee_currency': str( item.details[1].adjustment_amount_payee_currency ), 'apply_to_flowthrough_payment': item.details[ 1 ].apply_to_flowthrough_payment, }, ], } def test_format_ledger_adjustment_applied_entry_includes_flowthrough_field( mock_pending_adjustments, mock_exchange_rates ): """Test apply_to_flowthrough_payment is always included in the entry.""" adjustment = mock_pending_adjustments[0] exchange_rate = mock_exchange_rates[0] item = LedgerAdjustmentAppliedItem( adjustment['account_id'], adjustment['contract_id'], adjustment['abacus_event_id'], adjustment['worksheet_adjustment_id'], adjustment['adjustment_currency_code'], adjustment['adjustment_amount'], adjustment['account_currency_code'], exchange_rate['rate'], adjustment['apply_to_flowthrough_payment'], adjustment['reference_adjustment_type_id'], adjustment['details'], ) result = item.format_ledger_adjustment_applied_entry(1) assert 'apply_to_flowthrough_payment' in result assert ( result['apply_to_flowthrough_payment'] == adjustment['apply_to_flowthrough_payment'] ) for detail_entry in result['details']: assert 'apply_to_flowthrough_payment' in detail_entry assert ( detail_entry['apply_to_flowthrough_payment'] == adjustment['apply_to_flowthrough_payment'] )