2015-08-27 07:25:24 +00:00
|
|
|
# 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():
|
|
|
|
# Reload doctype
|
2015-09-17 11:58:39 +00:00
|
|
|
for dt in ("Account", "GL Entry", "Journal Entry",
|
2015-09-03 04:58:08 +00:00
|
|
|
"Journal Entry Account", "Sales Invoice", "Purchase Invoice", "Customer", "Supplier"):
|
2015-08-27 07:25:24 +00:00
|
|
|
frappe.reload_doctype(dt)
|
2015-09-17 11:58:39 +00:00
|
|
|
|
2015-09-17 11:32:48 +00:00
|
|
|
company_list = frappe.get_all("Company", fields=["name", "default_currency", "default_receivable_account"])
|
|
|
|
for company in company_list:
|
2015-09-17 11:58:39 +00:00
|
|
|
|
2015-08-27 07:25:24 +00:00
|
|
|
# update currency in account and gl entry as per company currency
|
2015-09-17 11:58:39 +00:00
|
|
|
frappe.db.sql("""update `tabAccount` set account_currency = %s
|
2015-08-28 13:56:28 +00:00
|
|
|
where ifnull(account_currency, '') = '' and company=%s""", (company.default_currency, company.name))
|
2015-09-17 11:58:39 +00:00
|
|
|
|
2015-08-27 07:25:24 +00:00
|
|
|
# update newly introduced field's value in sales / purchase invoice
|
|
|
|
frappe.db.sql("""
|
2015-09-17 11:58:39 +00:00
|
|
|
update
|
2015-08-27 07:25:24 +00:00
|
|
|
`tabSales Invoice`
|
2015-09-17 11:58:39 +00:00
|
|
|
set
|
2015-08-27 07:25:24 +00:00
|
|
|
base_paid_amount=paid_amount,
|
|
|
|
base_write_off_amount=write_off_amount,
|
|
|
|
party_account_currency=%s
|
|
|
|
where company=%s
|
|
|
|
""", (company.default_currency, company.name))
|
2015-09-17 11:58:39 +00:00
|
|
|
|
2015-08-27 07:25:24 +00:00
|
|
|
frappe.db.sql("""
|
2015-09-17 11:58:39 +00:00
|
|
|
update
|
2015-08-27 07:25:24 +00:00
|
|
|
`tabPurchase Invoice`
|
2015-09-17 11:58:39 +00:00
|
|
|
set
|
2015-08-27 07:25:24 +00:00
|
|
|
base_write_off_amount=write_off_amount,
|
|
|
|
party_account_currency=%s
|
|
|
|
where company=%s
|
|
|
|
""", (company.default_currency, company.name))
|
2015-09-17 11:58:39 +00:00
|
|
|
|
2015-08-27 07:25:24 +00:00
|
|
|
# update exchange rate, debit/credit in account currency in Journal Entry
|
|
|
|
frappe.db.sql("""
|
2015-09-09 13:13:12 +00:00
|
|
|
update `tabJournal Entry Account` jea
|
2015-09-17 11:58:39 +00:00
|
|
|
set exchange_rate=1,
|
2015-08-27 07:25:24 +00:00
|
|
|
debit_in_account_currency=debit,
|
|
|
|
credit_in_account_currency=credit,
|
2015-09-09 13:13:12 +00:00
|
|
|
account_type=(select account_type from `tabAccount` where name=jea.account)
|
|
|
|
""")
|
2015-09-17 11:58:39 +00:00
|
|
|
|
2015-09-09 13:13:12 +00:00
|
|
|
frappe.db.sql("""
|
|
|
|
update `tabJournal Entry Account` jea, `tabJournal Entry` je
|
|
|
|
set account_currency=%s
|
|
|
|
where jea.parent = je.name and je.company=%s
|
2015-08-27 07:25:24 +00:00
|
|
|
""", (company.default_currency, company.name))
|
2015-09-17 11:58:39 +00:00
|
|
|
|
2015-08-27 07:25:24 +00:00
|
|
|
# update debit/credit in account currency in GL Entry
|
|
|
|
frappe.db.sql("""
|
|
|
|
update
|
|
|
|
`tabGL Entry`
|
2015-09-17 11:58:39 +00:00
|
|
|
set
|
2015-08-27 07:25:24 +00:00
|
|
|
debit_in_account_currency=debit,
|
|
|
|
credit_in_account_currency=credit,
|
2015-08-28 13:56:28 +00:00
|
|
|
account_currency=%s
|
2015-08-27 07:25:24 +00:00
|
|
|
where
|
|
|
|
company=%s
|
|
|
|
""", (company.default_currency, company.name))
|