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.
 
 
 
 
 
 

127 lines
4.1 KiB

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