[patch] Set party account currency in existing orders

This commit is contained in:
Nabin Hait 2016-01-27 16:01:31 +05:30
parent b2206d1155
commit ee8f88d641
3 changed files with 25 additions and 0 deletions

View File

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

View File

View File

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