From 866c2959896a7a5075ce0fc8d0826cb49d69f4dd Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 15 Nov 2016 17:18:44 +0530 Subject: [PATCH] [fix] on jv cancel remove linkings from advance table of Sales/Purchase Invoice --- .../accounts/doctype/journal_entry/journal_entry.py | 13 +++++++++++-- erpnext/utilities/transaction_base.py | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 145ed815642..a30fec90b60 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -64,11 +64,20 @@ class JournalEntry(AccountsController): 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_salary_slip(self.name) + unlink_ref_doc_from_salary_slip(self.name) self.make_gl_entries(1) self.update_advance_paid() self.update_expense_claim() - + self.unlink_advance_entry_reference() + + def unlink_advance_entry_reference(self): + for d in self.get("accounts"): + if d.is_advance and d.reference_type in ("Sales Invoice", "Purchase Invoice"): + doc = frappe.get_doc(d.reference_type, d.reference_name) + doc.delink_advance_entries(self.name) + d.reference_type = '' + d.reference_name = '' + d.db_update() def validate_party(self): for d in self.get("accounts"): diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py index 3cc79ef713a..28d30efee75 100644 --- a/erpnext/utilities/transaction_base.py +++ b/erpnext/utilities/transaction_base.py @@ -125,6 +125,15 @@ class TransactionBase(StatusUpdater): ret = None return ret + + def delink_advance_entries(self, jv): + total_allocated_amount = 0 + for adv in self.advances: + if adv.reference_name == jv: + frappe.db.sql("""delete from `tab{0} Advance` + where name = %s""".format(self.doctype), adv.name) + total_allocated_amount += flt(adv.allocated_amount, adv.precision("allocated_amount")) + self.db_set("total_advance", total_allocated_amount) def delete_events(ref_type, ref_name): frappe.delete_doc("Event", frappe.db.sql_list("""select name from `tabEvent`