diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index c17f775a4e7..d1630f3ea69 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -84,7 +84,7 @@ class PaymentEntry(AccountsController):
self.delink_advance_entry_references()
self.update_payment_schedule(cancel=1)
self.set_payment_req_status()
- self.set_status()
+ self.set_status(update=True)
def set_payment_req_status(self):
from erpnext.accounts.doctype.payment_request.payment_request import update_payment_req_status
@@ -279,7 +279,7 @@ class PaymentEntry(AccountsController):
outstanding_amount, is_return = frappe.get_cached_value(d.reference_doctype, d.reference_name, ["outstanding_amount", "is_return"])
if outstanding_amount <= 0 and not is_return:
no_oustanding_refs.setdefault(d.reference_doctype, []).append(d)
-
+
for k, v in no_oustanding_refs.items():
frappe.msgprint(_("{} - {} now have {} as they had no outstanding amount left before submitting the Payment Entry.
\
If this is undesirable please cancel the corresponding Payment Entry.")
@@ -340,7 +340,7 @@ class PaymentEntry(AccountsController):
frappe.db.sql(""" UPDATE `tabPayment Schedule` SET paid_amount = `paid_amount` + %s
WHERE parent = %s and payment_term = %s""", (amount, key[1], key[0]))
- def set_status(self):
+ def set_status(self, update=False):
if self.docstatus == 2:
self.status = 'Cancelled'
elif self.docstatus == 1:
@@ -348,6 +348,9 @@ class PaymentEntry(AccountsController):
else:
self.status = 'Draft'
+ if update:
+ self.db_set('status', self.status)
+
def set_amounts(self):
self.set_amounts_in_company_currency()
self.set_total_allocated_amount()
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 831541ccb1f..afb6db35f27 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -677,3 +677,4 @@ erpnext.patches.v12_0.set_multi_uom_in_rfq
erpnext.patches.v12_0.update_state_code_for_daman_and_diu
erpnext.patches.v12_0.rename_lost_reason_detail
erpnext.patches.v12_0.update_leave_application_status
+erpnext.patches.v12_0.update_payment_entry_status
\ No newline at end of file
diff --git a/erpnext/patches/v12_0/update_payment_entry_status.py b/erpnext/patches/v12_0/update_payment_entry_status.py
new file mode 100644
index 00000000000..8d033800af3
--- /dev/null
+++ b/erpnext/patches/v12_0/update_payment_entry_status.py
@@ -0,0 +1,7 @@
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+ frappe.reload_doc("accounts", "doctype", "payment_entry")
+
+ frappe.db.sql(""" UPDATE `tabPayment Entry` set status = 'Cancelled' WHERE docstatus = 2 """)
\ No newline at end of file