mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-05 13:24:47 +00:00
refactor(test): remove flaky test in process pcv
This commit is contained in:
@@ -1,187 +1,4 @@
|
|||||||
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and Contributors
|
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
|
|
||||||
import unittest
|
# import frappe
|
||||||
|
|
||||||
import frappe
|
|
||||||
from frappe.utils import today
|
|
||||||
|
|
||||||
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
|
|
||||||
from erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher import (
|
|
||||||
process_individual_date,
|
|
||||||
)
|
|
||||||
from erpnext.accounts.utils import get_fiscal_year
|
|
||||||
|
|
||||||
|
|
||||||
class TestProcessPeriodClosingVoucher(unittest.TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
self.company = create_company()
|
|
||||||
frappe.db.set_single_value("Accounts Settings", "use_legacy_controller_for_pcv", 0)
|
|
||||||
|
|
||||||
def make_period_closing_voucher(self, posting_date, submit=True):
|
|
||||||
fy = get_fiscal_year(posting_date, company=self.company)
|
|
||||||
pcv = frappe.get_doc(
|
|
||||||
{
|
|
||||||
"doctype": "Period Closing Voucher",
|
|
||||||
"transaction_date": posting_date or today(),
|
|
||||||
"period_start_date": fy[1],
|
|
||||||
"period_end_date": fy[2],
|
|
||||||
"company": self.company,
|
|
||||||
"fiscal_year": fy[0],
|
|
||||||
"closing_account_head": "Retained Earnings - TPP",
|
|
||||||
"remarks": "closing",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
pcv.insert()
|
|
||||||
if submit:
|
|
||||||
pcv.submit()
|
|
||||||
|
|
||||||
return pcv
|
|
||||||
|
|
||||||
def make_process_pcv(self):
|
|
||||||
self.pcv = self.make_period_closing_voucher(posting_date=today(), submit=False)
|
|
||||||
ppcv = frappe.get_doc(
|
|
||||||
{
|
|
||||||
"doctype": "Process Period Closing Voucher",
|
|
||||||
"parent_pcv": self.pcv.name,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
ppcv.save()
|
|
||||||
return ppcv
|
|
||||||
|
|
||||||
def set_processing_date_status(self, date, ppcv, rpt_type, parentfield, status):
|
|
||||||
frappe.db.set_value(
|
|
||||||
"Process Period Closing Voucher Detail",
|
|
||||||
{"processing_date": date, "parent": ppcv, "report_type": rpt_type, "parentfield": parentfield},
|
|
||||||
"status",
|
|
||||||
status,
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_processing_date_closing_balance(self, date, ppcv, rpt_type, parentfield):
|
|
||||||
return frappe.db.get_value(
|
|
||||||
"Process Period Closing Voucher Detail",
|
|
||||||
{"processing_date": date, "parent": ppcv, "report_type": rpt_type, "parentfield": parentfield},
|
|
||||||
"closing_balance",
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_opening_balance_double_counting(self):
|
|
||||||
ppcv = self.make_process_pcv()
|
|
||||||
self.assertEqual(self.pcv.is_first_period_closing_voucher(), True)
|
|
||||||
opening_jv = make_journal_entry(
|
|
||||||
posting_date=today(),
|
|
||||||
amount=10,
|
|
||||||
account1="Cash - TPP",
|
|
||||||
account2="Debtors - TPP",
|
|
||||||
company=self.company,
|
|
||||||
save=False,
|
|
||||||
)
|
|
||||||
opening_jv.accounts[1].party_type = "Customer"
|
|
||||||
opening_jv.accounts[1].party = "_Test Customer"
|
|
||||||
opening_jv.is_opening = "Yes"
|
|
||||||
opening_jv.save()
|
|
||||||
opening_jv.submit()
|
|
||||||
|
|
||||||
jv = make_journal_entry(
|
|
||||||
posting_date=today(),
|
|
||||||
amount=120,
|
|
||||||
account1="Debtors - TPP",
|
|
||||||
account2="Sales - TPP",
|
|
||||||
company=self.company,
|
|
||||||
save=False,
|
|
||||||
)
|
|
||||||
jv.accounts[0].party_type = "Customer"
|
|
||||||
jv.accounts[0].party = "_Test Customer"
|
|
||||||
jv.save()
|
|
||||||
jv.submit()
|
|
||||||
|
|
||||||
# P&L balance
|
|
||||||
parentfield = "normal_balances"
|
|
||||||
rpt_type = "Profit and Loss"
|
|
||||||
# status has to be set to 'Running' for logic to run
|
|
||||||
self.set_processing_date_status(today(), ppcv.name, rpt_type, parentfield, "Running")
|
|
||||||
process_individual_date(ppcv.name, today(), rpt_type, parentfield)
|
|
||||||
bal = frappe.parse_json(
|
|
||||||
self.get_processing_date_closing_balance(today(), ppcv.name, rpt_type, parentfield)
|
|
||||||
)
|
|
||||||
self.assertEqual(len(bal), 1)
|
|
||||||
expected_pl = {
|
|
||||||
"account": "Sales - TPP",
|
|
||||||
"cost_center": "_Test Cost Center - TPP",
|
|
||||||
"debit": 0.0,
|
|
||||||
"credit": 120.0,
|
|
||||||
"debit_in_account_currency": 0.0,
|
|
||||||
"credit_in_account_currency": 120.0,
|
|
||||||
}
|
|
||||||
for k in expected_pl.keys():
|
|
||||||
with self.subTest(k):
|
|
||||||
self.assertEqual(expected_pl[k], bal[0][k])
|
|
||||||
|
|
||||||
# Balance sheet balance
|
|
||||||
rpt_type = "Balance Sheet"
|
|
||||||
self.set_processing_date_status(today(), ppcv.name, rpt_type, parentfield, "Running")
|
|
||||||
process_individual_date(ppcv.name, today(), rpt_type, parentfield)
|
|
||||||
bal = frappe.parse_json(
|
|
||||||
self.get_processing_date_closing_balance(today(), ppcv.name, rpt_type, parentfield)
|
|
||||||
)
|
|
||||||
self.assertEqual(len(bal), 1)
|
|
||||||
expected_bs = {
|
|
||||||
"account": "Debtors - TPP",
|
|
||||||
"cost_center": "_Test Cost Center - TPP",
|
|
||||||
"debit": 120.0,
|
|
||||||
"credit": 0.0,
|
|
||||||
"debit_in_account_currency": 120.0,
|
|
||||||
"credit_in_account_currency": 0.0,
|
|
||||||
}
|
|
||||||
for k in expected_bs.keys():
|
|
||||||
with self.subTest(k):
|
|
||||||
self.assertEqual(expected_bs[k], bal[0][k])
|
|
||||||
|
|
||||||
# Opening balance
|
|
||||||
parentfield = "z_opening_balances"
|
|
||||||
rpt_type = "Balance Sheet"
|
|
||||||
self.set_processing_date_status(today(), ppcv.name, rpt_type, parentfield, "Running")
|
|
||||||
process_individual_date(ppcv.name, today(), rpt_type, parentfield)
|
|
||||||
bal = frappe.parse_json(
|
|
||||||
self.get_processing_date_closing_balance(today(), ppcv.name, rpt_type, parentfield)
|
|
||||||
)
|
|
||||||
self.assertEqual(len(bal), 2)
|
|
||||||
opening_cash = next(x for x in bal if x["account"] == "Cash - TPP")
|
|
||||||
expected_opening_cash = {
|
|
||||||
"account": "Cash - TPP",
|
|
||||||
"cost_center": "_Test Cost Center - TPP",
|
|
||||||
"debit": 10.0,
|
|
||||||
"credit": 0.0,
|
|
||||||
"debit_in_account_currency": 10.0,
|
|
||||||
"credit_in_account_currency": 0.0,
|
|
||||||
"account_currency": "INR",
|
|
||||||
}
|
|
||||||
for k in expected_opening_cash.keys():
|
|
||||||
with self.subTest(k):
|
|
||||||
self.assertEqual(expected_opening_cash[k], opening_cash[k])
|
|
||||||
|
|
||||||
opening_debtors = next(x for x in bal if x["account"] == "Debtors - TPP")
|
|
||||||
expected_opening_debtors = {
|
|
||||||
"account": "Debtors - TPP",
|
|
||||||
"cost_center": "_Test Cost Center - TPP",
|
|
||||||
"debit": 0.0,
|
|
||||||
"credit": 10.0,
|
|
||||||
"debit_in_account_currency": 0.0,
|
|
||||||
"credit_in_account_currency": 10.0,
|
|
||||||
"account_currency": "INR",
|
|
||||||
}
|
|
||||||
for k in expected_opening_debtors.keys():
|
|
||||||
with self.subTest(k):
|
|
||||||
self.assertEqual(expected_opening_debtors[k], opening_debtors[k])
|
|
||||||
|
|
||||||
|
|
||||||
def create_company():
|
|
||||||
company = frappe.get_doc(
|
|
||||||
{
|
|
||||||
"doctype": "Company",
|
|
||||||
"company_name": "Test Procss PCV",
|
|
||||||
"country": "India",
|
|
||||||
"default_currency": "INR",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
company.insert(ignore_if_duplicate=True)
|
|
||||||
return company.name
|
|
||||||
|
|||||||
Reference in New Issue
Block a user