[refactor] added geo
This commit is contained in:
parent
7dd7944590
commit
470462cda6
20 changed files with 268 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
0
frappe/geo/__init__.py
Normal file
0
frappe/geo/__init__.py
Normal file
0
frappe/geo/doctype/__init__.py
Normal file
0
frappe/geo/doctype/__init__.py
Normal file
1
frappe/geo/doctype/country/README.md
Normal file
1
frappe/geo/doctype/country/README.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
Country Master.
|
||||
1
frappe/geo/doctype/country/__init__.py
Normal file
1
frappe/geo/doctype/country/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from __future__ import unicode_literals
|
||||
73
frappe/geo/doctype/country/country.json
Normal file
73
frappe/geo/doctype/country/country.json
Normal file
|
|
@ -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
|
||||
}
|
||||
10
frappe/geo/doctype/country/country.py
Normal file
10
frappe/geo/doctype/country/country.py
Normal file
|
|
@ -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
|
||||
6
frappe/geo/doctype/country/test_country.py
Normal file
6
frappe/geo/doctype/country/test_country.py
Normal file
|
|
@ -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')
|
||||
6
frappe/geo/doctype/country/test_records.json
Normal file
6
frappe/geo/doctype/country/test_records.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[
|
||||
{
|
||||
"country_name": "_Test Country",
|
||||
"doctype": "Country"
|
||||
}
|
||||
]
|
||||
1
frappe/geo/doctype/currency/README.md
Normal file
1
frappe/geo/doctype/currency/README.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
Currency Master with details about abbreviation, symbol etc.
|
||||
1
frappe/geo/doctype/currency/__init__.py
Normal file
1
frappe/geo/doctype/currency/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from __future__ import unicode_literals
|
||||
9
frappe/geo/doctype/currency/currency.js
Normal file
9
frappe/geo/doctype/currency/currency.js
Normal file
|
|
@ -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"))
|
||||
}
|
||||
}
|
||||
92
frappe/geo/doctype/currency/currency.json
Normal file
92
frappe/geo/doctype/currency/currency.json
Normal file
|
|
@ -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
|
||||
}
|
||||
21
frappe/geo/doctype/currency/currency.py
Normal file
21
frappe/geo/doctype/currency/currency.py
Normal file
|
|
@ -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))
|
||||
7
frappe/geo/doctype/currency/test_currency.py
Normal file
7
frappe/geo/doctype/currency/test_currency.py
Normal file
|
|
@ -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')
|
||||
1
frappe/geo/doctype/currency/test_records.json
Normal file
1
frappe/geo/doctype/currency/test_records.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
[]
|
||||
|
|
@ -3,3 +3,4 @@ Website
|
|||
Workflow
|
||||
Email
|
||||
Custom
|
||||
Geo
|
||||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue