blob: ba1dfb70f99eba4f1b380f31460876f5859ba4e0 [file] [log] [blame]
Rushabh Mehtaad45e312013-11-20 12:59:58 +05301# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302# License: GNU General Public License v3. See license.txt
3
Rushabh Mehta6f9915c2013-01-16 17:48:17 +05304from __future__ import unicode_literals
5
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05306import frappe
Rushabh Mehta6f9915c2013-01-16 17:48:17 +05307
Rushabh Mehta370a0242014-04-18 16:00:41 +05308from frappe import _
9
Rushabh Mehta1f847992013-12-12 19:12:19 +053010def after_install():
Rushabh Mehta40b2b032014-04-21 13:43:11 +053011 frappe.get_doc({'doctype': "Role", "role_name": "Analytics"}).insert()
Rushabh Mehta33003c62014-04-30 11:16:02 +053012 set_single_defaults()
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053013 import_country_and_currency()
Nabin Hait813a93d2014-03-06 18:21:56 +053014 from erpnext.accounts.doctype.chart_of_accounts.import_charts import import_charts
15 import_charts()
Rushabh Mehta558a9aa2014-04-04 12:00:36 +053016 frappe.db.set_default('desktop:home_page', 'setup-wizard')
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053017 feature_setup()
Rushabh Mehta1f847992013-12-12 19:12:19 +053018 from erpnext.setup.page.setup_wizard.setup_wizard import add_all_roles_to
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053019 add_all_roles_to("Administrator")
Anand Doshie9baaa62014-02-26 12:35:33 +053020 frappe.db.commit()
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053021
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053022def import_country_and_currency():
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053023 from frappe.country_info import get_all
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053024 data = get_all()
Anand Doshi13ae5482014-04-10 18:40:57 +053025
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053026 for name in data:
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053027 country = frappe._dict(data[name])
Anand Doshi7fbdba02014-03-25 13:50:52 +053028 if not frappe.db.exists("Country", name):
Rushabh Mehtab385ecf2014-03-28 16:44:37 +053029 frappe.get_doc({
Anand Doshi7fbdba02014-03-25 13:50:52 +053030 "doctype": "Country",
31 "country_name": name,
32 "code": country.code,
33 "date_format": country.date_format or "dd-mm-yyyy",
34 "time_zones": "\n".join(country.timezones or [])
35 }).insert()
Anand Doshi13ae5482014-04-10 18:40:57 +053036
Anand Doshie9baaa62014-02-26 12:35:33 +053037 if country.currency and not frappe.db.exists("Currency", country.currency):
Rushabh Mehtab385ecf2014-03-28 16:44:37 +053038 frappe.get_doc({
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053039 "doctype": "Currency",
40 "currency_name": country.currency,
41 "fraction": country.currency_fraction,
42 "symbol": country.currency_symbol,
Rushabh Mehtaf5b04cf2013-01-21 10:14:10 +053043 "fraction_units": country.currency_fraction_units,
44 "number_format": country.number_format
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053045 }).insert()
46
Anand Doshide560aa2014-05-06 12:02:23 +053047 # enable frequently used currencies
48 for currency in ("INR", "USD", "GBP", "EUR", "AED", "AUD", "JPY", "CNY", "CHF"):
49 frappe.db.set_value("Currency", currency, "enabled", 1)
50
Rushabh Mehta1f847992013-12-12 19:12:19 +053051def feature_setup():
52 """save global defaults and features setup"""
Rushabh Mehtaf191f852014-04-02 18:09:34 +053053 doc = frappe.get_doc("Features Setup", "Features Setup")
54 doc.ignore_permissions = True
Rushabh Mehta1f847992013-12-12 19:12:19 +053055
56 # store value as 1 for all these fields
57 flds = ['fs_item_serial_nos', 'fs_item_batch_nos', 'fs_brands', 'fs_item_barcode',
58 'fs_item_advanced', 'fs_packing_details', 'fs_item_group_in_details',
59 'fs_exports', 'fs_imports', 'fs_discounts', 'fs_purchase_discounts',
60 'fs_after_sales_installations', 'fs_projects', 'fs_sales_extras',
61 'fs_recurring_invoice', 'fs_pos', 'fs_manufacturing', 'fs_quality',
62 'fs_page_break', 'fs_more_info', 'fs_pos_view'
63 ]
Rushabh Mehtad21f55b2014-04-29 16:24:37 +053064 for f in flds:
65 doc.set(f, 1)
Rushabh Mehtaf191f852014-04-02 18:09:34 +053066 doc.save()
Pratik Vyas28da7522014-02-19 20:53:45 +053067
68def set_single_defaults():
Nabin Haite7885e32014-04-04 13:26:50 +053069 for dt in frappe.db.sql_list("""select name from `tabDocType` where issingle=1"""):
Anand Doshieb7fea62014-03-19 17:10:01 +053070 default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField`
Rushabh Mehtaf14b8092014-04-03 14:30:42 +053071 where parent=%s""", dt)
Anand Doshieb7fea62014-03-19 17:10:01 +053072 if default_values:
73 try:
Rushabh Mehtab385ecf2014-03-28 16:44:37 +053074 b = frappe.get_doc(dt, dt)
Anand Doshieb7fea62014-03-19 17:10:01 +053075 for fieldname, value in default_values:
Anand Doshif78d1ae2014-03-28 13:55:00 +053076 b.set(fieldname, value)
Anand Doshieb7fea62014-03-19 17:10:01 +053077 b.save()
78 except frappe.MandatoryError:
79 pass
80
Anand Doshie9baaa62014-02-26 12:35:33 +053081 frappe.db.set_default("date_format", "dd-mm-yyyy")