You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

265 lines
7.6 KiB

  1. # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals, print_function
  4. import frappe
  5. import getpass
  6. from frappe.utils.password import update_password
  7. def before_install():
  8. frappe.reload_doc("core", "doctype", "docfield")
  9. frappe.reload_doc("core", "doctype", "docperm")
  10. frappe.reload_doc("core", "doctype", "doctype_action")
  11. frappe.reload_doc("core", "doctype", "doctype_link")
  12. frappe.reload_doc("core", "doctype", "doctype")
  13. def after_install():
  14. # reset installed apps for re-install
  15. frappe.db.set_global("installed_apps", '["frappe"]')
  16. create_user_type()
  17. install_basic_docs()
  18. from frappe.core.doctype.file.file import make_home_folder
  19. make_home_folder()
  20. import_country_and_currency()
  21. from frappe.core.doctype.language.language import sync_languages
  22. sync_languages()
  23. # save default print setting
  24. print_settings = frappe.get_doc("Print Settings")
  25. print_settings.save()
  26. # all roles to admin
  27. frappe.get_doc("User", "Administrator").add_roles(*frappe.db.sql_list("""select name from tabRole"""))
  28. # update admin password
  29. update_password("Administrator", get_admin_password())
  30. if not frappe.conf.skip_setup_wizard:
  31. frappe.db.set_default('desktop:home_page', 'setup-wizard')
  32. # clear test log
  33. with open(frappe.get_site_path('.test_log'), 'w') as f:
  34. f.write('')
  35. add_standard_navbar_items()
  36. frappe.db.commit()
  37. def create_user_type():
  38. for user_type in ['System User', 'Website User']:
  39. if not frappe.db.exists('User Type', user_type):
  40. frappe.get_doc({
  41. 'doctype': 'User Type',
  42. 'name': user_type,
  43. 'is_standard': 1
  44. }).insert(ignore_permissions=True)
  45. def install_basic_docs():
  46. # core users / roles
  47. install_docs = [
  48. {'doctype':'User', 'name':'Administrator', 'first_name':'Administrator',
  49. 'email':'admin@example.com', 'enabled':1, "is_admin": 1,
  50. 'roles': [{'role': 'Administrator'}],
  51. 'thread_notify': 0, 'send_me_a_copy': 0
  52. },
  53. {'doctype':'User', 'name':'Guest', 'first_name':'Guest',
  54. 'email':'guest@example.com', 'enabled':1, "is_guest": 1,
  55. 'roles': [{'role': 'Guest'}],
  56. 'thread_notify': 0, 'send_me_a_copy': 0
  57. },
  58. {'doctype': "Role", "role_name": "Report Manager"},
  59. {'doctype': "Role", "role_name": "Translator"},
  60. {'doctype': "Workflow State", "workflow_state_name": "Pending",
  61. "icon": "question-sign", "style": ""},
  62. {'doctype': "Workflow State", "workflow_state_name": "Approved",
  63. "icon": "ok-sign", "style": "Success"},
  64. {'doctype': "Workflow State", "workflow_state_name": "Rejected",
  65. "icon": "remove", "style": "Danger"},
  66. {'doctype': "Workflow Action Master", "workflow_action_name": "Approve"},
  67. {'doctype': "Workflow Action Master", "workflow_action_name": "Reject"},
  68. {'doctype': "Workflow Action Master", "workflow_action_name": "Review"},
  69. {'doctype': "Email Domain", "domain_name":"example.com", "email_id": "account@example.com", "password": "pass", "email_server": "imap.example.com","use_imap": 1, "smtp_server": "smtp.example.com"},
  70. {'doctype': "Email Account", "domain":"example.com", "email_id": "notifications@example.com", "default_outgoing": 1},
  71. {'doctype': "Email Account", "domain":"example.com", "email_id": "replies@example.com", "default_incoming": 1}
  72. ]
  73. for d in install_docs:
  74. try:
  75. frappe.get_doc(d).insert()
  76. except frappe.NameError:
  77. pass
  78. def get_admin_password():
  79. def ask_admin_password():
  80. admin_password = getpass.getpass("Set Administrator password: ")
  81. admin_password2 = getpass.getpass("Re-enter Administrator password: ")
  82. if not admin_password == admin_password2:
  83. print("\nPasswords do not match")
  84. return ask_admin_password()
  85. return admin_password
  86. admin_password = frappe.conf.get("admin_password")
  87. if not admin_password:
  88. return ask_admin_password()
  89. return admin_password
  90. def before_tests():
  91. if len(frappe.get_installed_apps()) > 1:
  92. # don't run before tests if any other app is installed
  93. return
  94. frappe.db.sql("delete from `tabCustom Field`")
  95. frappe.db.sql("delete from `tabEvent`")
  96. frappe.db.commit()
  97. frappe.clear_cache()
  98. # complete setup if missing
  99. if not int(frappe.db.get_single_value('System Settings', 'setup_complete') or 0):
  100. complete_setup_wizard()
  101. frappe.db.commit()
  102. frappe.clear_cache()
  103. def complete_setup_wizard():
  104. from frappe.desk.page.setup_wizard.setup_wizard import setup_complete
  105. setup_complete({
  106. "language" :"English",
  107. "email" :"test@erpnext.com",
  108. "full_name" :"Test User",
  109. "password" :"test",
  110. "country" :"United States",
  111. "timezone" :"America/New_York",
  112. "currency" :"USD"
  113. })
  114. def import_country_and_currency():
  115. from frappe.geo.country_info import get_all
  116. from frappe.utils import update_progress_bar
  117. data = get_all()
  118. for i, name in enumerate(data):
  119. update_progress_bar("Updating country info", i, len(data))
  120. country = frappe._dict(data[name])
  121. add_country_and_currency(name, country)
  122. print("")
  123. # enable frequently used currencies
  124. for currency in ("INR", "USD", "GBP", "EUR", "AED", "AUD", "JPY", "CNY", "CHF"):
  125. frappe.db.set_value("Currency", currency, "enabled", 1)
  126. def add_country_and_currency(name, country):
  127. if not frappe.db.exists("Country", name):
  128. frappe.get_doc({
  129. "doctype": "Country",
  130. "country_name": name,
  131. "code": country.code,
  132. "date_format": country.date_format or "dd-mm-yyyy",
  133. "time_format": country.time_format or "HH:mm:ss",
  134. "time_zones": "\n".join(country.timezones or []),
  135. "docstatus": 0
  136. }).db_insert()
  137. if country.currency and not frappe.db.exists("Currency", country.currency):
  138. frappe.get_doc({
  139. "doctype": "Currency",
  140. "currency_name": country.currency,
  141. "fraction": country.currency_fraction,
  142. "symbol": country.currency_symbol,
  143. "fraction_units": country.currency_fraction_units,
  144. "smallest_currency_fraction_value": country.smallest_currency_fraction_value,
  145. "number_format": country.number_format,
  146. "docstatus": 0
  147. }).db_insert()
  148. def add_standard_navbar_items():
  149. navbar_settings = frappe.get_single("Navbar Settings")
  150. standard_navbar_items = [
  151. {
  152. 'item_label': 'My Profile',
  153. 'item_type': 'Route',
  154. 'route': '/app/user-profile',
  155. 'is_standard': 1
  156. },
  157. {
  158. 'item_label': 'My Settings',
  159. 'item_type': 'Action',
  160. 'action': 'frappe.ui.toolbar.route_to_user()',
  161. 'is_standard': 1
  162. },
  163. {
  164. 'item_label': 'Session Defaults',
  165. 'item_type': 'Action',
  166. 'action': 'frappe.ui.toolbar.setup_session_defaults()',
  167. 'is_standard': 1
  168. },
  169. {
  170. 'item_label': 'Reload',
  171. 'item_type': 'Action',
  172. 'action': 'frappe.ui.toolbar.clear_cache()',
  173. 'is_standard': 1
  174. },
  175. {
  176. 'item_label': 'View Website',
  177. 'item_type': 'Action',
  178. 'action': 'frappe.ui.toolbar.view_website()',
  179. 'is_standard': 1
  180. },
  181. {
  182. 'item_label': 'Toggle Full Width',
  183. 'item_type': 'Action',
  184. 'action': 'frappe.ui.toolbar.toggle_full_width()',
  185. 'is_standard': 1
  186. },
  187. {
  188. 'item_label': 'Background Jobs',
  189. 'item_type': 'Route',
  190. 'route': '/app/background_jobs',
  191. 'is_standard': 1
  192. },
  193. {
  194. 'item_type': 'Separator',
  195. 'is_standard': 1
  196. },
  197. {
  198. 'item_label': 'Logout',
  199. 'item_type': 'Action',
  200. 'action': 'frappe.app.logout()',
  201. 'is_standard': 1
  202. }
  203. ]
  204. standard_help_items = [
  205. {
  206. 'item_label': 'About',
  207. 'item_type': 'Action',
  208. 'action': 'frappe.ui.toolbar.show_about()',
  209. 'is_standard': 1
  210. },
  211. {
  212. 'item_label': 'Keyboard Shortcuts',
  213. 'item_type': 'Action',
  214. 'action': 'frappe.ui.toolbar.show_shortcuts(event)',
  215. 'is_standard': 1
  216. }
  217. ]
  218. navbar_settings.settings_dropdown = []
  219. navbar_settings.help_dropdown = []
  220. for item in standard_navbar_items:
  221. navbar_settings.append('settings_dropdown', item)
  222. for item in standard_help_items:
  223. navbar_settings.append('help_dropdown', item)
  224. navbar_settings.save()