Merge pull request #24651 from ankush/ignore_gl_while_cancelling_so

fix(selling): cancel sales order with cancelled PE
This commit is contained in:
Deepesh Garg 2021-02-17 18:39:35 +05:30 committed by GitHub
commit c5b94adc87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 1 deletions

View File

@ -180,6 +180,7 @@ class SalesOrder(SellingController):
update_coupon_code_count(self.coupon_code,'used')
def on_cancel(self):
self.ignore_linked_doctypes = ('GL Entry', 'Stock Ledger Entry')
super(SalesOrder, self).on_cancel()
# Cannot cancel closed SO

View File

@ -17,6 +17,18 @@ from erpnext.selling.doctype.product_bundle.test_product_bundle import make_prod
from erpnext.stock.doctype.item.test_item import make_item
class TestSalesOrder(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.unlink_setting = int(frappe.db.get_value("Accounts Settings", "Accounts Settings",
"unlink_advance_payment_on_cancelation_of_order"))
@classmethod
def tearDownClass(cls) -> None:
# reset config to previous state
frappe.db.set_value("Accounts Settings", "Accounts Settings",
"unlink_advance_payment_on_cancelation_of_order", cls.unlink_setting)
def tearDown(self):
frappe.set_user("Administrator")
@ -1049,6 +1061,38 @@ class TestSalesOrder(unittest.TestCase):
self.assertRaises(frappe.LinkExistsError, so_doc.cancel)
def test_cancel_sales_order_after_cancel_payment_entry(self):
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
# make a sales order
so = make_sales_order()
# disable unlinking of payment entry
frappe.db.set_value("Accounts Settings", "Accounts Settings",
"unlink_advance_payment_on_cancelation_of_order", 0)
# create a payment entry against sales order
pe = get_payment_entry("Sales Order", so.name, bank_account="_Test Bank - _TC")
pe.reference_no = "1"
pe.reference_date = nowdate()
pe.paid_from_account_currency = so.currency
pe.paid_to_account_currency = so.currency
pe.source_exchange_rate = 1
pe.target_exchange_rate = 1
pe.paid_amount = so.grand_total
pe.save(ignore_permissions=True)
pe.submit()
# Cancel payment entry
po_doc = frappe.get_doc("Payment Entry", pe.name)
po_doc.cancel()
# Cancel sales order
try:
so_doc = frappe.get_doc('Sales Order', so.name)
so_doc.cancel()
except Exception:
self.fail("Can not cancel sales order with linked cancelled payment entry")
def test_request_for_raw_materials(self):
item = make_item("_Test Finished Item", {"is_stock_item": 1,
"maintain_stock": 1,
@ -1207,4 +1251,4 @@ def make_sales_order_workflow():
))
workflow.insert(ignore_permissions=True)
return workflow
return workflow