From 19b06b074532bbdc7481cf346b43aeb533bac740 Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Sun, 26 Sep 2021 16:58:55 +0530 Subject: [PATCH] patch: invalid gain loss gl entry (cherry picked from commit beebfb323ac50c72df20b6c447087fec84b9c80d) --- erpnext/patches.txt | 1 + .../modify_invalid_gain_loss_gl_entries.py | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 erpnext/patches/v13_0/modify_invalid_gain_loss_gl_entries.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 46a30f37f72..c83f39708b5 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -315,3 +315,4 @@ erpnext.patches.v13_0.make_homepage_products_website_items erpnext.patches.v13_0.update_dates_in_tax_withholding_category erpnext.patches.v13_0.replace_supplier_item_group_with_party_specific_item erpnext.patches.v13_0.create_accounting_dimensions_in_pos_doctypes +erpnext.patches.v13_0.modify_invalid_gain_loss_gl_entries \ No newline at end of file diff --git a/erpnext/patches/v13_0/modify_invalid_gain_loss_gl_entries.py b/erpnext/patches/v13_0/modify_invalid_gain_loss_gl_entries.py new file mode 100644 index 00000000000..4781ccb4b2e --- /dev/null +++ b/erpnext/patches/v13_0/modify_invalid_gain_loss_gl_entries.py @@ -0,0 +1,40 @@ +from __future__ import unicode_literals + +import frappe + + +def execute(): + purchase_invoices = frappe.db.sql(""" + select + parenttype as type, parent as name + from + `tabPurchase Invoice Advance` + where + ref_exchange_rate = 1 + and docstatus = 1 + and ifnull(exchange_gain_loss, '') != '' + group by + parent + """, as_dict=1) + + sales_invoices = frappe.db.sql(""" + select + parenttype as type, parent as name + from + `tabSales Invoice Advance` + where + ref_exchange_rate = 1 + and docstatus = 1 + and ifnull(exchange_gain_loss, '') != '' + group by + parent + """, as_dict=1) + + for invoice in purchase_invoices + sales_invoices: + doc = frappe.get_doc(invoice.type, invoice.name) + doc.docstatus = 2 + doc.make_gl_entries() + for advance in doc.advances: + advance.db_set('exchange_gain_loss', 0, False) + doc.docstatus = 1 + doc.make_gl_entries() \ No newline at end of file