test: Add test case for closing balance
This commit is contained in:
parent
3249a79f07
commit
f0267feca8
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.utils import cint, cstr
|
||||||
|
|
||||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||||
get_accounting_dimensions,
|
get_accounting_dimensions,
|
||||||
@ -65,25 +66,26 @@ def aggregate_with_last_account_closing_balance(entries, accounting_dimensions):
|
|||||||
|
|
||||||
def generate_key(entry, accounting_dimensions):
|
def generate_key(entry, accounting_dimensions):
|
||||||
key = [
|
key = [
|
||||||
entry.get("account"),
|
cstr(entry.get("account")),
|
||||||
entry.get("account_currency"),
|
cstr(entry.get("account_currency")),
|
||||||
entry.get("cost_center"),
|
cstr(entry.get("cost_center")),
|
||||||
entry.get("project"),
|
cstr(entry.get("project")),
|
||||||
entry.get("finance_book"),
|
cstr(entry.get("finance_book")),
|
||||||
entry.get("is_period_closing_voucher_entry"),
|
cint(entry.get("is_period_closing_voucher_entry")),
|
||||||
]
|
]
|
||||||
|
|
||||||
key_values = {
|
key_values = {
|
||||||
"account": entry.get("account"),
|
"company": cstr(entry.get("company")),
|
||||||
"account_currency": entry.get("account_currency"),
|
"account": cstr(entry.get("account")),
|
||||||
"cost_center": entry.get("cost_center"),
|
"account_currency": cstr(entry.get("account_currency")),
|
||||||
"project": entry.get("project"),
|
"cost_center": cstr(entry.get("cost_center")),
|
||||||
"finance_book": entry.get("finance_book"),
|
"project": cstr(entry.get("project")),
|
||||||
"is_period_closing_voucher_entry": entry.get("is_period_closing_voucher_entry"),
|
"finance_book": cstr(entry.get("finance_book")),
|
||||||
|
"is_period_closing_voucher_entry": cint(entry.get("is_period_closing_voucher_entry")),
|
||||||
}
|
}
|
||||||
for dimension in accounting_dimensions:
|
for dimension in accounting_dimensions:
|
||||||
key.append(entry.get(dimension))
|
key.append(cstr(entry.get(dimension)))
|
||||||
key_values[dimension] = entry.get(dimension)
|
key_values[dimension] = cstr(entry.get(dimension))
|
||||||
|
|
||||||
return tuple(key), key_values
|
return tuple(key), key_values
|
||||||
|
|
||||||
@ -101,6 +103,7 @@ def get_previous_closing_entries(company, closing_date, accounting_dimensions):
|
|||||||
if last_period_closing_voucher:
|
if last_period_closing_voucher:
|
||||||
account_closing_balance = frappe.qb.DocType("Account Closing Balance")
|
account_closing_balance = frappe.qb.DocType("Account Closing Balance")
|
||||||
query = frappe.qb.from_(account_closing_balance).select(
|
query = frappe.qb.from_(account_closing_balance).select(
|
||||||
|
account_closing_balance.company,
|
||||||
account_closing_balance.account,
|
account_closing_balance.account,
|
||||||
account_closing_balance.account_currency,
|
account_closing_balance.account_currency,
|
||||||
account_closing_balance.debit,
|
account_closing_balance.debit,
|
||||||
|
@ -144,6 +144,7 @@ class PeriodClosingVoucher(AccountsController):
|
|||||||
def get_gle_for_pl_account(self, acc):
|
def get_gle_for_pl_account(self, acc):
|
||||||
gl_entry = self.get_gl_dict(
|
gl_entry = self.get_gl_dict(
|
||||||
{
|
{
|
||||||
|
"company": self.company,
|
||||||
"closing_date": self.posting_date,
|
"closing_date": self.posting_date,
|
||||||
"account": acc.account,
|
"account": acc.account,
|
||||||
"cost_center": acc.cost_center,
|
"cost_center": acc.cost_center,
|
||||||
@ -167,6 +168,7 @@ class PeriodClosingVoucher(AccountsController):
|
|||||||
def get_gle_for_closing_account(self, acc):
|
def get_gle_for_closing_account(self, acc):
|
||||||
gl_entry = self.get_gl_dict(
|
gl_entry = self.get_gl_dict(
|
||||||
{
|
{
|
||||||
|
"company": self.company,
|
||||||
"closing_date": self.posting_date,
|
"closing_date": self.posting_date,
|
||||||
"account": self.closing_account_head,
|
"account": self.closing_account_head,
|
||||||
"cost_center": acc.cost_center,
|
"cost_center": acc.cost_center,
|
||||||
@ -190,6 +192,7 @@ class PeriodClosingVoucher(AccountsController):
|
|||||||
def get_closing_entries(self, acc):
|
def get_closing_entries(self, acc):
|
||||||
closing_entry = self.get_gl_dict(
|
closing_entry = self.get_gl_dict(
|
||||||
{
|
{
|
||||||
|
"company": self.company,
|
||||||
"closing_date": self.posting_date,
|
"closing_date": self.posting_date,
|
||||||
"period_closing_voucher": self.name,
|
"period_closing_voucher": self.name,
|
||||||
"account": acc.account,
|
"account": acc.account,
|
||||||
@ -293,18 +296,10 @@ class PeriodClosingVoucher(AccountsController):
|
|||||||
return query.run(as_dict=1)
|
return query.run(as_dict=1)
|
||||||
|
|
||||||
|
|
||||||
def process_closing_entries(closing_entries):
|
|
||||||
from erpnext.accounts.doctype.closing_balance.closing_balance import make_closing_entries
|
|
||||||
|
|
||||||
try:
|
|
||||||
make_closing_entries(closing_entries)
|
|
||||||
except Exception as e:
|
|
||||||
frappe.db.rollback()
|
|
||||||
frappe.log_error(e)
|
|
||||||
|
|
||||||
|
|
||||||
def process_gl_entries(gl_entries, closing_entries, voucher_name=None):
|
def process_gl_entries(gl_entries, closing_entries, voucher_name=None):
|
||||||
from erpnext.accounts.doctype.closing_balance.closing_balance import make_closing_entries
|
from erpnext.accounts.doctype.account_closing_balance.account_closing_balance import (
|
||||||
|
make_closing_entries,
|
||||||
|
)
|
||||||
from erpnext.accounts.general_ledger import make_gl_entries
|
from erpnext.accounts.general_ledger import make_gl_entries
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -205,7 +205,99 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertRaises(frappe.ValidationError, jv1.submit)
|
self.assertRaises(frappe.ValidationError, jv1.submit)
|
||||||
|
|
||||||
# def test_closing_balance_with_dimensions(self):
|
def test_closing_balance_with_dimensions(self):
|
||||||
|
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
|
||||||
|
frappe.db.sql("delete from `tabPeriod Closing Voucher` where company='Test PCV Company'")
|
||||||
|
frappe.db.sql("delete from `tabAccount Closing Balance` where company='Test PCV Company'")
|
||||||
|
|
||||||
|
company = create_company()
|
||||||
|
cost_center1 = create_cost_center("Test Cost Center 1")
|
||||||
|
cost_center2 = create_cost_center("Test Cost Center 2")
|
||||||
|
|
||||||
|
jv1 = make_journal_entry(
|
||||||
|
posting_date="2021-03-15",
|
||||||
|
amount=400,
|
||||||
|
account1="Cash - TPC",
|
||||||
|
account2="Sales - TPC",
|
||||||
|
cost_center=cost_center1,
|
||||||
|
save=False,
|
||||||
|
)
|
||||||
|
jv1.company = company
|
||||||
|
jv1.save()
|
||||||
|
jv1.submit()
|
||||||
|
|
||||||
|
jv2 = make_journal_entry(
|
||||||
|
posting_date="2021-03-15",
|
||||||
|
amount=200,
|
||||||
|
account1="Cash - TPC",
|
||||||
|
account2="Sales - TPC",
|
||||||
|
cost_center=cost_center2,
|
||||||
|
save=False,
|
||||||
|
)
|
||||||
|
jv2.company = company
|
||||||
|
jv2.save()
|
||||||
|
jv2.submit()
|
||||||
|
|
||||||
|
pcv1 = self.make_period_closing_voucher(posting_date="2021-03-31")
|
||||||
|
|
||||||
|
closing_balance = frappe.db.get_value(
|
||||||
|
"Account Closing Balance",
|
||||||
|
{
|
||||||
|
"account": "Sales - TPC",
|
||||||
|
"cost_center": cost_center1,
|
||||||
|
"period_closing_voucher": pcv1.name,
|
||||||
|
"is_period_closing_voucher_entry": 0,
|
||||||
|
},
|
||||||
|
["credit", "credit_in_account_currency"],
|
||||||
|
as_dict=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(closing_balance.credit, 400)
|
||||||
|
self.assertEqual(closing_balance.credit_in_account_currency, 400)
|
||||||
|
|
||||||
|
jv3 = make_journal_entry(
|
||||||
|
posting_date="2022-03-15",
|
||||||
|
amount=300,
|
||||||
|
account1="Cash - TPC",
|
||||||
|
account2="Sales - TPC",
|
||||||
|
cost_center=cost_center2,
|
||||||
|
save=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
jv3.company = company
|
||||||
|
jv3.save()
|
||||||
|
jv3.submit()
|
||||||
|
|
||||||
|
pcv2 = self.make_period_closing_voucher(posting_date="2022-03-31")
|
||||||
|
|
||||||
|
cc1_closing_balance = frappe.db.get_value(
|
||||||
|
"Account Closing Balance",
|
||||||
|
{
|
||||||
|
"account": "Sales - TPC",
|
||||||
|
"cost_center": cost_center1,
|
||||||
|
"period_closing_voucher": pcv2.name,
|
||||||
|
"is_period_closing_voucher_entry": 0,
|
||||||
|
},
|
||||||
|
["credit", "credit_in_account_currency"],
|
||||||
|
as_dict=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
cc2_closing_balance = frappe.db.get_value(
|
||||||
|
"Account Closing Balance",
|
||||||
|
{
|
||||||
|
"account": "Sales - TPC",
|
||||||
|
"cost_center": cost_center2,
|
||||||
|
"period_closing_voucher": pcv2.name,
|
||||||
|
"is_period_closing_voucher_entry": 0,
|
||||||
|
},
|
||||||
|
["credit", "credit_in_account_currency"],
|
||||||
|
as_dict=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(cc1_closing_balance.credit, 400)
|
||||||
|
self.assertEqual(cc1_closing_balance.credit_in_account_currency, 400)
|
||||||
|
self.assertEqual(cc2_closing_balance.credit, 500)
|
||||||
|
self.assertEqual(cc2_closing_balance.credit_in_account_currency, 500)
|
||||||
|
|
||||||
def make_period_closing_voucher(self, posting_date=None, submit=True):
|
def make_period_closing_voucher(self, posting_date=None, submit=True):
|
||||||
surplus_account = create_account()
|
surplus_account = create_account()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user