Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

271 righe
7.8 KiB

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