# Copyright (c) 2022, SolutionERP LLC and Contributors
# See license.txt

import xhiveframework
from xhiveframework.tests.utils import XhiveframeworkTestCase

from xhiveerp.accounts.doctype.bank_transaction.test_bank_transaction import (
	create_loan_and_repayment,
)
from xhiveerp.accounts.report.bank_reconciliation_statement.bank_reconciliation_statement import (
	execute,
)
from xhiveerp.loan_management.doctype.loan.test_loan import create_loan_accounts


class TestBankReconciliationStatement(XhiveframeworkTestCase):
	def setUp(self):
		for dt in [
			"Loan Repayment",
			"Loan Disbursement",
			"Journal Entry",
			"Journal Entry Account",
			"Payment Entry",
		]:
			xhiveframework.db.delete(dt)

	def test_loan_entries_in_bank_reco_statement(self):
		create_loan_accounts()
		repayment_entry = create_loan_and_repayment()

		filters = xhiveframework._dict(
			{
				"company": "Test Company",
				"account": "Payment Account - _TC",
				"report_date": "2018-10-30",
			}
		)
		result = execute(filters)

		self.assertEqual(result[1][0].payment_entry, repayment_entry.name)
