Skip to content

Commit

Permalink
refactor(test): make use existing test data and dynamic fy creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ruthra-kumar committed Sep 17, 2024
1 parent 75babd4 commit f456380
Showing 1 changed file with 13 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1849,31 +1849,19 @@ def test_cr_note_payment_limit_filter(self):
def test_reconciliation_on_closed_period_payment(self):
from erpnext.accounts.doctype.account.test_account import create_account

self.create_company()
self.create_cost_center()

# create bank account
parent_account = frappe.db.get_value(
"Account", {"company": self.company, "account_name": "Bank Accounts", "is_group": 1}, "name"
)
bank_account = create_account(
account_name="Bank Account",
account_type="Bank",
is_group=0,
company=self.company,
root_type="Asset",
report_type="Balance Sheet",
account_currency="INR",
parent_account=parent_account,
doctype="Account",
)
# Get current fiscal year
current_fy_start_date = get_fiscal_year(today())[1]

# create backdated fiscal year
create_fiscal_year(company=self.company, year_start_date="1990-04-01", year_end_date="1991-03-31")
prev_fy_start_date = add_days(current_fy_start_date, -366)
prev_fy_end_date = add_days(current_fy_start_date, -1)
create_fiscal_year(
company=self.company, year_start_date=prev_fy_start_date, year_end_date=prev_fy_end_date
)

# make journal entry for previous year
je_1 = frappe.new_doc("Journal Entry")
je_1.posting_date = "1990-06-01"
je_1.posting_date = add_days(prev_fy_start_date, 20)
je_1.company = self.company
je_1.user_remark = "test"
je_1.set(
Expand All @@ -1888,28 +1876,24 @@ def test_reconciliation_on_closed_period_payment(self):
"credit_in_account_currency": 1000,
},
{
"account": bank_account,
"cost_center": self.sub_cc,
"account": self.bank,
"cost_center": self.sub_cc.name,
"credit_in_account_currency": 0,
"debit_in_account_currency": 500,
},
{
"account": "Cash - _PR",
"cost_center": self.sub_cc,
"account": self.cash,
"cost_center": self.sub_cc.name,
"credit_in_account_currency": 0,
"debit_in_account_currency": 500,
},
],
)
je_1.save()
je_1.submit()
je_1.reload()
# check journal entry is submitted
self.assertTrue(je_1.docstatus == 1)

# make period closing voucher
pcv = make_period_closing_voucher(
company=self.company, cost_center=self.cost_center, posting_date="1991-03-31"
company=self.company, cost_center=self.cost_center, posting_date=prev_fy_end_date
)
pcv.reload()
# check if period closing voucher is completed
Expand All @@ -1921,11 +1905,7 @@ def test_reconciliation_on_closed_period_payment(self):
)
je_2.accounts[0].party_type = "Customer"
je_2.accounts[0].party = self.customer
je_2.save()
je_2.submit()
je_2.reload()
# check journal entry is submitted
self.assertTrue(je_2.docstatus == 1)

# process reconciliation on closed period payment
pr = self.create_payment_reconciliation(party_is_customer=True)
Expand All @@ -1942,11 +1922,6 @@ def test_reconciliation_on_closed_period_payment(self):
self.assertEqual(pr.get("invoices"), [])
self.assertEqual(pr.get("payments"), [])

# cancel created entires during test
pcv.cancel()
je_1.cancel()
je_2.cancel()


def make_customer(customer_name, currency=None):
if not frappe.db.exists("Customer", customer_name):
Expand Down

0 comments on commit f456380

Please sign in to comment.