[patch] Multi currency
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index ebdd729..f122deb 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -263,7 +263,7 @@
self.difference = flt(self.total_debit, self.precision("total_debit")) - \
flt(self.total_credit, self.precision("total_credit"))
-
+ print self.difference
if self.difference:
frappe.throw(_("Total Debit must be equal to Total Credit. The difference is {0}")
.format(self.difference))
diff --git a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
index 253c267..718d96a 100644
--- a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
+++ b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
@@ -270,14 +270,14 @@
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 1,
- "label": "Debit",
+ "label": "Debit in Company Currency",
"no_copy": 0,
"oldfieldname": "debit",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 0,
- "read_only": 0,
+ "read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
@@ -331,14 +331,14 @@
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 1,
- "label": "Credit",
+ "label": "Credit in Company Currency",
"no_copy": 0,
"oldfieldname": "credit",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 0,
- "read_only": 0,
+ "read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
@@ -476,7 +476,7 @@
"is_submittable": 0,
"issingle": 0,
"istable": 1,
- "modified": "2015-08-18 17:23:28.378231",
+ "modified": "2015-08-27 12:52:20.914258",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Journal Entry Account",
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 21656c6..cadd6af 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -193,3 +193,4 @@
erpnext.patches.v5_7.item_template_attributes
erpnext.patches.v4_2.repost_reserved_qty #2015-08-20
erpnext.patches.v5_4.update_purchase_cost_against_project
+erpnext.patches.v6_0.multi_currency
\ No newline at end of file
diff --git a/erpnext/patches/v5_7/multi_currency.py b/erpnext/patches/v5_7/multi_currency.py
deleted file mode 100644
index 52e4d04..0000000
--- a/erpnext/patches/v5_7/multi_currency.py
+++ /dev/null
@@ -1,10 +0,0 @@
-# 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():
- frappe.db.sql("""update `tabAccount` acc
- set currency = (select default_currency from tabCompany where name=acc.company)
- where ifnull(currency, '') = ''""")
\ No newline at end of file
diff --git a/erpnext/patches/v6_0/__init__.py b/erpnext/patches/v6_0/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/patches/v6_0/__init__.py
diff --git a/erpnext/patches/v6_0/multi_currency.py b/erpnext/patches/v6_0/multi_currency.py
new file mode 100644
index 0000000..21c851b
--- /dev/null
+++ b/erpnext/patches/v6_0/multi_currency.py
@@ -0,0 +1,85 @@
+# 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
+ for dt in ("Account", "GL Entry", "Journal Entry",
+ "Journal Entry Account", "Sales Invoice", "Purchase Invoice"):
+ frappe.reload_doctype(dt)
+
+ for company in frappe.get_all("Company", fields=["name", "default_currency", "default_receivable_account"]):
+
+ # update currency in account and gl entry as per company currency
+ frappe.db.sql("""update `tabAccount` set currency = %s
+ where ifnull(currency, '') = '' and company=%s""", (company.default_currency, company.name))
+
+ # update newly introduced field's value in sales / purchase invoice
+ frappe.db.sql("""
+ update
+ `tabSales Invoice`
+ set
+ base_paid_amount=paid_amount,
+ base_write_off_amount=write_off_amount,
+ party_account_currency=%s
+ where company=%s
+ """, (company.default_currency, company.name))
+
+ frappe.db.sql("""
+ update
+ `tabPurchase Invoice`
+ set
+ base_write_off_amount=write_off_amount,
+ party_account_currency=%s
+ where company=%s
+ """, (company.default_currency, company.name))
+
+ # update exchange rate, debit/credit in account currency in Journal Entry
+ frappe.db.sql("""update `tabJournal Entry` set exchange_rate=1""")
+
+ frappe.db.sql("""
+ update
+ `tabJournal Entry Account` jea, `tabJournal Entry` je
+ set
+ debit_in_account_currency=debit,
+ credit_in_account_currency=credit,
+ currency=%s
+ where
+ jea.parent = je.name
+ and je.company=%s
+ """, (company.default_currency, company.name))
+
+ # update debit/credit in account currency in GL Entry
+ frappe.db.sql("""
+ update
+ `tabGL Entry`
+ set
+ debit_in_account_currency=debit,
+ credit_in_account_currency=credit,
+ currency=%s
+ where
+ company=%s
+ """, (company.default_currency, company.name))
+
+ # Set party account if default currency of party other than company's default currency
+ for dt in ("Customer", "Supplier"):
+ parties = frappe.db.sql("""select name from `tab{0}` p
+ where ifnull(default_currency, '') != '' and default_currency != %s
+ and not exists(select name from `tabParty Account` where parent=p.name and company=%s)"""
+ .format(dt), (company.default_currency, company.name))
+
+ for p in parties:
+ party = frappe.get_doc(dt, p[0])
+ party_gle = frappe.db.get_value("GL Entry", {"party_type": dt, "party": p[0],
+ "company": company.name}, ["account"], as_dict=True)
+
+ party_account = party_gle.account or company.default_receivable_account
+
+ party.append("party_accounts", {
+ "company": company.name,
+ "account": party_account
+ })
+ party.ignore_mandatory()
+ party.save()
\ No newline at end of file