diff --git a/frappe/custom/doctype/custom_field/custom_field.js b/frappe/custom/doctype/custom_field/custom_field.js index ec4eea4809..a4e08f5503 100644 --- a/frappe/custom/doctype/custom_field/custom_field.js +++ b/frappe/custom/doctype/custom_field/custom_field.js @@ -69,7 +69,7 @@ cur_frm.cscript.dt = function(doc, dt, dn) { } var insert_after = doc.insert_after || null; return frappe.call({ - method: 'frappe.core.doctype.custom_field.custom_field.get_fields_label', + method: 'frappe.custom.doctype.custom_field.custom_field.get_fields_label', args: { doctype: doc.dt, fieldname: doc.fieldname }, callback: function(r, rt) { set_field_options('insert_after', r.message); diff --git a/frappe/geo/__init__.py b/frappe/geo/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frappe/country_info.json b/frappe/geo/country_info.json similarity index 100% rename from frappe/country_info.json rename to frappe/geo/country_info.json diff --git a/frappe/country_info.py b/frappe/geo/country_info.py similarity index 100% rename from frappe/country_info.py rename to frappe/geo/country_info.py diff --git a/frappe/geo/doctype/__init__.py b/frappe/geo/doctype/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frappe/geo/doctype/country/README.md b/frappe/geo/doctype/country/README.md new file mode 100644 index 0000000000..0e3f46cddc --- /dev/null +++ b/frappe/geo/doctype/country/README.md @@ -0,0 +1 @@ +Country Master. \ No newline at end of file diff --git a/frappe/geo/doctype/country/__init__.py b/frappe/geo/doctype/country/__init__.py new file mode 100644 index 0000000000..baffc48825 --- /dev/null +++ b/frappe/geo/doctype/country/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/frappe/geo/doctype/country/country.json b/frappe/geo/doctype/country/country.json new file mode 100644 index 0000000000..1db0b816d5 --- /dev/null +++ b/frappe/geo/doctype/country/country.json @@ -0,0 +1,73 @@ +{ + "allow_import": 1, + "autoname": "field:country_name", + "creation": "2013-01-19 10:23:30", + "docstatus": 0, + "doctype": "DocType", + "document_type": "Master", + "fields": [ + { + "fieldname": "country_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Country Name", + "oldfieldname": "country_name", + "oldfieldtype": "Data", + "permlevel": 0, + "reqd": 1 + }, + { + "fieldname": "date_format", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Date Format", + "permlevel": 0 + }, + { + "fieldname": "time_zones", + "fieldtype": "Text", + "in_list_view": 1, + "label": "Time Zones", + "permlevel": 0 + }, + { + "fieldname": "code", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Code", + "permlevel": 0 + } + ], + "icon": "icon-globe", + "idx": 1, + "in_create": 0, + "modified": "2014-05-27 03:49:08.984711", + "modified_by": "Administrator", + "module": "Geo", + "name": "Country", + "owner": "Administrator", + "permissions": [ + { + "amend": 0, + "create": 1, + "email": 1, + "permlevel": 0, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "submit": 0, + "write": 1 + }, + { + "apply_user_permissions": 1, + "email": 1, + "permlevel": 0, + "print": 1, + "read": 1, + "report": 1, + "role": "All" + } + ], + "read_only": 0 +} diff --git a/frappe/geo/doctype/country/country.py b/frappe/geo/doctype/country/country.py new file mode 100644 index 0000000000..5e16f51f8f --- /dev/null +++ b/frappe/geo/doctype/country/country.py @@ -0,0 +1,10 @@ +# 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 + +from frappe.model.document import Document + +class Country(Document): + pass \ No newline at end of file diff --git a/frappe/geo/doctype/country/test_country.py b/frappe/geo/doctype/country/test_country.py new file mode 100644 index 0000000000..b2610667af --- /dev/null +++ b/frappe/geo/doctype/country/test_country.py @@ -0,0 +1,6 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + + +import frappe +test_records = frappe.get_test_records('Country') \ No newline at end of file diff --git a/frappe/geo/doctype/country/test_records.json b/frappe/geo/doctype/country/test_records.json new file mode 100644 index 0000000000..5a7c8a5568 --- /dev/null +++ b/frappe/geo/doctype/country/test_records.json @@ -0,0 +1,6 @@ +[ + { + "country_name": "_Test Country", + "doctype": "Country" + } +] \ No newline at end of file diff --git a/frappe/geo/doctype/currency/README.md b/frappe/geo/doctype/currency/README.md new file mode 100644 index 0000000000..3e1558e9d7 --- /dev/null +++ b/frappe/geo/doctype/currency/README.md @@ -0,0 +1 @@ +Currency Master with details about abbreviation, symbol etc. \ No newline at end of file diff --git a/frappe/geo/doctype/currency/__init__.py b/frappe/geo/doctype/currency/__init__.py new file mode 100644 index 0000000000..baffc48825 --- /dev/null +++ b/frappe/geo/doctype/currency/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/frappe/geo/doctype/currency/currency.js b/frappe/geo/doctype/currency/currency.js new file mode 100644 index 0000000000..79343e9ae6 --- /dev/null +++ b/frappe/geo/doctype/currency/currency.js @@ -0,0 +1,9 @@ +// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +// License: GNU General Public License v3. See license.txt + +cur_frm.cscript.refresh = function(doc) { + cur_frm.set_intro(""); + if(!cur_frm.doc.enabled) { + cur_frm.set_intro(__("This Currency is disabled. Enable to use in transactions")) + } +} \ No newline at end of file diff --git a/frappe/geo/doctype/currency/currency.json b/frappe/geo/doctype/currency/currency.json new file mode 100644 index 0000000000..9cf3fcb3ac --- /dev/null +++ b/frappe/geo/doctype/currency/currency.json @@ -0,0 +1,92 @@ +{ + "autoname": "field:currency_name", + "creation": "2013-01-28 10:06:02", + "description": "**Currency** Master", + "docstatus": 0, + "doctype": "DocType", + "fields": [ + { + "fieldname": "currency_name", + "fieldtype": "Data", + "label": "Currency Name", + "oldfieldname": "currency_name", + "oldfieldtype": "Data", + "permlevel": 0, + "reqd": 1 + }, + { + "fieldname": "enabled", + "fieldtype": "Check", + "in_list_view": 1, + "label": "Enabled", + "permlevel": 0 + }, + { + "description": "Sub-currency. For e.g. \"Cent\"", + "fieldname": "fraction", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Fraction", + "permlevel": 0 + }, + { + "description": "1 Currency = [?] Fraction\nFor e.g. 1 USD = 100 Cent", + "fieldname": "fraction_units", + "fieldtype": "Int", + "in_list_view": 1, + "label": "Fraction Units", + "permlevel": 0 + }, + { + "description": "A symbol for this currency. For e.g. $", + "fieldname": "symbol", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Symbol", + "permlevel": 0 + }, + { + "description": "How should this currency be formatted? If not set, will use system defaults", + "fieldname": "number_format", + "fieldtype": "Select", + "in_list_view": 1, + "label": "Number Format", + "options": "\n#,###.##\n#.###,##\n# ###.##\n# ###,##\n#'###.##\n#, ###.##\n#,##,###.##\n#,###.###\n#.###\n#,###", + "permlevel": 0 + } + ], + "icon": "icon-bitcoin", + "idx": 1, + "in_create": 0, + "modified": "2014-06-18 03:49:09.038452", + "modified_by": "Administrator", + "module": "Geo", + "name": "Currency", + "owner": "Administrator", + "permissions": [ + { + "amend": 0, + "create": 1, + "delete": 1, + "email": 1, + "permlevel": 0, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "submit": 0, + "write": 1 + }, + { + "apply_user_permissions": 1, + "delete": 0, + "email": 1, + "permlevel": 0, + "print": 1, + "read": 1, + "report": 1, + "role": "All" + } + ], + "read_only": 0 +} diff --git a/frappe/geo/doctype/currency/currency.py b/frappe/geo/doctype/currency/currency.py new file mode 100644 index 0000000000..abfbe1930c --- /dev/null +++ b/frappe/geo/doctype/currency/currency.py @@ -0,0 +1,21 @@ +# 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 +from frappe import throw, _ + +from frappe.model.document import Document + +class Currency(Document): + def validate(self): + frappe.clear_cache() + +def validate_conversion_rate(currency, conversion_rate, conversion_rate_label, company): + """common validation for currency and price list currency""" + + company_currency = frappe.db.get_value("Company", company, "default_currency") + + if not conversion_rate: + throw(_("{0} is mandatory. Maybe Currency Exchange record is not created for {1} to {2}.").format( + conversion_rate_label, currency, company_currency)) diff --git a/frappe/geo/doctype/currency/test_currency.py b/frappe/geo/doctype/currency/test_currency.py new file mode 100644 index 0000000000..f0c6cee260 --- /dev/null +++ b/frappe/geo/doctype/currency/test_currency.py @@ -0,0 +1,7 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +# pre loaded + +import frappe +test_records = frappe.get_test_records('Currency') \ No newline at end of file diff --git a/frappe/geo/doctype/currency/test_records.json b/frappe/geo/doctype/currency/test_records.json new file mode 100644 index 0000000000..0637a088a0 --- /dev/null +++ b/frappe/geo/doctype/currency/test_records.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/frappe/modules.txt b/frappe/modules.txt index 017ccc06a5..6cb0fe668a 100644 --- a/frappe/modules.txt +++ b/frappe/modules.txt @@ -2,4 +2,5 @@ Core Website Workflow Email -Custom \ No newline at end of file +Custom +Geo \ No newline at end of file diff --git a/frappe/utils/install.py b/frappe/utils/install.py index 7af476b156..ef04d527e8 100644 --- a/frappe/utils/install.py +++ b/frappe/utils/install.py @@ -42,6 +42,8 @@ def after_install(): except frappe.NameError: pass + import_country_and_currency() + # all roles to admin frappe.get_doc("User", "Administrator").add_roles(*frappe.db.sql_list("""select name from tabRole""")) @@ -49,6 +51,7 @@ def after_install(): from frappe.auth import _update_password _update_password("Administrator", frappe.conf.get("admin_password")) + frappe.db.commit() def before_tests(): @@ -56,3 +59,36 @@ def before_tests(): frappe.db.sql("delete from `tabEvent`") frappe.db.commit() frappe.clear_cache() + +def import_country_and_currency(): + from frappe.geo.country_info import get_all + data = get_all() + + for name in data: + country = frappe._dict(data[name]) + add_country_and_currency(name, country) + + # enable frequently used currencies + for currency in ("INR", "USD", "GBP", "EUR", "AED", "AUD", "JPY", "CNY", "CHF"): + frappe.db.set_value("Currency", currency, "enabled", 1) + +def add_country_and_currency(name, country): + if not frappe.db.exists("Country", name): + frappe.get_doc({ + "doctype": "Country", + "country_name": name, + "code": country.code, + "date_format": country.date_format or "dd-mm-yyyy", + "time_zones": "\n".join(country.timezones or []) + }).insert() + + if country.currency and not frappe.db.exists("Currency", country.currency): + frappe.get_doc({ + "doctype": "Currency", + "currency_name": country.currency, + "fraction": country.currency_fraction, + "symbol": country.currency_symbol, + "fraction_units": country.currency_fraction_units, + "number_format": country.number_format + }).insert() +