blob: 0e8e58d95759b475b52dd1739ef5cf3d4ece2267 [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 Doshi6b8145a2014-08-08 13:24:18 +053031 add_country_and_currency(name, country)
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053032
Anand Doshide560aa2014-05-06 12:02:23 +053033 # enable frequently used currencies
34 for currency in ("INR", "USD", "GBP", "EUR", "AED", "AUD", "JPY", "CNY", "CHF"):
35 frappe.db.set_value("Currency", currency, "enabled", 1)
36
Anand Doshi6b8145a2014-08-08 13:24:18 +053037def add_country_and_currency(name, country):
38 if not frappe.db.exists("Country", name):
39 frappe.get_doc({
40 "doctype": "Country",
41 "country_name": name,
42 "code": country.code,
43 "date_format": country.date_format or "dd-mm-yyyy",
44 "time_zones": "\n".join(country.timezones or [])
45 }).insert()
46
47 if country.currency and not frappe.db.exists("Currency", country.currency):
48 frappe.get_doc({
49 "doctype": "Currency",
50 "currency_name": country.currency,
51 "fraction": country.currency_fraction,
52 "symbol": country.currency_symbol,
53 "fraction_units": country.currency_fraction_units,
54 "number_format": country.number_format
55 }).insert()
56
Rushabh Mehta1f847992013-12-12 19:12:19 +053057def feature_setup():
58 """save global defaults and features setup"""
Rushabh Mehtaf191f852014-04-02 18:09:34 +053059 doc = frappe.get_doc("Features Setup", "Features Setup")
60 doc.ignore_permissions = True
Rushabh Mehta1f847992013-12-12 19:12:19 +053061
62 # store value as 1 for all these fields
63 flds = ['fs_item_serial_nos', 'fs_item_batch_nos', 'fs_brands', 'fs_item_barcode',
64 'fs_item_advanced', 'fs_packing_details', 'fs_item_group_in_details',
65 'fs_exports', 'fs_imports', 'fs_discounts', 'fs_purchase_discounts',
66 'fs_after_sales_installations', 'fs_projects', 'fs_sales_extras',
67 'fs_recurring_invoice', 'fs_pos', 'fs_manufacturing', 'fs_quality',
68 'fs_page_break', 'fs_more_info', 'fs_pos_view'
69 ]
Rushabh Mehtad21f55b2014-04-29 16:24:37 +053070 for f in flds:
71 doc.set(f, 1)
Rushabh Mehtaf191f852014-04-02 18:09:34 +053072 doc.save()
Pratik Vyas28da7522014-02-19 20:53:45 +053073
74def set_single_defaults():
Nabin Haite7885e32014-04-04 13:26:50 +053075 for dt in frappe.db.sql_list("""select name from `tabDocType` where issingle=1"""):
Anand Doshieb7fea62014-03-19 17:10:01 +053076 default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField`
Rushabh Mehtaf14b8092014-04-03 14:30:42 +053077 where parent=%s""", dt)
Anand Doshieb7fea62014-03-19 17:10:01 +053078 if default_values:
79 try:
Rushabh Mehtab385ecf2014-03-28 16:44:37 +053080 b = frappe.get_doc(dt, dt)
Anand Doshieb7fea62014-03-19 17:10:01 +053081 for fieldname, value in default_values:
Anand Doshif78d1ae2014-03-28 13:55:00 +053082 b.set(fieldname, value)
Anand Doshieb7fea62014-03-19 17:10:01 +053083 b.save()
84 except frappe.MandatoryError:
85 pass
86
Anand Doshie9baaa62014-02-26 12:35:33 +053087 frappe.db.set_default("date_format", "dd-mm-yyyy")
Anand Doshi7f41ff22014-06-26 12:02:55 +053088
Anand Doshi56198f42014-06-26 12:47:45 +053089 frappe.db.set_value("Outgoing Email Settings", "Outgoing Email Settings", "footer",
90 default_mail_footer)