Anand Doshi | 885e074 | 2015-03-03 14:55:30 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Aditya Hase | 6ccb656 | 2017-08-28 18:17:36 +0530 | [diff] [blame] | 4 | from __future__ import print_function, unicode_literals |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 5 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 6 | import frappe |
Rushabh Mehta | d42167e | 2016-05-11 16:47:14 +0530 | [diff] [blame] | 7 | from frappe import _ |
Nabin Hait | 45dce89 | 2017-09-14 15:17:38 +0530 | [diff] [blame] | 8 | from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to |
| 9 | from frappe.custom.doctype.custom_field.custom_field import create_custom_field |
Rushabh Mehta | 6f9915c | 2013-01-16 17:48:17 +0530 | [diff] [blame] | 10 | |
Anand Doshi | 56198f4 | 2014-06-26 12:47:45 +0530 | [diff] [blame] | 11 | default_mail_footer = """<div style="padding: 7px; text-align: right; color: #888"><small>Sent via |
Anand Doshi | 7f41ff2 | 2014-06-26 12:02:55 +0530 | [diff] [blame] | 12 | <a style="color: #888" href="http://erpnext.org">ERPNext</a></div>""" |
| 13 | |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 14 | def after_install(): |
Shreya | 61cf49d | 2018-01-24 18:21:18 +0530 | [diff] [blame] | 15 | leave_application_workflow() |
Rushabh Mehta | 40b2b03 | 2014-04-21 13:43:11 +0530 | [diff] [blame] | 16 | frappe.get_doc({'doctype': "Role", "role_name": "Analytics"}).insert() |
Rushabh Mehta | 33003c6 | 2014-04-30 11:16:02 +0530 | [diff] [blame] | 17 | set_single_defaults() |
Rushabh Mehta | d42167e | 2016-05-11 16:47:14 +0530 | [diff] [blame] | 18 | create_compact_item_print_custom_field() |
Nabin Hait | 45dce89 | 2017-09-14 15:17:38 +0530 | [diff] [blame] | 19 | create_print_zero_amount_taxes_custom_field() |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 20 | add_all_roles_to("Administrator") |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 21 | frappe.db.commit() |
Rushabh Mehta | db7139a | 2013-01-17 18:22:22 +0530 | [diff] [blame] | 22 | |
Shreya | 61cf49d | 2018-01-24 18:21:18 +0530 | [diff] [blame] | 23 | def leave_application_workflow(): |
| 24 | states = {'Approved': 'Success', 'Rejected': 'Danger', 'Open': 'Warning'} |
| 25 | |
| 26 | for state, style in states.items(): |
| 27 | if not frappe.db.exists("Workflow State", state): |
| 28 | frappe.get_doc({ |
| 29 | 'doctype': 'Workflow State', |
| 30 | 'workflow_state_name': state, |
| 31 | 'style': style |
| 32 | }).insert(ignore_permissions=True) |
| 33 | |
Shreya | 5f264fa | 2018-01-24 20:39:30 +0530 | [diff] [blame^] | 34 | for action in ['Approve', 'Reject']: |
| 35 | if not frappe.db.exists("Workflow Action", action): |
| 36 | frappe.get_doc({ |
| 37 | 'doctype': 'Workflow Action', |
| 38 | 'workflow_action_name': action |
| 39 | }).insert(ignore_permissions=True) |
| 40 | |
Shreya | 61cf49d | 2018-01-24 18:21:18 +0530 | [diff] [blame] | 41 | if not frappe.db.exists("Workflow", "Leave Approval"): |
| 42 | frappe.get_doc({ |
| 43 | 'doctype': 'Workflow', |
| 44 | 'workflow_name': 'Leave Approval', |
| 45 | 'document_type': 'Leave Application', |
| 46 | 'is_active': 1, |
| 47 | 'workflow_state_field': 'workflow_state', |
| 48 | 'states': [{ |
| 49 | "state": 'Open', |
| 50 | "doc_status": 0, |
| 51 | "allow_edit": 'Employee' |
| 52 | }, { |
| 53 | "state": 'Approved', |
| 54 | "doc_status": 1, |
| 55 | "allow_edit": 'Leave Approver' |
| 56 | }, { |
| 57 | "state": 'Rejected', |
| 58 | "doc_status": 1, |
| 59 | "allow_edit": 'Leave Approver' |
| 60 | }], |
| 61 | 'transitions': [{ |
| 62 | "state": 'Open', |
| 63 | "action": 'Approve', |
| 64 | "next_state": 'Approved', |
| 65 | "allowed": 'Leave Approver' |
| 66 | }, |
| 67 | { |
| 68 | "state": 'Open', |
| 69 | "action": 'Reject', |
| 70 | "next_state": 'Rejected', |
| 71 | "allowed": 'Leave Approver' |
| 72 | }] |
| 73 | }).insert(ignore_permissions=True) |
| 74 | |
Rushabh Mehta | d55bdcf | 2015-12-31 11:12:48 +0530 | [diff] [blame] | 75 | def check_setup_wizard_not_completed(): |
| 76 | if frappe.db.get_default('desktop:home_page') == 'desktop': |
Aditya Hase | 6ccb656 | 2017-08-28 18:17:36 +0530 | [diff] [blame] | 77 | print() |
| 78 | print("ERPNext can only be installed on a fresh site where the setup wizard is not completed") |
| 79 | print("You can reinstall this site (after saving your data) using: bench --site [sitename] reinstall") |
| 80 | print() |
Rushabh Mehta | d55bdcf | 2015-12-31 11:12:48 +0530 | [diff] [blame] | 81 | return False |
| 82 | |
Pratik Vyas | 28da752 | 2014-02-19 20:53:45 +0530 | [diff] [blame] | 83 | def set_single_defaults(): |
Rushabh Mehta | b62ed7a | 2016-10-13 11:00:00 +0530 | [diff] [blame] | 84 | for dt in ('Accounts Settings', 'Print Settings', 'HR Settings', 'Buying Settings', |
Rushabh Mehta | fe816c3 | 2016-11-08 18:18:40 +0530 | [diff] [blame] | 85 | 'Selling Settings', 'Stock Settings', 'Daily Work Summary Settings'): |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 86 | default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField` |
Rushabh Mehta | f14b809 | 2014-04-03 14:30:42 +0530 | [diff] [blame] | 87 | where parent=%s""", dt) |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 88 | if default_values: |
| 89 | try: |
Rushabh Mehta | b385ecf | 2014-03-28 16:44:37 +0530 | [diff] [blame] | 90 | b = frappe.get_doc(dt, dt) |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 91 | for fieldname, value in default_values: |
Anand Doshi | f78d1ae | 2014-03-28 13:55:00 +0530 | [diff] [blame] | 92 | b.set(fieldname, value) |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 93 | b.save() |
| 94 | except frappe.MandatoryError: |
| 95 | pass |
Rushabh Mehta | b62ed7a | 2016-10-13 11:00:00 +0530 | [diff] [blame] | 96 | except frappe.ValidationError: |
| 97 | pass |
Anand Doshi | eb7fea6 | 2014-03-19 17:10:01 +0530 | [diff] [blame] | 98 | |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 99 | frappe.db.set_default("date_format", "dd-mm-yyyy") |
Rushabh Mehta | d42167e | 2016-05-11 16:47:14 +0530 | [diff] [blame] | 100 | |
| 101 | def create_compact_item_print_custom_field(): |
Rushabh Mehta | d42167e | 2016-05-11 16:47:14 +0530 | [diff] [blame] | 102 | create_custom_field('Print Settings', { |
| 103 | 'label': _('Compact Item Print'), |
| 104 | 'fieldname': 'compact_item_print', |
| 105 | 'fieldtype': 'Check', |
| 106 | 'default': 1, |
| 107 | 'insert_after': 'with_letterhead' |
Nabin Hait | 45dce89 | 2017-09-14 15:17:38 +0530 | [diff] [blame] | 108 | }) |
| 109 | |
| 110 | def create_print_zero_amount_taxes_custom_field(): |
| 111 | create_custom_field('Print Settings', { |
| 112 | 'label': _('Print taxes with zero amount'), |
| 113 | 'fieldname': 'print_taxes_with_zero_amount', |
| 114 | 'fieldtype': 'Check', |
| 115 | 'default': 0, |
| 116 | 'insert_after': 'allow_print_for_cancelled' |
Rushabh Mehta | d42167e | 2016-05-11 16:47:14 +0530 | [diff] [blame] | 117 | }) |