Merge pull request #38684 from frappe/mergify/bp/version-15-hotfix/pr-38679
refactor(test): repost utility deletion flag test (backport #38679)
This commit is contained in:
commit
fc79c6bf54
@ -126,7 +126,7 @@ class RepostAccountingLedger(Document):
|
|||||||
return rendered_page
|
return rendered_page
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
if len(self.vouchers) > 1:
|
if len(self.vouchers) > 5:
|
||||||
job_name = "repost_accounting_ledger_" + self.name
|
job_name = "repost_accounting_ledger_" + self.name
|
||||||
frappe.enqueue(
|
frappe.enqueue(
|
||||||
method="erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger.start_repost",
|
method="erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger.start_repost",
|
||||||
@ -170,8 +170,6 @@ def start_repost(account_repost_doc=str) -> None:
|
|||||||
doc.make_gl_entries(1)
|
doc.make_gl_entries(1)
|
||||||
doc.make_gl_entries()
|
doc.make_gl_entries()
|
||||||
|
|
||||||
frappe.db.commit()
|
|
||||||
|
|
||||||
|
|
||||||
def get_allowed_types_from_settings():
|
def get_allowed_types_from_settings():
|
||||||
return [
|
return [
|
||||||
|
|||||||
@ -20,18 +20,11 @@ class TestRepostAccountingLedger(AccountsTestMixin, FrappeTestCase):
|
|||||||
self.create_company()
|
self.create_company()
|
||||||
self.create_customer()
|
self.create_customer()
|
||||||
self.create_item()
|
self.create_item()
|
||||||
self.update_repost_settings()
|
update_repost_settings()
|
||||||
|
|
||||||
def teadDown(self):
|
def teadDown(self):
|
||||||
frappe.db.rollback()
|
frappe.db.rollback()
|
||||||
|
|
||||||
def update_repost_settings(self):
|
|
||||||
allowed_types = ["Sales Invoice", "Purchase Invoice", "Payment Entry", "Journal Entry"]
|
|
||||||
repost_settings = frappe.get_doc("Repost Accounting Ledger Settings")
|
|
||||||
for x in allowed_types:
|
|
||||||
repost_settings.append("allowed_types", {"document_type": x, "allowed": True})
|
|
||||||
repost_settings.save()
|
|
||||||
|
|
||||||
def test_01_basic_functions(self):
|
def test_01_basic_functions(self):
|
||||||
si = create_sales_invoice(
|
si = create_sales_invoice(
|
||||||
item=self.item,
|
item=self.item,
|
||||||
@ -90,9 +83,6 @@ class TestRepostAccountingLedger(AccountsTestMixin, FrappeTestCase):
|
|||||||
# Submit repost document
|
# Submit repost document
|
||||||
ral.save().submit()
|
ral.save().submit()
|
||||||
|
|
||||||
# background jobs don't run on test cases. Manually triggering repost function.
|
|
||||||
start_repost(ral.name)
|
|
||||||
|
|
||||||
res = (
|
res = (
|
||||||
qb.from_(gl)
|
qb.from_(gl)
|
||||||
.select(gl.voucher_no, Sum(gl.debit).as_("debit"), Sum(gl.credit).as_("credit"))
|
.select(gl.voucher_no, Sum(gl.debit).as_("debit"), Sum(gl.credit).as_("credit"))
|
||||||
@ -177,26 +167,6 @@ class TestRepostAccountingLedger(AccountsTestMixin, FrappeTestCase):
|
|||||||
pe = get_payment_entry(si.doctype, si.name)
|
pe = get_payment_entry(si.doctype, si.name)
|
||||||
pe.save().submit()
|
pe.save().submit()
|
||||||
|
|
||||||
# without deletion flag set
|
|
||||||
ral = frappe.new_doc("Repost Accounting Ledger")
|
|
||||||
ral.company = self.company
|
|
||||||
ral.delete_cancelled_entries = False
|
|
||||||
ral.append("vouchers", {"voucher_type": si.doctype, "voucher_no": si.name})
|
|
||||||
ral.append("vouchers", {"voucher_type": pe.doctype, "voucher_no": pe.name})
|
|
||||||
ral.save()
|
|
||||||
|
|
||||||
# assert preview data is generated
|
|
||||||
preview = ral.generate_preview()
|
|
||||||
self.assertIsNotNone(preview)
|
|
||||||
|
|
||||||
ral.save().submit()
|
|
||||||
|
|
||||||
# background jobs don't run on test cases. Manually triggering repost function.
|
|
||||||
start_repost(ral.name)
|
|
||||||
|
|
||||||
self.assertIsNotNone(frappe.db.exists("GL Entry", {"voucher_no": si.name, "is_cancelled": 1}))
|
|
||||||
self.assertIsNotNone(frappe.db.exists("GL Entry", {"voucher_no": pe.name, "is_cancelled": 1}))
|
|
||||||
|
|
||||||
# with deletion flag set
|
# with deletion flag set
|
||||||
ral = frappe.new_doc("Repost Accounting Ledger")
|
ral = frappe.new_doc("Repost Accounting Ledger")
|
||||||
ral.company = self.company
|
ral.company = self.company
|
||||||
@ -205,6 +175,38 @@ class TestRepostAccountingLedger(AccountsTestMixin, FrappeTestCase):
|
|||||||
ral.append("vouchers", {"voucher_type": pe.doctype, "voucher_no": pe.name})
|
ral.append("vouchers", {"voucher_type": pe.doctype, "voucher_no": pe.name})
|
||||||
ral.save().submit()
|
ral.save().submit()
|
||||||
|
|
||||||
start_repost(ral.name)
|
|
||||||
self.assertIsNone(frappe.db.exists("GL Entry", {"voucher_no": si.name, "is_cancelled": 1}))
|
self.assertIsNone(frappe.db.exists("GL Entry", {"voucher_no": si.name, "is_cancelled": 1}))
|
||||||
self.assertIsNone(frappe.db.exists("GL Entry", {"voucher_no": pe.name, "is_cancelled": 1}))
|
self.assertIsNone(frappe.db.exists("GL Entry", {"voucher_no": pe.name, "is_cancelled": 1}))
|
||||||
|
|
||||||
|
def test_05_without_deletion_flag(self):
|
||||||
|
si = create_sales_invoice(
|
||||||
|
item=self.item,
|
||||||
|
company=self.company,
|
||||||
|
customer=self.customer,
|
||||||
|
debit_to=self.debit_to,
|
||||||
|
parent_cost_center=self.cost_center,
|
||||||
|
cost_center=self.cost_center,
|
||||||
|
rate=100,
|
||||||
|
)
|
||||||
|
|
||||||
|
pe = get_payment_entry(si.doctype, si.name)
|
||||||
|
pe.save().submit()
|
||||||
|
|
||||||
|
# without deletion flag set
|
||||||
|
ral = frappe.new_doc("Repost Accounting Ledger")
|
||||||
|
ral.company = self.company
|
||||||
|
ral.delete_cancelled_entries = False
|
||||||
|
ral.append("vouchers", {"voucher_type": si.doctype, "voucher_no": si.name})
|
||||||
|
ral.append("vouchers", {"voucher_type": pe.doctype, "voucher_no": pe.name})
|
||||||
|
ral.save().submit()
|
||||||
|
|
||||||
|
self.assertIsNotNone(frappe.db.exists("GL Entry", {"voucher_no": si.name, "is_cancelled": 1}))
|
||||||
|
self.assertIsNotNone(frappe.db.exists("GL Entry", {"voucher_no": pe.name, "is_cancelled": 1}))
|
||||||
|
|
||||||
|
|
||||||
|
def update_repost_settings():
|
||||||
|
allowed_types = ["Sales Invoice", "Purchase Invoice", "Payment Entry", "Journal Entry"]
|
||||||
|
repost_settings = frappe.get_doc("Repost Accounting Ledger Settings")
|
||||||
|
for x in allowed_types:
|
||||||
|
repost_settings.append("allowed_types", {"document_type": x, "allowed": True})
|
||||||
|
repost_settings.save()
|
||||||
|
|||||||
@ -2799,6 +2799,12 @@ class TestSalesInvoice(FrappeTestCase):
|
|||||||
@change_settings("Selling Settings", {"enable_discount_accounting": 1})
|
@change_settings("Selling Settings", {"enable_discount_accounting": 1})
|
||||||
def test_additional_discount_for_sales_invoice_with_discount_accounting_enabled(self):
|
def test_additional_discount_for_sales_invoice_with_discount_accounting_enabled(self):
|
||||||
|
|
||||||
|
from erpnext.accounts.doctype.repost_accounting_ledger.test_repost_accounting_ledger import (
|
||||||
|
update_repost_settings,
|
||||||
|
)
|
||||||
|
|
||||||
|
update_repost_settings()
|
||||||
|
|
||||||
additional_discount_account = create_account(
|
additional_discount_account = create_account(
|
||||||
account_name="Discount Account",
|
account_name="Discount Account",
|
||||||
parent_account="Indirect Expenses - _TC",
|
parent_account="Indirect Expenses - _TC",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user