Unlink payment entries on cancellation of invoice

This commit is contained in:
Nabin Hait 2016-11-23 15:58:51 +05:30
parent b8a7926464
commit 297d74a997
6 changed files with 28 additions and 21 deletions

View File

@ -63,7 +63,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()

View File

@ -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")

View File

@ -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

View File

@ -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`

View File

@ -560,6 +560,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)
@frappe.whitelist()
def get_tax_rate(account_head):

View File

@ -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`