Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

137 rindas
4.5 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")
  11. def after_install():
  12. # reset installed apps for re-install
  13. frappe.db.set_global("installed_apps", '["frappe"]')
  14. install_basic_docs()
  15. from frappe.core.doctype.file.file import make_home_folder
  16. make_home_folder()
  17. import_country_and_currency()
  18. from frappe.core.doctype.language.language import sync_languages
  19. sync_languages()
  20. # save default print setting
  21. print_settings = frappe.get_doc("Print Settings")
  22. print_settings.save()
  23. # all roles to admin
  24. frappe.get_doc("User", "Administrator").add_roles(*frappe.db.sql_list("""select name from tabRole"""))
  25. # update admin password
  26. update_password("Administrator", get_admin_password())
  27. # setup wizard now in frappe
  28. frappe.db.set_default('desktop:home_page', 'setup-wizard')
  29. frappe.db.commit()
  30. def install_basic_docs():
  31. # core users / roles
  32. install_docs = [
  33. {'doctype':'User', 'name':'Administrator', 'first_name':'Administrator',
  34. 'email':'admin@example.com', 'enabled':1, "is_admin": 1,
  35. 'roles': [{'role': 'Administrator'}]
  36. },
  37. {'doctype':'User', 'name':'Guest', 'first_name':'Guest',
  38. 'email':'guest@example.com', 'enabled':1, "is_guest": 1,
  39. 'roles': [{'role': 'Guest'}]
  40. },
  41. {'doctype': "Role", "role_name": "Report Manager"},
  42. {'doctype': "Workflow State", "workflow_state_name": "Pending",
  43. "icon": "question-sign", "style": ""},
  44. {'doctype': "Workflow State", "workflow_state_name": "Approved",
  45. "icon": "ok-sign", "style": "Success"},
  46. {'doctype': "Workflow State", "workflow_state_name": "Rejected",
  47. "icon": "remove", "style": "Danger"},
  48. {'doctype': "Workflow Action", "workflow_action_name": "Approve"},
  49. {'doctype': "Workflow Action", "workflow_action_name": "Reject"},
  50. {'doctype': "Workflow Action", "workflow_action_name": "Review"},
  51. {'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"},
  52. {'doctype': "Email Account", "domain":"example.com", "email_id": "notifications@example.com", "default_outgoing": 1},
  53. {'doctype': "Email Account", "domain":"example.com", "email_id": "replies@example.com", "default_incoming": 1}
  54. ]
  55. for d in install_docs:
  56. try:
  57. frappe.get_doc(d).insert()
  58. except frappe.NameError:
  59. pass
  60. def get_admin_password():
  61. def ask_admin_password():
  62. admin_password = getpass.getpass("Set Administrator password: ")
  63. admin_password2 = getpass.getpass("Re-enter Administrator password: ")
  64. if not admin_password == admin_password2:
  65. print("\nPasswords do not match")
  66. return ask_admin_password()
  67. return admin_password
  68. admin_password = frappe.conf.get("admin_password")
  69. if not admin_password:
  70. return ask_admin_password()
  71. return admin_password
  72. def before_tests():
  73. frappe.db.sql("delete from `tabCustom Field`")
  74. frappe.db.sql("delete from `tabEvent`")
  75. frappe.db.commit()
  76. frappe.clear_cache()
  77. def import_country_and_currency():
  78. from frappe.geo.country_info import get_all
  79. from frappe.utils import update_progress_bar
  80. data = get_all()
  81. for i, name in enumerate(data):
  82. update_progress_bar("Updating country info", i, len(data))
  83. country = frappe._dict(data[name])
  84. add_country_and_currency(name, country)
  85. print()
  86. # enable frequently used currencies
  87. for currency in ("INR", "USD", "GBP", "EUR", "AED", "AUD", "JPY", "CNY", "CHF"):
  88. frappe.db.set_value("Currency", currency, "enabled", 1)
  89. def add_country_and_currency(name, country):
  90. if not frappe.db.exists("Country", name):
  91. frappe.get_doc({
  92. "doctype": "Country",
  93. "country_name": name,
  94. "code": country.code,
  95. "date_format": country.date_format or "dd-mm-yyyy",
  96. "time_zones": "\n".join(country.timezones or []),
  97. "docstatus": 0
  98. }).db_insert()
  99. if country.currency and not frappe.db.exists("Currency", country.currency):
  100. frappe.get_doc({
  101. "doctype": "Currency",
  102. "currency_name": country.currency,
  103. "fraction": country.currency_fraction,
  104. "symbol": country.currency_symbol,
  105. "fraction_units": country.currency_fraction_units,
  106. "smallest_currency_fraction_value": country.smallest_currency_fraction_value,
  107. "number_format": country.number_format,
  108. "docstatus": 0
  109. }).db_insert()