blob: 1c646101b21f254697f63cc79ef9dbc9de53d373 [file] [log] [blame]
Anand Doshi885e0742015-03-03 14:55:30 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302# License: GNU General Public License v3. See license.txt
3
Aditya Hase6ccb6562017-08-28 18:17:36 +05304from __future__ import print_function, unicode_literals
Rushabh Mehta6f9915c2013-01-16 17:48:17 +05305
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05306import frappe
Rushabh Mehtad42167e2016-05-11 16:47:14 +05307from frappe import _
Nabin Hait45dce892017-09-14 15:17:38 +05308from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to
9from frappe.custom.doctype.custom_field.custom_field import create_custom_field
Rushabh Mehta6f9915c2013-01-16 17:48:17 +053010
Anand Doshi56198f42014-06-26 12:47:45 +053011default_mail_footer = """<div style="padding: 7px; text-align: right; color: #888"><small>Sent via
Anand Doshi7f41ff22014-06-26 12:02:55 +053012 <a style="color: #888" href="http://erpnext.org">ERPNext</a></div>"""
13
Rushabh Mehta1f847992013-12-12 19:12:19 +053014def after_install():
Shreya61cf49d2018-01-24 18:21:18 +053015 leave_application_workflow()
Rushabh Mehta40b2b032014-04-21 13:43:11 +053016 frappe.get_doc({'doctype': "Role", "role_name": "Analytics"}).insert()
Rushabh Mehta33003c62014-04-30 11:16:02 +053017 set_single_defaults()
Rushabh Mehtad42167e2016-05-11 16:47:14 +053018 create_compact_item_print_custom_field()
Nabin Hait45dce892017-09-14 15:17:38 +053019 create_print_zero_amount_taxes_custom_field()
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053020 add_all_roles_to("Administrator")
Anand Doshie9baaa62014-02-26 12:35:33 +053021 frappe.db.commit()
Rushabh Mehtadb7139a2013-01-17 18:22:22 +053022
Shreya61cf49d2018-01-24 18:21:18 +053023def 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
34 if not frappe.db.exists("Workflow", "Leave Approval"):
35 frappe.get_doc({
36 'doctype': 'Workflow',
37 'workflow_name': 'Leave Approval',
38 'document_type': 'Leave Application',
39 'is_active': 1,
40 'workflow_state_field': 'workflow_state',
41 'states': [{
42 "state": 'Open',
43 "doc_status": 0,
44 "allow_edit": 'Employee'
45 }, {
46 "state": 'Approved',
47 "doc_status": 1,
48 "allow_edit": 'Leave Approver'
49 }, {
50 "state": 'Rejected',
51 "doc_status": 1,
52 "allow_edit": 'Leave Approver'
53 }],
54 'transitions': [{
55 "state": 'Open',
56 "action": 'Approve',
57 "next_state": 'Approved',
58 "allowed": 'Leave Approver'
59 },
60 {
61 "state": 'Open',
62 "action": 'Reject',
63 "next_state": 'Rejected',
64 "allowed": 'Leave Approver'
65 }]
66 }).insert(ignore_permissions=True)
67
Rushabh Mehtad55bdcf2015-12-31 11:12:48 +053068def check_setup_wizard_not_completed():
69 if frappe.db.get_default('desktop:home_page') == 'desktop':
Aditya Hase6ccb6562017-08-28 18:17:36 +053070 print()
71 print("ERPNext can only be installed on a fresh site where the setup wizard is not completed")
72 print("You can reinstall this site (after saving your data) using: bench --site [sitename] reinstall")
73 print()
Rushabh Mehtad55bdcf2015-12-31 11:12:48 +053074 return False
75
Pratik Vyas28da7522014-02-19 20:53:45 +053076def set_single_defaults():
Rushabh Mehtab62ed7a2016-10-13 11:00:00 +053077 for dt in ('Accounts Settings', 'Print Settings', 'HR Settings', 'Buying Settings',
Rushabh Mehtafe816c32016-11-08 18:18:40 +053078 'Selling Settings', 'Stock Settings', 'Daily Work Summary Settings'):
Anand Doshieb7fea62014-03-19 17:10:01 +053079 default_values = frappe.db.sql("""select fieldname, `default` from `tabDocField`
Rushabh Mehtaf14b8092014-04-03 14:30:42 +053080 where parent=%s""", dt)
Anand Doshieb7fea62014-03-19 17:10:01 +053081 if default_values:
82 try:
Rushabh Mehtab385ecf2014-03-28 16:44:37 +053083 b = frappe.get_doc(dt, dt)
Anand Doshieb7fea62014-03-19 17:10:01 +053084 for fieldname, value in default_values:
Anand Doshif78d1ae2014-03-28 13:55:00 +053085 b.set(fieldname, value)
Anand Doshieb7fea62014-03-19 17:10:01 +053086 b.save()
87 except frappe.MandatoryError:
88 pass
Rushabh Mehtab62ed7a2016-10-13 11:00:00 +053089 except frappe.ValidationError:
90 pass
Anand Doshieb7fea62014-03-19 17:10:01 +053091
Anand Doshie9baaa62014-02-26 12:35:33 +053092 frappe.db.set_default("date_format", "dd-mm-yyyy")
Rushabh Mehtad42167e2016-05-11 16:47:14 +053093
94def create_compact_item_print_custom_field():
Rushabh Mehtad42167e2016-05-11 16:47:14 +053095 create_custom_field('Print Settings', {
96 'label': _('Compact Item Print'),
97 'fieldname': 'compact_item_print',
98 'fieldtype': 'Check',
99 'default': 1,
100 'insert_after': 'with_letterhead'
Nabin Hait45dce892017-09-14 15:17:38 +0530101 })
102
103def create_print_zero_amount_taxes_custom_field():
104 create_custom_field('Print Settings', {
105 'label': _('Print taxes with zero amount'),
106 'fieldname': 'print_taxes_with_zero_amount',
107 'fieldtype': 'Check',
108 'default': 0,
109 'insert_after': 'allow_print_for_cancelled'
Rushabh Mehtad42167e2016-05-11 16:47:14 +0530110 })