Rushabh Mehta | ad45e31 | 2013-11-20 12:59:58 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 4 | from __future__ import unicode_literals |
| 5 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 6 | import frappe |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 7 | |
Rushabh Mehta | 370a024 | 2014-04-18 16:00:41 +0530 | [diff] [blame] | 8 | from frappe import _ |
| 9 | |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 10 | def after_install(): |
Rushabh Mehta | 40b2b03 | 2014-04-21 13:43:11 +0530 | [diff] [blame] | 11 | frappe.get_doc({'doctype': "Role", "role_name": "Analytics"}).insert() |
Rushabh Mehta | 33003c6 | 2014-04-30 11:16:02 +0530 | [diff] [blame] | 12 | set_single_defaults() |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 13 | import_country_and_currency() |
Nabin Hait | 813a93d | 2014-03-06 18:21:56 +0530 | [diff] [blame] | 14 | from erpnext.accounts.doctype.chart_of_accounts.import_charts import import_charts |
| 15 | import_charts() |
Rushabh Mehta | 558a9aa | 2014-04-04 12:00:36 +0530 | [diff] [blame] | 16 | frappe.db.set_default('desktop:home_page', 'setup-wizard') |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 17 | feature_setup() |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 18 | from erpnext.setup.page.setup_wizard.setup_wizard import add_all_roles_to |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 19 | add_all_roles_to("Administrator") |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 20 | frappe.db.commit() |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 21 | |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 22 | def import_country_and_currency(): |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 23 | from frappe.country_info import get_all |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 24 | data = get_all() |
Anand Doshi | 13ae548 | 2014-04-10 18:40:57 +0530 | [diff] [blame] | 25 | |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 26 | for name in data: |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 27 | country = frappe._dict(data[name]) |
Anand Doshi | 7fbdba0 | 2014-03-25 13:50:52 +0530 | [diff] [blame] | 28 | if not frappe.db.exists("Country", name): |
Rushabh Mehta | b385ecf | 2014-03-28 16:44:37 +0530 | [diff] [blame] | 29 | frappe.get_doc({ |
Anand Doshi | 7fbdba0 | 2014-03-25 13:50:52 +0530 | [diff] [blame] | 30 | "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 Doshi | 13ae548 | 2014-04-10 18:40:57 +0530 | [diff] [blame] | 36 | |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 37 | if country.currency and not frappe.db.exists("Currency", country.currency): |
Rushabh Mehta | b385ecf | 2014-03-28 16:44:37 +0530 | [diff] [blame] | 38 | frappe.get_doc({ |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 39 | "doctype": "Currency", |
| 40 | "currency_name": country.currency, |
| 41 | "fraction": country.currency_fraction, |
| 42 | "symbol": country.currency_symbol, |
Rushabh Mehta | f5b04cf | 2013-01-21 10:14:10 +0530 | [diff] [blame] | 43 | "fraction_units": country.currency_fraction_units, |
| 44 | "number_format": country.number_format |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 45 | }).insert() |
| 46 | |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 47 | def feature_setup(): |
| 48 | """save global defaults and features setup""" |
Rushabh Mehta | f191f85 | 2014-04-02 18:09:34 +0530 | [diff] [blame] | 49 | doc = frappe.get_doc("Features Setup", "Features Setup") |
| 50 | doc.ignore_permissions = True |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 51 | |
| 52 | # store value as 1 for all these fields |
| 53 | flds = ['fs_item_serial_nos', 'fs_item_batch_nos', 'fs_brands', 'fs_item_barcode', |
| 54 | 'fs_item_advanced', 'fs_packing_details', 'fs_item_group_in_details', |
| 55 | 'fs_exports', 'fs_imports', 'fs_discounts', 'fs_purchase_discounts', |
| 56 | 'fs_after_sales_installations', 'fs_projects', 'fs_sales_extras', |
| 57 | 'fs_recurring_invoice', 'fs_pos', 'fs_manufacturing', 'fs_quality', |
| 58 | 'fs_page_break', 'fs_more_info', 'fs_pos_view' |
| 59 | ] |
Rushabh Mehta | d21f55b | 2014-04-29 16:24:37 +0530 | [diff] [blame] | 60 | for f in flds: |
| 61 | doc.set(f, 1) |
Rushabh Mehta | f191f85 | 2014-04-02 18:09:34 +0530 | [diff] [blame] | 62 | doc.save() |
Pratik Vyas | 28da752 | 2014-02-19 20:53:45 +0530 | [diff] [blame] | 63 | |
| 64 | def set_single_defaults(): |
Nabin Hait | e7885e3 | 2014-04-04 13:26:50 +0530 | [diff] [blame] | 65 | for dt in frappe.db.sql_list("""select name from `tabDocType` where issingle=1"""): |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 66 | default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField` |
Rushabh Mehta | f14b809 | 2014-04-03 14:30:42 +0530 | [diff] [blame] | 67 | where parent=%s""", dt) |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 68 | if default_values: |
| 69 | try: |
Rushabh Mehta | b385ecf | 2014-03-28 16:44:37 +0530 | [diff] [blame] | 70 | b = frappe.get_doc(dt, dt) |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 71 | for fieldname, value in default_values: |
Anand Doshi | f78d1ae | 2014-03-28 13:55:00 +0530 | [diff] [blame] | 72 | b.set(fieldname, value) |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 73 | b.save() |
| 74 | except frappe.MandatoryError: |
| 75 | pass |
| 76 | |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 77 | frappe.db.set_default("date_format", "dd-mm-yyyy") |