From 31f6436f75b191c0d30bcb37d7828847a84359b9 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 8 Nov 2016 17:25:14 +0530 Subject: [PATCH] [patch] Set base amount in Sales Invoice Payment table --- erpnext/patches.txt | 3 ++- ...et_base_amount_in_invoice_payment_table.py | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 erpnext/patches/v7_0/set_base_amount_in_invoice_payment_table.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index c7b61d482b..b53bbc64eb 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -344,4 +344,5 @@ execute:frappe.reload_doc('accounts', 'doctype', 'accounts_settings') execute:frappe.db.set_value("Accounts Settings", "Accounts Settings", "unlink_payment_on_cancellation_of_invoice", 0) execute:frappe.db.sql("update `tabStock Entry` set total_amount = null where purpose in('Repack', 'Manufacture')") erpnext.patches.v7_0.repost_gle_for_pi_with_update_stock #2016-11-01 -erpnext.patches.v7_1.add_account_user_role_for_timesheet \ No newline at end of file +erpnext.patches.v7_1.add_account_user_role_for_timesheet +erpnext.patches.v7_0.set_base_amount_in_invoice_payment_table diff --git a/erpnext/patches/v7_0/set_base_amount_in_invoice_payment_table.py b/erpnext/patches/v7_0/set_base_amount_in_invoice_payment_table.py new file mode 100644 index 0000000000..89ce43bfa3 --- /dev/null +++ b/erpnext/patches/v7_0/set_base_amount_in_invoice_payment_table.py @@ -0,0 +1,23 @@ +from __future__ import unicode_literals +import frappe +from frappe.utils import flt + +def execute(): + si_list = frappe.db.sql(""" + select distinct parent + from `tabSales Invoice Payment` + where docstatus!=2 and amount != 0 and base_amount = 0 + """) + + count = 0 + for d in si_list: + si = frappe.get_doc("Sales Invoice", d[0]) + for p in si.get("payments"): + if p.amount and not p.base_amount: + base_amount = flt(p.amount*si.conversion_rate, si.precision("base_paid_amount")) + frappe.db.set_value("Sales Invoice Payment", p.name, "base_amount", base_amount, update_modified=False) + + count +=1 + + if count % 200 == 0: + frappe.db.commit() \ No newline at end of file