test: Added test for PCV cancellation
This commit is contained in:
parent
4caaab32d1
commit
914a388ee3
@ -8,7 +8,6 @@ from frappe.utils import flt
|
|||||||
|
|
||||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||||
get_accounting_dimensions,
|
get_accounting_dimensions,
|
||||||
get_dimensions,
|
|
||||||
)
|
)
|
||||||
from erpnext.accounts.utils import get_account_currency
|
from erpnext.accounts.utils import get_account_currency
|
||||||
from erpnext.controllers.accounts_controller import AccountsController
|
from erpnext.controllers.accounts_controller import AccountsController
|
||||||
@ -28,16 +27,18 @@ class PeriodClosingVoucher(AccountsController):
|
|||||||
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry")
|
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry")
|
||||||
gle_count = frappe.db.count(
|
gle_count = frappe.db.count(
|
||||||
"GL Entry",
|
"GL Entry",
|
||||||
{
|
{"voucher_type": "Period Closing Voucher", "voucher_no": self.name, "is_cancelled": 0},
|
||||||
"voucher_type": "Period Closing Voucher",
|
|
||||||
"voucher_no": self.name,
|
|
||||||
"is_cancelled": 0
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
if gle_count > 5000:
|
if gle_count > 5000:
|
||||||
frappe.enqueue(make_reverse_gl_entries, voucher_type="Period Closing Voucher",
|
frappe.enqueue(
|
||||||
voucher_no=self.name, queue="long")
|
make_reverse_gl_entries,
|
||||||
frappe.msgprint(_("The GL Entries will be cancelled in the background, it can take a few minutes."), alert=True)
|
voucher_type="Period Closing Voucher",
|
||||||
|
voucher_no=self.name,
|
||||||
|
queue="long",
|
||||||
|
)
|
||||||
|
frappe.msgprint(
|
||||||
|
_("The GL Entries will be cancelled in the background, it can take a few minutes."), alert=True
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
make_reverse_gl_entries(voucher_type="Period Closing Voucher", voucher_no=self.name)
|
make_reverse_gl_entries(voucher_type="Period Closing Voucher", voucher_no=self.name)
|
||||||
|
|
||||||
@ -82,7 +83,10 @@ class PeriodClosingVoucher(AccountsController):
|
|||||||
if gl_entries:
|
if gl_entries:
|
||||||
if len(gl_entries) > 5000:
|
if len(gl_entries) > 5000:
|
||||||
frappe.enqueue(process_gl_entries, gl_entries=gl_entries, queue="long")
|
frappe.enqueue(process_gl_entries, gl_entries=gl_entries, queue="long")
|
||||||
frappe.msgprint(_("The GL Entries will be processed in the background, it can take a few minutes."), alert=True)
|
frappe.msgprint(
|
||||||
|
_("The GL Entries will be processed in the background, it can take a few minutes."),
|
||||||
|
alert=True,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
process_gl_entries(gl_entries)
|
process_gl_entries(gl_entries)
|
||||||
|
|
||||||
@ -109,17 +113,13 @@ class PeriodClosingVoucher(AccountsController):
|
|||||||
"finance_book": acc.finance_book,
|
"finance_book": acc.finance_book,
|
||||||
"account_currency": acc.account_currency,
|
"account_currency": acc.account_currency,
|
||||||
"debit_in_account_currency": abs(flt(acc.bal_in_account_currency))
|
"debit_in_account_currency": abs(flt(acc.bal_in_account_currency))
|
||||||
if flt(acc.bal_in_account_currency) < 0
|
if flt(acc.bal_in_account_currency) < 0
|
||||||
else 0,
|
else 0,
|
||||||
"debit": abs(flt(acc.bal_in_company_currency))
|
"debit": abs(flt(acc.bal_in_company_currency)) if flt(acc.bal_in_company_currency) < 0 else 0,
|
||||||
if flt(acc.bal_in_company_currency) < 0
|
|
||||||
else 0,
|
|
||||||
"credit_in_account_currency": abs(flt(acc.bal_in_account_currency))
|
"credit_in_account_currency": abs(flt(acc.bal_in_account_currency))
|
||||||
if flt(acc.bal_in_account_currency) > 0
|
if flt(acc.bal_in_account_currency) > 0
|
||||||
else 0,
|
else 0,
|
||||||
"credit": abs(flt(acc.bal_in_company_currency))
|
"credit": abs(flt(acc.bal_in_company_currency)) if flt(acc.bal_in_company_currency) > 0 else 0,
|
||||||
if flt(acc.bal_in_company_currency) > 0
|
|
||||||
else 0,
|
|
||||||
},
|
},
|
||||||
item=acc,
|
item=acc,
|
||||||
)
|
)
|
||||||
@ -136,15 +136,11 @@ class PeriodClosingVoucher(AccountsController):
|
|||||||
"debit_in_account_currency": abs(flt(acc.bal_in_account_currency))
|
"debit_in_account_currency": abs(flt(acc.bal_in_account_currency))
|
||||||
if flt(acc.bal_in_account_currency) > 0
|
if flt(acc.bal_in_account_currency) > 0
|
||||||
else 0,
|
else 0,
|
||||||
"debit": abs(flt(acc.bal_in_company_currency))
|
"debit": abs(flt(acc.bal_in_company_currency)) if flt(acc.bal_in_company_currency) > 0 else 0,
|
||||||
if flt(acc.bal_in_company_currency) > 0
|
|
||||||
else 0,
|
|
||||||
"credit_in_account_currency": abs(flt(acc.bal_in_account_currency))
|
"credit_in_account_currency": abs(flt(acc.bal_in_account_currency))
|
||||||
if flt(acc.bal_in_account_currency) < 0
|
if flt(acc.bal_in_account_currency) < 0
|
||||||
else 0,
|
else 0,
|
||||||
"credit": abs(flt(acc.bal_in_company_currency))
|
"credit": abs(flt(acc.bal_in_company_currency)) if flt(acc.bal_in_company_currency) < 0 else 0,
|
||||||
if flt(acc.bal_in_company_currency) < 0
|
|
||||||
else 0,
|
|
||||||
},
|
},
|
||||||
item=acc,
|
item=acc,
|
||||||
)
|
)
|
||||||
@ -170,7 +166,8 @@ class PeriodClosingVoucher(AccountsController):
|
|||||||
if group_by_account:
|
if group_by_account:
|
||||||
dimension_fields.append("t1.account")
|
dimension_fields.append("t1.account")
|
||||||
|
|
||||||
return frappe.db.sql("""
|
return frappe.db.sql(
|
||||||
|
"""
|
||||||
select
|
select
|
||||||
t2.account_currency,
|
t2.account_currency,
|
||||||
{dimension_fields},
|
{dimension_fields},
|
||||||
@ -192,22 +189,30 @@ class PeriodClosingVoucher(AccountsController):
|
|||||||
as_dict=1,
|
as_dict=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def process_gl_entries(gl_entries):
|
def process_gl_entries(gl_entries):
|
||||||
from erpnext.accounts.general_ledger import make_gl_entries
|
from erpnext.accounts.general_ledger import make_gl_entries
|
||||||
|
|
||||||
try:
|
try:
|
||||||
make_gl_entries(gl_entries, merge_entries=False)
|
make_gl_entries(gl_entries, merge_entries=False)
|
||||||
frappe.db.set_value("Period Closing Voucher", gl_entries[0].get("voucher_no"), "status", "Completed")
|
frappe.db.set_value(
|
||||||
|
"Period Closing Voucher", gl_entries[0].get("voucher_no"), "status", "Completed"
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
frappe.db.rollback()
|
frappe.db.rollback()
|
||||||
frappe.log_error(e)
|
frappe.log_error(e)
|
||||||
frappe.db.set_value("Period Closing Voucher", gl_entries[0].get("voucher_no"), "status", "Failed")
|
frappe.db.set_value(
|
||||||
|
"Period Closing Voucher", gl_entries[0].get("voucher_no"), "status", "Failed"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def make_reverse_gl_entries(voucher_type, voucher_no):
|
def make_reverse_gl_entries(voucher_type, voucher_no):
|
||||||
from erpnext.accounts.general_ledger import make_reverse_gl_entries
|
from erpnext.accounts.general_ledger import make_reverse_gl_entries
|
||||||
|
|
||||||
try:
|
try:
|
||||||
make_reverse_gl_entries(voucher_type=voucher_type, voucher_no=voucher_no)
|
make_reverse_gl_entries(voucher_type=voucher_type, voucher_no=voucher_no)
|
||||||
frappe.db.set_value("Period Closing Voucher", voucher_no, "status", "Completed")
|
frappe.db.set_value("Period Closing Voucher", voucher_no, "status", "Completed")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
frappe.db.rollback()
|
frappe.db.rollback()
|
||||||
frappe.log_error(e)
|
frappe.log_error(e)
|
||||||
frappe.db.set_value("Period Closing Voucher", gl_entries[0].get("voucher_no"), "status", "Failed")
|
frappe.db.set_value("Period Closing Voucher", voucher_no, "status", "Failed")
|
||||||
|
@ -92,7 +92,6 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
pcv = self.make_period_closing_voucher(submit=False)
|
pcv = self.make_period_closing_voucher(submit=False)
|
||||||
pcv.cost_center_wise_pnl = 1
|
|
||||||
pcv.save()
|
pcv.save()
|
||||||
pcv.submit()
|
pcv.submit()
|
||||||
surplus_account = pcv.closing_account_head
|
surplus_account = pcv.closing_account_head
|
||||||
@ -115,6 +114,16 @@ class TestPeriodClosingVoucher(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(pcv_gle, expected_gle)
|
self.assertEqual(pcv_gle, expected_gle)
|
||||||
|
|
||||||
|
pcv.reload()
|
||||||
|
pcv.cancel()
|
||||||
|
|
||||||
|
self.assertFalse(
|
||||||
|
frappe.db.get_value(
|
||||||
|
"GL Entry",
|
||||||
|
{"voucher_type": "Period Closing Voucher", "voucher_no": pcv.name, "is_cancelled": 0},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def test_period_closing_with_finance_book_entries(self):
|
def test_period_closing_with_finance_book_entries(self):
|
||||||
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
|
frappe.db.sql("delete from `tabGL Entry` where company='Test PCV Company'")
|
||||||
|
|
||||||
|
@ -291,6 +291,7 @@ def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False):
|
|||||||
for entry in gl_map:
|
for entry in gl_map:
|
||||||
make_entry(entry, adv_adj, update_outstanding, from_repost)
|
make_entry(entry, adv_adj, update_outstanding, from_repost)
|
||||||
|
|
||||||
|
|
||||||
def make_entry(args, adv_adj, update_outstanding, from_repost=False):
|
def make_entry(args, adv_adj, update_outstanding, from_repost=False):
|
||||||
gle = frappe.new_doc("GL Entry")
|
gle = frappe.new_doc("GL Entry")
|
||||||
gle.update(args)
|
gle.update(args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user