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.
 
 
 
 
 
 

335 lines
8.2 KiB

  1. # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
  2. # License: MIT. See LICENSE
  3. import getpass
  4. import frappe
  5. from frappe.utils.password import update_password
  6. def before_install():
  7. frappe.reload_doc("core", "doctype", "doctype_state")
  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("desk", "doctype", "form_tour_step")
  13. frappe.reload_doc("desk", "doctype", "form_tour")
  14. frappe.reload_doc("core", "doctype", "doctype")
  15. def after_install():
  16. create_user_type()
  17. install_basic_docs()
  18. from frappe.core.doctype.file.utils 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.get_all("Role", pluck="name"))
  28. # update admin password
  29. update_password("Administrator", get_admin_password())
  30. if not frappe.conf.skip_setup_wizard:
  31. # only set home_page if the value doesn't exist in the db
  32. if not frappe.db.get_default("desktop:home_page"):
  33. frappe.db.set_default("desktop:home_page", "setup-wizard")
  34. frappe.db.set_single_value("System Settings", "setup_complete", 0)
  35. # clear test log
  36. with open(frappe.get_site_path(".test_log"), "w") as f:
  37. f.write("")
  38. add_standard_navbar_items()
  39. frappe.db.commit()
  40. def create_user_type():
  41. for user_type in ["System User", "Website User"]:
  42. if not frappe.db.exists("User Type", user_type):
  43. frappe.get_doc({"doctype": "User Type", "name": user_type, "is_standard": 1}).insert(
  44. ignore_permissions=True
  45. )
  46. def install_basic_docs():
  47. # core users / roles
  48. install_docs = [
  49. {
  50. "doctype": "User",
  51. "name": "Administrator",
  52. "first_name": "Administrator",
  53. "email": "admin@example.com",
  54. "enabled": 1,
  55. "is_admin": 1,
  56. "roles": [{"role": "Administrator"}],
  57. "thread_notify": 0,
  58. "send_me_a_copy": 0,
  59. },
  60. {
  61. "doctype": "User",
  62. "name": "Guest",
  63. "first_name": "Guest",
  64. "email": "guest@example.com",
  65. "enabled": 1,
  66. "is_guest": 1,
  67. "roles": [{"role": "Guest"}],
  68. "thread_notify": 0,
  69. "send_me_a_copy": 0,
  70. },
  71. {"doctype": "Role", "role_name": "Report Manager"},
  72. {"doctype": "Role", "role_name": "Translator"},
  73. {
  74. "doctype": "Workflow State",
  75. "workflow_state_name": "Pending",
  76. "icon": "question-sign",
  77. "style": "",
  78. },
  79. {
  80. "doctype": "Workflow State",
  81. "workflow_state_name": "Approved",
  82. "icon": "ok-sign",
  83. "style": "Success",
  84. },
  85. {
  86. "doctype": "Workflow State",
  87. "workflow_state_name": "Rejected",
  88. "icon": "remove",
  89. "style": "Danger",
  90. },
  91. {"doctype": "Workflow Action Master", "workflow_action_name": "Approve"},
  92. {"doctype": "Workflow Action Master", "workflow_action_name": "Reject"},
  93. {"doctype": "Workflow Action Master", "workflow_action_name": "Review"},
  94. {
  95. "doctype": "Email Domain",
  96. "domain_name": "example.com",
  97. "email_id": "account@example.com",
  98. "password": "pass",
  99. "email_server": "imap.example.com",
  100. "use_imap": 1,
  101. "smtp_server": "smtp.example.com",
  102. },
  103. {
  104. "doctype": "Email Account",
  105. "domain": "example.com",
  106. "email_id": "notifications@example.com",
  107. "default_outgoing": 1,
  108. },
  109. {
  110. "doctype": "Email Account",
  111. "domain": "example.com",
  112. "email_id": "replies@example.com",
  113. "default_incoming": 1,
  114. },
  115. ]
  116. for d in install_docs:
  117. try:
  118. frappe.get_doc(d).insert(ignore_if_duplicate=True)
  119. except frappe.NameError:
  120. pass
  121. def get_admin_password():
  122. def ask_admin_password():
  123. admin_password = getpass.getpass("Set Administrator password: ")
  124. admin_password2 = getpass.getpass("Re-enter Administrator password: ")
  125. if not admin_password == admin_password2:
  126. print("\nPasswords do not match")
  127. return ask_admin_password()
  128. return admin_password
  129. admin_password = frappe.conf.get("admin_password")
  130. if not admin_password:
  131. return ask_admin_password()
  132. return admin_password
  133. def before_tests():
  134. if len(frappe.get_installed_apps()) > 1:
  135. # don't run before tests if any other app is installed
  136. return
  137. frappe.db.truncate("Custom Field")
  138. frappe.db.truncate("Event")
  139. frappe.clear_cache()
  140. # complete setup if missing
  141. if not int(frappe.db.get_single_value("System Settings", "setup_complete") or 0):
  142. complete_setup_wizard()
  143. frappe.db.commit()
  144. frappe.clear_cache()
  145. def complete_setup_wizard():
  146. from frappe.desk.page.setup_wizard.setup_wizard import setup_complete
  147. setup_complete(
  148. {
  149. "language": "English",
  150. "email": "test@erpnext.com",
  151. "full_name": "Test User",
  152. "password": "test",
  153. "country": "United States",
  154. "timezone": "America/New_York",
  155. "currency": "USD",
  156. }
  157. )
  158. def import_country_and_currency():
  159. from frappe.geo.country_info import get_all
  160. from frappe.utils import update_progress_bar
  161. data = get_all()
  162. for i, name in enumerate(data):
  163. update_progress_bar("Updating country info", i, len(data))
  164. country = frappe._dict(data[name])
  165. add_country_and_currency(name, country)
  166. print("")
  167. # enable frequently used currencies
  168. for currency in ("INR", "USD", "GBP", "EUR", "AED", "AUD", "JPY", "CNY", "CHF"):
  169. frappe.db.set_value("Currency", currency, "enabled", 1)
  170. def add_country_and_currency(name, country):
  171. if not frappe.db.exists("Country", name):
  172. frappe.get_doc(
  173. {
  174. "doctype": "Country",
  175. "country_name": name,
  176. "code": country.code,
  177. "date_format": country.date_format or "dd-mm-yyyy",
  178. "time_format": country.time_format or "HH:mm:ss",
  179. "time_zones": "\n".join(country.timezones or []),
  180. "docstatus": 0,
  181. }
  182. ).db_insert()
  183. if country.currency and not frappe.db.exists("Currency", country.currency):
  184. frappe.get_doc(
  185. {
  186. "doctype": "Currency",
  187. "currency_name": country.currency,
  188. "fraction": country.currency_fraction,
  189. "symbol": country.currency_symbol,
  190. "fraction_units": country.currency_fraction_units,
  191. "smallest_currency_fraction_value": country.smallest_currency_fraction_value,
  192. "number_format": country.number_format,
  193. "docstatus": 0,
  194. }
  195. ).db_insert()
  196. def add_standard_navbar_items():
  197. navbar_settings = frappe.get_single("Navbar Settings")
  198. # don't add settings/help options if they're already present
  199. if navbar_settings.settings_dropdown and navbar_settings.help_dropdown:
  200. return
  201. standard_navbar_items = [
  202. {
  203. "item_label": "My Profile",
  204. "item_type": "Route",
  205. "route": "/app/user-profile",
  206. "is_standard": 1,
  207. },
  208. {
  209. "item_label": "My Settings",
  210. "item_type": "Action",
  211. "action": "frappe.ui.toolbar.route_to_user()",
  212. "is_standard": 1,
  213. },
  214. {
  215. "item_label": "Session Defaults",
  216. "item_type": "Action",
  217. "action": "frappe.ui.toolbar.setup_session_defaults()",
  218. "is_standard": 1,
  219. },
  220. {
  221. "item_label": "Reload",
  222. "item_type": "Action",
  223. "action": "frappe.ui.toolbar.clear_cache()",
  224. "is_standard": 1,
  225. },
  226. {
  227. "item_label": "View Website",
  228. "item_type": "Action",
  229. "action": "frappe.ui.toolbar.view_website()",
  230. "is_standard": 1,
  231. },
  232. {
  233. "item_label": "Toggle Full Width",
  234. "item_type": "Action",
  235. "action": "frappe.ui.toolbar.toggle_full_width()",
  236. "is_standard": 1,
  237. },
  238. {
  239. "item_label": "Toggle Theme",
  240. "item_type": "Action",
  241. "action": "new frappe.ui.ThemeSwitcher().show()",
  242. "is_standard": 1,
  243. },
  244. {
  245. "item_type": "Separator",
  246. "is_standard": 1,
  247. "item_label": "",
  248. },
  249. {
  250. "item_label": "Log out",
  251. "item_type": "Action",
  252. "action": "frappe.app.logout()",
  253. "is_standard": 1,
  254. },
  255. ]
  256. standard_help_items = [
  257. {
  258. "item_label": "About",
  259. "item_type": "Action",
  260. "action": "frappe.ui.toolbar.show_about()",
  261. "is_standard": 1,
  262. },
  263. {
  264. "item_label": "Keyboard Shortcuts",
  265. "item_type": "Action",
  266. "action": "frappe.ui.toolbar.show_shortcuts(event)",
  267. "is_standard": 1,
  268. },
  269. {
  270. "item_label": "Frappe Support",
  271. "item_type": "Route",
  272. "route": "https://frappe.io/support",
  273. "is_standard": 1,
  274. },
  275. ]
  276. navbar_settings.settings_dropdown = []
  277. navbar_settings.help_dropdown = []
  278. for item in standard_navbar_items:
  279. navbar_settings.append("settings_dropdown", item)
  280. for item in standard_help_items:
  281. navbar_settings.append("help_dropdown", item)
  282. navbar_settings.save()