Merge branch 'hotfix'
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index f0ba6f2..ddaa155 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -2,7 +2,7 @@
from __future__ import unicode_literals
import frappe
-__version__ = '7.1.18'
+__version__ = '7.1.19'
def get_default_company(user=None):
'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 2802835..6ea163b 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -63,7 +63,7 @@
def on_cancel(self):
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
from erpnext.hr.doctype.salary_slip.salary_slip import unlink_ref_doc_from_salary_slip
- unlink_ref_doc_from_payment_entries(self.doctype, self.name)
+ unlink_ref_doc_from_payment_entries(self)
unlink_ref_doc_from_salary_slip(self.name)
self.make_gl_entries(1)
self.update_advance_paid()
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 5c2b62c..14459fa 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -583,7 +583,7 @@
if not self.is_return:
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
if frappe.db.get_single_value('Accounts Settings', 'unlink_payment_on_cancellation_of_invoice'):
- unlink_ref_doc_from_payment_entries(self.doctype, self.name)
+ unlink_ref_doc_from_payment_entries(self)
self.update_prevdoc_status()
self.update_billing_status_for_zero_amount_refdoc("Purchase Order")
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 4e0a6b4..5dce71f 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -138,7 +138,7 @@
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
if frappe.db.get_single_value('Accounts Settings', 'unlink_payment_on_cancellation_of_invoice'):
- unlink_ref_doc_from_payment_entries(self.doctype, self.name)
+ unlink_ref_doc_from_payment_entries(self)
if self.is_return:
# NOTE status updating bypassed for is_return
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index f3dc7ba..cec01a0 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -401,16 +401,22 @@
payment_entry.set_amounts()
payment_entry.save(ignore_permissions=True)
-def unlink_ref_doc_from_payment_entries(ref_type, ref_no):
- remove_ref_doc_link_from_jv(ref_type, ref_no)
- remove_ref_doc_link_from_pe(ref_type, ref_no)
+def unlink_ref_doc_from_payment_entries(ref_doc):
+ remove_ref_doc_link_from_jv(ref_doc.doctype, ref_doc.name)
+ remove_ref_doc_link_from_pe(ref_doc.doctype, ref_doc.name)
frappe.db.sql("""update `tabGL Entry`
set against_voucher_type=null, against_voucher=null,
modified=%s, modified_by=%s
where against_voucher_type=%s and against_voucher=%s
and voucher_no != ifnull(against_voucher, '')""",
- (now(), frappe.session.user, ref_type, ref_no))
+ (now(), frappe.session.user, ref_doc.doctype, ref_doc.name))
+
+ if ref_doc.doctype in ("Sales Invoice", "Purchase Invoice"):
+ ref_doc.set("advances", [])
+
+ frappe.db.sql("""delete from `tab{0} Advance` where parent = %s"""
+ .format(ref_doc.doctype), ref_doc.name)
def remove_ref_doc_link_from_jv(ref_type, ref_no):
linked_jv = frappe.db.sql_list("""select parent from `tabJournal Entry Account`
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index b436670..6d1412d 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -560,6 +560,21 @@
elif asset.status in ("Scrapped", "Cancelled", "Sold"):
frappe.throw(_("Row #{0}: Asset {1} cannot be submitted, it is already {2}")
.format(d.idx, d.asset, asset.status))
+
+ def delink_advance_entries(self, linked_doc_name):
+ total_allocated_amount = 0
+ for adv in self.advances:
+ consider_for_total_advance = True
+ if adv.reference_name == linked_doc_name:
+ frappe.db.sql("""delete from `tab{0} Advance`
+ where name = %s""".format(self.doctype), adv.name)
+ consider_for_total_advance = False
+
+ if consider_for_total_advance:
+ total_allocated_amount += flt(adv.allocated_amount, adv.precision("allocated_amount"))
+
+ frappe.db.set_value(self.doctype, self.name, "total_advance",
+ total_allocated_amount, update_modified=False)
@frappe.whitelist()
def get_tax_rate(account_head):
diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py
index 051334c..3cc79ef 100644
--- a/erpnext/utilities/transaction_base.py
+++ b/erpnext/utilities/transaction_base.py
@@ -125,20 +125,6 @@
ret = None
return ret
-
- def delink_advance_entries(self, linked_doc_name):
- total_allocated_amount = 0
- for adv in self.advances:
- consider_for_total_advance = True
- if adv.reference_name == linked_doc_name:
- frappe.db.sql("""delete from `tab{0} Advance`
- where name = %s""".format(self.doctype), adv.name)
- consider_for_total_advance = False
-
- if consider_for_total_advance:
- total_allocated_amount += flt(adv.allocated_amount, adv.precision("allocated_amount"))
-
- frappe.db.set_value(self.doctype, self.name, "total_advance", total_allocated_amount, update_modified=False)
def delete_events(ref_type, ref_name):
frappe.delete_doc("Event", frappe.db.sql_list("""select name from `tabEvent`