diff --git a/erpnext/__init__.py b/erpnext/__init__.py index f0ba6f2f8d..ddaa1550d6 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 9d891a59e3..2f3b101f33 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -68,7 +68,7 @@ class JournalEntry(AccountsController): 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 5c2b62cd02..14459fa497 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -583,7 +583,7 @@ class PurchaseInvoice(BuyingController): 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 4e0a6b493c..5dce71f9c7 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -138,7 +138,7 @@ class SalesInvoice(SellingController): 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 f3dc7bac56..cec01a0842 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -401,16 +401,22 @@ def update_reference_in_payment_entry(d, payment_entry): 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 eec07db909..5796a4da10 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -565,6 +565,21 @@ class AccountsController(TransactionBase): 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) def group_similar_items(self): group_item_qty = {} diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py index 051334ca86..3cc79ef713 100644 --- a/erpnext/utilities/transaction_base.py +++ b/erpnext/utilities/transaction_base.py @@ -125,20 +125,6 @@ class TransactionBase(StatusUpdater): 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`