Merge pull request #5822 from nabinhait/fix_106
Unlink payment entries on cancellation of Invoice
This commit is contained in:
commit
2b12a74fef
@ -61,8 +61,8 @@ class JournalEntry(AccountsController):
|
|||||||
frappe.get_doc(voucher_type, voucher_no).set_total_advance_paid()
|
frappe.get_doc(voucher_type, voucher_no).set_total_advance_paid()
|
||||||
|
|
||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
from erpnext.accounts.utils import remove_against_link_from_jv
|
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
|
||||||
remove_against_link_from_jv(self.doctype, self.name)
|
unlink_ref_doc_from_payment_entries(self.doctype, self.name)
|
||||||
|
|
||||||
self.make_gl_entries(1)
|
self.make_gl_entries(1)
|
||||||
self.update_advance_paid()
|
self.update_advance_paid()
|
||||||
|
@ -553,8 +553,8 @@ class PurchaseInvoice(BuyingController):
|
|||||||
self.update_status_updater_args()
|
self.update_status_updater_args()
|
||||||
|
|
||||||
if not self.is_return:
|
if not self.is_return:
|
||||||
from erpnext.accounts.utils import remove_against_link_from_jv
|
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
|
||||||
remove_against_link_from_jv(self.doctype, self.name)
|
unlink_ref_doc_from_payment_entries(self.doctype, self.name)
|
||||||
|
|
||||||
self.update_prevdoc_status()
|
self.update_prevdoc_status()
|
||||||
self.update_billing_status_for_zero_amount_refdoc("Purchase Order")
|
self.update_billing_status_for_zero_amount_refdoc("Purchase Order")
|
||||||
|
@ -134,8 +134,8 @@ class SalesInvoice(SellingController):
|
|||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
self.check_close_sales_order("sales_order")
|
self.check_close_sales_order("sales_order")
|
||||||
|
|
||||||
from erpnext.accounts.utils import remove_against_link_from_jv
|
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
|
||||||
remove_against_link_from_jv(self.doctype, self.name)
|
unlink_ref_doc_from_payment_entries(self.doctype, self.name)
|
||||||
|
|
||||||
if self.is_return:
|
if self.is_return:
|
||||||
# NOTE status updating bypassed for is_return
|
# NOTE status updating bypassed for is_return
|
||||||
|
@ -324,7 +324,18 @@ def update_reference_in_payment_entry(d, payment_entry):
|
|||||||
payment_entry.set_amounts()
|
payment_entry.set_amounts()
|
||||||
payment_entry.save(ignore_permissions=True)
|
payment_entry.save(ignore_permissions=True)
|
||||||
|
|
||||||
def remove_against_link_from_jv(ref_type, ref_no):
|
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)
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
def remove_ref_doc_link_from_jv(ref_type, ref_no):
|
||||||
linked_jv = frappe.db.sql_list("""select parent from `tabJournal Entry Account`
|
linked_jv = frappe.db.sql_list("""select parent from `tabJournal Entry Account`
|
||||||
where reference_type=%s and reference_name=%s and docstatus < 2""", (ref_type, ref_no))
|
where reference_type=%s and reference_name=%s and docstatus < 2""", (ref_type, ref_no))
|
||||||
|
|
||||||
@ -335,15 +346,30 @@ def remove_against_link_from_jv(ref_type, ref_no):
|
|||||||
where reference_type=%s and reference_name=%s
|
where reference_type=%s and reference_name=%s
|
||||||
and docstatus < 2""", (now(), frappe.session.user, ref_type, ref_no))
|
and docstatus < 2""", (now(), frappe.session.user, ref_type, ref_no))
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
||||||
frappe.msgprint(_("Journal Entries {0} are un-linked".format("\n".join(linked_jv))))
|
frappe.msgprint(_("Journal Entries {0} are un-linked".format("\n".join(linked_jv))))
|
||||||
|
|
||||||
|
def remove_ref_doc_link_from_pe(ref_type, ref_no):
|
||||||
|
linked_pe = frappe.db.sql_list("""select parent from `tabPayment Entry Reference`
|
||||||
|
where reference_doctype=%s and reference_name=%s and docstatus < 2""", (ref_type, ref_no))
|
||||||
|
|
||||||
|
if linked_pe:
|
||||||
|
frappe.db.sql("""update `tabPayment Entry Reference`
|
||||||
|
set allocated_amount=0, modified=%s, modified_by=%s
|
||||||
|
where reference_doctype=%s and reference_name=%s
|
||||||
|
and docstatus < 2""", (now(), frappe.session.user, ref_type, ref_no))
|
||||||
|
|
||||||
|
for pe in linked_pe:
|
||||||
|
pe_doc = frappe.get_doc("Payment Entry", pe)
|
||||||
|
pe_doc.set_total_allocated_amount()
|
||||||
|
pe_doc.set_unallocated_amount()
|
||||||
|
pe_doc.clear_unallocated_reference_document_rows()
|
||||||
|
|
||||||
|
frappe.db.sql("""update `tabPayment Entry` set total_allocated_amount=%s,
|
||||||
|
base_total_allocated_amount=%s, unallocated_amount=%s, modified=%s, modified_by=%s
|
||||||
|
where name=%s""", (pe_doc.total_allocated_amount, pe_doc.base_total_allocated_amount,
|
||||||
|
pe_doc.unallocated_amount, now(), frappe.session.user, pe))
|
||||||
|
|
||||||
|
frappe.msgprint(_("Payment Entries {0} are un-linked".format("\n".join(linked_pe))))
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_company_default(company, fieldname):
|
def get_company_default(company, fieldname):
|
||||||
|
@ -3,11 +3,13 @@
|
|||||||
"allow_import": 1,
|
"allow_import": 1,
|
||||||
"allow_rename": 0,
|
"allow_rename": 0,
|
||||||
"autoname": "naming_series:",
|
"autoname": "naming_series:",
|
||||||
|
"beta": 0,
|
||||||
"creation": "2013-06-18 12:39:59",
|
"creation": "2013-06-18 12:39:59",
|
||||||
"custom": 0,
|
"custom": 0,
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
"document_type": "Document",
|
"document_type": "Document",
|
||||||
|
"editable_grid": 1,
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
@ -712,6 +714,34 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"fieldname": "currency",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"ignore_xss_filter": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"label": "Currency",
|
||||||
|
"length": 0,
|
||||||
|
"no_copy": 0,
|
||||||
|
"oldfieldname": "currency",
|
||||||
|
"oldfieldtype": "Select",
|
||||||
|
"options": "Currency",
|
||||||
|
"permlevel": 0,
|
||||||
|
"print_hide": 1,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 1,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0,
|
||||||
|
"width": "100px"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
@ -741,34 +771,6 @@
|
|||||||
"unique": 0,
|
"unique": 0,
|
||||||
"width": "100px"
|
"width": "100px"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"fieldname": "currency",
|
|
||||||
"fieldtype": "Link",
|
|
||||||
"hidden": 0,
|
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"ignore_xss_filter": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"label": "Currency",
|
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"oldfieldname": "currency",
|
|
||||||
"oldfieldtype": "Select",
|
|
||||||
"options": "Currency",
|
|
||||||
"permlevel": 0,
|
|
||||||
"print_hide": 1,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 1,
|
|
||||||
"search_index": 0,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"unique": 0,
|
|
||||||
"width": "100px"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
@ -2989,13 +2991,14 @@
|
|||||||
"hide_toolbar": 0,
|
"hide_toolbar": 0,
|
||||||
"icon": "icon-file-text",
|
"icon": "icon-file-text",
|
||||||
"idx": 105,
|
"idx": 105,
|
||||||
|
"image_view": 0,
|
||||||
"in_create": 0,
|
"in_create": 0,
|
||||||
"in_dialog": 0,
|
"in_dialog": 0,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
"modified": "2016-04-14 12:34:16.220066",
|
"modified": "2016-07-21 17:24:25.306923",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Selling",
|
"module": "Selling",
|
||||||
"name": "Sales Order",
|
"name": "Sales Order",
|
||||||
@ -3122,6 +3125,7 @@
|
|||||||
"write": 1
|
"write": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"quick_entry": 0,
|
||||||
"read_only": 0,
|
"read_only": 0,
|
||||||
"read_only_onload": 1,
|
"read_only_onload": 1,
|
||||||
"search_fields": "status,transaction_date,customer,customer_name, territory,order_type,company",
|
"search_fields": "status,transaction_date,customer,customer_name, territory,order_type,company",
|
||||||
|
Loading…
Reference in New Issue
Block a user