blob: 344a89e7735d0478d1b9009706d1bcdf32efa648 [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
Anand Doshi56198f42014-06-26 12:47:45 +053010default_mail_footer = """<div style="padding: 7px; text-align: right; color: #888"><small>Sent via
Anand Doshi7f41ff22014-06-26 12:02:55 +053011 <a style="color: #888" href="http://erpnext.org">ERPNext</a></div>"""
12
Rushabh Mehta1f847992013-12-12 19:12:19 +053013def after_install():
Rushabh Mehta40b2b032014-04-21 13:43:11 +053014 frappe.get_doc({'doctype': "Role", "role_name": "Analytics"}).insert()
Rushabh Mehta33003c62014-04-30 11:16:02 +053015 set_single_defaults()
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053016 import_country_and_currency()
Nabin Hait813a93d2014-03-06 18:21:56 +053017 from erpnext.accounts.doctype.chart_of_accounts.import_charts import import_charts
18 import_charts()
Rushabh Mehta558a9aa2014-04-04 12:00:36 +053019 frappe.db.set_default('desktop:home_page', 'setup-wizard')
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053020 feature_setup()
Rushabh Mehta1f847992013-12-12 19:12:19 +053021 from erpnext.setup.page.setup_wizard.setup_wizard import add_all_roles_to
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053022 add_all_roles_to("Administrator")
Anand Doshie9baaa62014-02-26 12:35:33 +053023 frappe.db.commit()
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053024
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053025def import_country_and_currency():
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053026 from frappe.country_info import get_all
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053027 data = get_all()
Anand Doshi13ae5482014-04-10 18:40:57 +053028
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053029 for name in data:
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053030 country = frappe._dict(data[name])
Anand Doshi7fbdba02014-03-25 13:50:52 +053031 if not frappe.db.exists("Country", name):
Rushabh Mehtab385ecf2014-03-28 16:44:37 +053032 frappe.get_doc({
Anand Doshi7fbdba02014-03-25 13:50:52 +053033 "doctype": "Country",
34 "country_name": name,
35 "code": country.code,
36 "date_format": country.date_format or "dd-mm-yyyy",
37 "time_zones": "\n".join(country.timezones or [])
38 }).insert()
Anand Doshi13ae5482014-04-10 18:40:57 +053039
Anand Doshie9baaa62014-02-26 12:35:33 +053040 if country.currency and not frappe.db.exists("Currency", country.currency):
Rushabh Mehtab385ecf2014-03-28 16:44:37 +053041 frappe.get_doc({
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053042 "doctype": "Currency",
43 "currency_name": country.currency,
44 "fraction": country.currency_fraction,
45 "symbol": country.currency_symbol,
Rushabh Mehtaf5b04cf2013-01-21 10:14:10 +053046 "fraction_units": country.currency_fraction_units,
47 "number_format": country.number_format
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053048 }).insert()
49
Anand Doshide560aa2014-05-06 12:02:23 +053050 # enable frequently used currencies
51 for currency in ("INR", "USD", "GBP", "EUR", "AED", "AUD", "JPY", "CNY", "CHF"):
52 frappe.db.set_value("Currency", currency, "enabled", 1)
53
Rushabh Mehta1f847992013-12-12 19:12:19 +053054def feature_setup():
55 """save global defaults and features setup"""
Rushabh Mehtaf191f852014-04-02 18:09:34 +053056 doc = frappe.get_doc("Features Setup", "Features Setup")
57 doc.ignore_permissions = True
Rushabh Mehta1f847992013-12-12 19:12:19 +053058
59 # store value as 1 for all these fields
60 flds = ['fs_item_serial_nos', 'fs_item_batch_nos', 'fs_brands', 'fs_item_barcode',
61 'fs_item_advanced', 'fs_packing_details', 'fs_item_group_in_details',
62 'fs_exports', 'fs_imports', 'fs_discounts', 'fs_purchase_discounts',
63 'fs_after_sales_installations', 'fs_projects', 'fs_sales_extras',
64 'fs_recurring_invoice', 'fs_pos', 'fs_manufacturing', 'fs_quality',
65 'fs_page_break', 'fs_more_info', 'fs_pos_view'
66 ]
Rushabh Mehtad21f55b2014-04-29 16:24:37 +053067 for f in flds:
68 doc.set(f, 1)
Rushabh Mehtaf191f852014-04-02 18:09:34 +053069 doc.save()
Pratik Vyas28da7522014-02-19 20:53:45 +053070
71def set_single_defaults():
Nabin Haite7885e32014-04-04 13:26:50 +053072 for dt in frappe.db.sql_list("""select name from `tabDocType` where issingle=1"""):
Anand Doshieb7fea62014-03-19 17:10:01 +053073 default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField`
Rushabh Mehtaf14b8092014-04-03 14:30:42 +053074 where parent=%s""", dt)
Anand Doshieb7fea62014-03-19 17:10:01 +053075 if default_values:
76 try:
Rushabh Mehtab385ecf2014-03-28 16:44:37 +053077 b = frappe.get_doc(dt, dt)
Anand Doshieb7fea62014-03-19 17:10:01 +053078 for fieldname, value in default_values:
Anand Doshif78d1ae2014-03-28 13:55:00 +053079 b.set(fieldname, value)
Anand Doshieb7fea62014-03-19 17:10:01 +053080 b.save()
81 except frappe.MandatoryError:
82 pass
83
Anand Doshie9baaa62014-02-26 12:35:33 +053084 frappe.db.set_default("date_format", "dd-mm-yyyy")
Anand Doshi7f41ff22014-06-26 12:02:55 +053085
Anand Doshi56198f42014-06-26 12:47:45 +053086 frappe.db.set_value("Outgoing Email Settings", "Outgoing Email Settings", "footer",
87 default_mail_footer)