From ee8f88d6414efff4edc1d4a70017fa1f95561f45 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 27 Jan 2016 16:01:31 +0530 Subject: [PATCH] [patch] Set party account currency in existing orders --- erpnext/patches.txt | 1 + erpnext/patches/v6_20/__init__.py | 0 .../set_party_account_currency_in_orders.py | 24 +++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 erpnext/patches/v6_20/__init__.py create mode 100644 erpnext/patches/v6_20/set_party_account_currency_in_orders.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 7b079974d0..f0e12e0c85 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -245,3 +245,4 @@ erpnext.patches.v6_12.set_overdue_tasks erpnext.patches.v6_16.update_billing_status_in_dn_and_pr erpnext.patches.v6_16.create_manufacturer_records execute:frappe.db.sql("update `tabPricing Rule` set title=name where title='' or title is null") #2016-01-27 +erpnext.patches.v6_20.set_party_account_currency_in_orders \ No newline at end of file diff --git a/erpnext/patches/v6_20/__init__.py b/erpnext/patches/v6_20/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/patches/v6_20/set_party_account_currency_in_orders.py b/erpnext/patches/v6_20/set_party_account_currency_in_orders.py new file mode 100644 index 0000000000..ae7ad9592d --- /dev/null +++ b/erpnext/patches/v6_20/set_party_account_currency_in_orders.py @@ -0,0 +1,24 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + for doctype in ("Sales Order", "Purchase Order"): + frappe.reload_doctype(doctype) + + for order in frappe.db.sql("""select name, {0} as party from `tab{1}` + where advance_paid > 0 and docstatus=1""" + .format(("customer" if doctype=="Sales Order" else "supplier"), doctype), as_dict=1): + + party_account_currency = frappe.db.get_value("Journal Entry Account", { + "reference_type": doctype, + "reference_name": order.name, + "party": order.party, + "docstatus": 1, + "is_advance": "Yes" + }, "account_currency") + + frappe.db.set_value(doctype, order.name, "party_account_currency", party_account_currency) + \ No newline at end of file