"""Test LedgerAdjustmentDetailAppliedItem.""" from decimal import Decimal from adjustments_apply.ledger_adjustment_applied_item import ( LedgerAdjustmentDetailAppliedItem, ) def test_ledger_adjustment_applied_detail( mock_pending_adjustments, mock_exchange_rates ): """Test for correct calculated values of a LedgerAdjustmentDetailAppliedItem.""" adjustment = mock_pending_adjustments[0] detail = adjustment['details'][0] exchange_rate = mock_exchange_rates[0] item = LedgerAdjustmentDetailAppliedItem( detail['worksheet_adjustment_id'], detail['worksheet_adjustment_detail_id'], detail['currency_code'], detail['amount'], adjustment['account_currency_code'], Decimal(str(exchange_rate['rate'])), adjustment['apply_to_flowthrough_payment'], ) assert item.adjustment_amount_by_exchange_rate == Decimal('1069.5857616') assert item.adjustment_amount_payee_currency == Decimal('1069.59') assert item.adjustment_amount_remainder == Decimal('-0.0042384') assert item.format_ledger_adjustment_detail_applied_entry() == { 'worksheet_adjustment_id': item.worksheet_adjustment_id, 'worksheet_adjustment_detail_id': item.worksheet_adjustment_detail_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, } def test_format_ledger_adjustment_detail_applied_entry( mock_pending_adjustments, mock_exchange_rates ): """Test format_ledger_adjustment_detail_applied_entry method. apply_to_flowthrough_payment is always included in the entry. """ adjustment = mock_pending_adjustments[0] detail = adjustment['details'][0] exchange_rate = mock_exchange_rates[0] item = LedgerAdjustmentDetailAppliedItem( detail['worksheet_adjustment_id'], detail['worksheet_adjustment_detail_id'], detail['currency_code'], detail['amount'], adjustment['account_currency_code'], Decimal(str(exchange_rate['rate'])), adjustment['apply_to_flowthrough_payment'], ) result = item.format_ledger_adjustment_detail_applied_entry() assert result == { 'worksheet_adjustment_id': detail['worksheet_adjustment_id'], 'worksheet_adjustment_detail_id': detail['worksheet_adjustment_detail_id'], 'adjustment_currency_code': detail['currency_code'], 'adjustment_amount': detail['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'], }