Merged language patch with global_defaults_to_system_settings patch
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 5315f79..3fc2b11 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -4,6 +4,7 @@
erpnext.patches.v4_0.update_user_properties
erpnext.patches.v4_0.move_warehouse_user_to_restrictions
erpnext.patches.v4_0.new_permissions
+erpnext.patches.v4_0.global_defaults_to_system_settings
erpnext.patches.v4_0.update_incharge_name_to_sales_person_in_maintenance_schedule
execute:frappe.reload_doc('accounts', 'doctype', 'sales_invoice') # 2014-01-29
execute:frappe.reload_doc('selling', 'doctype', 'sales_order') # 2014-01-29
@@ -42,4 +43,4 @@
execute:frappe.db.sql("delete from `tabWebsite Item Group` where ifnull(item_group, '')=''")
execute:frappe.delete_doc("Print Format", "SalesInvoice")
execute:import frappe.defaults;frappe.defaults.clear_default("price_list_currency")
-erpnext.patches.v4_0.global_defaults_to_system_settings
+
diff --git a/erpnext/patches/v4_0/global_defaults_to_system_settings.py b/erpnext/patches/v4_0/global_defaults_to_system_settings.py
index 5a3c41c..ab4f241 100644
--- a/erpnext/patches/v4_0/global_defaults_to_system_settings.py
+++ b/erpnext/patches/v4_0/global_defaults_to_system_settings.py
@@ -4,14 +4,30 @@
from __future__ import unicode_literals
import frappe
+from collections import Counter
+from frappe.core.doctype.user.user import STANDARD_USERS
def execute():
+ system_settings = frappe.get_doc("System Settings")
+
+ # set values from global_defauls
global_defauls = frappe.db.get_value("Global Defaults", None,
["time_zone", "date_format", "number_format", "float_precision", "session_expiry"])
if global_defauls:
- system_settings = frappe.get_doc("System Settings")
for key, val in global_defauls.items():
- system_settings[key] = val
- system_settings.ignore_mandatory = True
- system_settings.save()
+ if not system_settings.get(key):
+ system_settings[key] = val
+
+ # language
+ if not system_settings.get("language"):
+ # find most common language
+ lang = frappe.db.sql_list("""select language from `tabUser`
+ where ifnull(language, '')!='' and language not like "Loading%%" and name not in ({standard_users})""".format(
+ standard_users=", ".join(["%s"]*len(STANDARD_USERS))), tuple(STANDARD_USERS))
+ lang = Counter(lang).most_common(1)
+ lang = (len(lang) > 0) and lang[0][0] or "english"
+
+ system_settings.language = lang
+
+ system_settings.save()