test: bank reconciliation API methods
This commit is contained in:
parent
2ad62be2c7
commit
2be025311a
@ -1,9 +1,100 @@
|
|||||||
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
|
||||||
# import frappe
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
from frappe import qb
|
||||||
|
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||||
|
from frappe.utils import add_days, flt, getdate, today
|
||||||
|
|
||||||
class TestBankReconciliationTool(unittest.TestCase):
|
from erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool import (
|
||||||
pass
|
auto_reconcile_vouchers,
|
||||||
|
get_bank_transactions,
|
||||||
|
)
|
||||||
|
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry
|
||||||
|
from erpnext.accounts.test.accounts_mixin import AccountsTestMixin
|
||||||
|
|
||||||
|
|
||||||
|
class TestBankReconciliationTool(AccountsTestMixin, FrappeTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.create_company()
|
||||||
|
self.create_customer()
|
||||||
|
self.clear_old_entries()
|
||||||
|
bank_dt = qb.DocType("Bank")
|
||||||
|
q = qb.from_(bank_dt).delete().where(bank_dt.name == "HDFC").run()
|
||||||
|
self.create_bank_account()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
frappe.db.rollback()
|
||||||
|
|
||||||
|
def create_bank_account(self):
|
||||||
|
bank = frappe.get_doc(
|
||||||
|
{
|
||||||
|
"doctype": "Bank",
|
||||||
|
"bank_name": "HDFC",
|
||||||
|
}
|
||||||
|
).save()
|
||||||
|
|
||||||
|
self.bank_account = (
|
||||||
|
frappe.get_doc(
|
||||||
|
{
|
||||||
|
"doctype": "Bank Account",
|
||||||
|
"account_name": "HDFC _current_",
|
||||||
|
"bank": bank,
|
||||||
|
"is_company_account": True,
|
||||||
|
"account": self.bank, # account from Chart of Accounts
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.insert()
|
||||||
|
.name
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_auto_reconcile(self):
|
||||||
|
# make payment
|
||||||
|
from_date = add_days(today(), -1)
|
||||||
|
to_date = today()
|
||||||
|
payment = create_payment_entry(
|
||||||
|
company=self.company,
|
||||||
|
posting_date=from_date,
|
||||||
|
payment_type="Receive",
|
||||||
|
party_type="Customer",
|
||||||
|
party=self.customer,
|
||||||
|
paid_from=self.debit_to,
|
||||||
|
paid_to=self.bank,
|
||||||
|
paid_amount=100,
|
||||||
|
).save()
|
||||||
|
payment.reference_no = "123"
|
||||||
|
payment = payment.save().submit()
|
||||||
|
|
||||||
|
# make bank transaction
|
||||||
|
bank_transaction = (
|
||||||
|
frappe.get_doc(
|
||||||
|
{
|
||||||
|
"doctype": "Bank Transaction",
|
||||||
|
"date": to_date,
|
||||||
|
"deposit": 100,
|
||||||
|
"bank_account": self.bank_account,
|
||||||
|
"reference_number": "123",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.save()
|
||||||
|
.submit()
|
||||||
|
)
|
||||||
|
|
||||||
|
# assert API output pre reconciliation
|
||||||
|
transactions = get_bank_transactions(self.bank_account, from_date, to_date)
|
||||||
|
self.assertEqual(len(transactions), 1)
|
||||||
|
self.assertEqual(transactions[0].name, bank_transaction.name)
|
||||||
|
|
||||||
|
# auto reconcile
|
||||||
|
auto_reconcile_vouchers(
|
||||||
|
bank_account=self.bank_account,
|
||||||
|
from_date=from_date,
|
||||||
|
to_date=to_date,
|
||||||
|
filter_by_reference_date=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
# assert API output post reconciliation
|
||||||
|
transactions = get_bank_transactions(self.bank_account, from_date, to_date)
|
||||||
|
self.assertEqual(len(transactions), 0)
|
||||||
|
|||||||
@ -136,6 +136,8 @@ class AccountsTestMixin:
|
|||||||
"Journal Entry",
|
"Journal Entry",
|
||||||
"Sales Order",
|
"Sales Order",
|
||||||
"Exchange Rate Revaluation",
|
"Exchange Rate Revaluation",
|
||||||
|
"Bank Account",
|
||||||
|
"Bank Transaction",
|
||||||
]
|
]
|
||||||
for doctype in doctype_list:
|
for doctype in doctype_list:
|
||||||
qb.from_(qb.DocType(doctype)).delete().where(qb.DocType(doctype).company == self.company).run()
|
qb.from_(qb.DocType(doctype)).delete().where(qb.DocType(doctype).company == self.company).run()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user