feat: appointment Letter (#20104)

* feat: appointment Letter

* fix: requested changes

Co-authored-by: Nabin Hait <nabinhait@gmail.com>
diff --git a/erpnext/config/hr.py b/erpnext/config/hr.py
index 4e5e903..7b3b466 100644
--- a/erpnext/config/hr.py
+++ b/erpnext/config/hr.py
@@ -291,6 +291,10 @@
 				},
 				{
 					"type": "doctype",
+					"name": "Appointment Letter",
+				},
+				{
+					"type": "doctype",
 					"name": "Staffing Plan",
 				},
 			]
diff --git a/erpnext/hr/doctype/appointment_letter/__init__.py b/erpnext/hr/doctype/appointment_letter/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/hr/doctype/appointment_letter/__init__.py
diff --git a/erpnext/hr/doctype/appointment_letter/appointment_letter.js b/erpnext/hr/doctype/appointment_letter/appointment_letter.js
new file mode 100644
index 0000000..a338dc6
--- /dev/null
+++ b/erpnext/hr/doctype/appointment_letter/appointment_letter.js
@@ -0,0 +1,30 @@
+// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Appointment Letter', {
+	appointment_letter_template: function(frm){
+		if (frm.doc.appointment_letter_template){
+			frappe.call({
+				method: 'erpnext.hr.doctype.appointment_letter.appointment_letter.get_appointment_letter_details',
+				args : {
+					template : frm.doc.appointment_letter_template
+				},
+				callback: function(r){
+					if(r.message){
+						let message_body = r.message;
+						frm.set_value("introduction", message_body[0].introduction);
+						frm.set_value("closing_notes", message_body[0].closing_notes);
+						frm.doc.terms = []
+						for (var i in message_body[1].description){
+							frm.add_child("terms");
+							frm.fields_dict.terms.get_value()[i].title = message_body[1].description[i].title;
+							frm.fields_dict.terms.get_value()[i].description = message_body[1].description[i].description;
+						}
+						frm.refresh();
+					}
+				}
+
+			});
+		}
+	},
+});
diff --git a/erpnext/hr/doctype/appointment_letter/appointment_letter.json b/erpnext/hr/doctype/appointment_letter/appointment_letter.json
new file mode 100644
index 0000000..c81b700
--- /dev/null
+++ b/erpnext/hr/doctype/appointment_letter/appointment_letter.json
@@ -0,0 +1,124 @@
+{
+ "actions": [],
+ "autoname": "HR-APP-LETTER-.#####",
+ "creation": "2019-12-26 12:35:49.574828",
+ "default_print_format": "Standard Appointment Letter",
+ "doctype": "DocType",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+  "job_applicant",
+  "applicant_name",
+  "column_break_3",
+  "company",
+  "appointment_date",
+  "appointment_letter_template",
+  "body_section",
+  "introduction",
+  "terms",
+  "closing_notes"
+ ],
+ "fields": [
+  {
+   "fetch_from": "job_applicant.applicant_name",
+   "fieldname": "applicant_name",
+   "fieldtype": "Data",
+   "in_global_search": 1,
+   "in_list_view": 1,
+   "label": "Applicant Name",
+   "read_only": 1,
+   "reqd": 1
+  },
+  {
+   "fieldname": "appointment_date",
+   "fieldtype": "Date",
+   "label": "Appointment Date",
+   "reqd": 1
+  },
+  {
+   "fieldname": "appointment_letter_template",
+   "fieldtype": "Link",
+   "label": "Appointment Letter Template",
+   "options": "Appointment Letter Template",
+   "reqd": 1
+  },
+  {
+   "fetch_from": "appointment_letter_template.introduction",
+   "fieldname": "introduction",
+   "fieldtype": "Long Text",
+   "label": "Introduction",
+   "reqd": 1
+  },
+  {
+   "fieldname": "body_section",
+   "fieldtype": "Section Break",
+   "label": "Body"
+  },
+  {
+   "fieldname": "column_break_3",
+   "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "job_applicant",
+   "fieldtype": "Link",
+   "label": "Job Applicant",
+   "options": "Job Applicant",
+   "reqd": 1
+  },
+  {
+   "fieldname": "company",
+   "fieldtype": "Link",
+   "label": "Company",
+   "options": "Company",
+   "reqd": 1
+  },
+  {
+   "fieldname": "closing_notes",
+   "fieldtype": "Text",
+   "label": "Closing Notes"
+  },
+  {
+   "fieldname": "terms",
+   "fieldtype": "Table",
+   "label": "Terms",
+   "options": "Appointment Letter content",
+   "reqd": 1
+  }
+ ],
+ "links": [],
+ "modified": "2020-01-21 17:30:36.334395",
+ "modified_by": "Administrator",
+ "module": "HR",
+ "name": "Appointment Letter",
+ "name_case": "Title Case",
+ "owner": "Administrator",
+ "permissions": [
+  {
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "System Manager",
+   "share": 1,
+   "write": 1
+  },
+  {
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "HR Manager",
+   "share": 1,
+   "write": 1
+  }
+ ],
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "track_changes": 1
+}
\ No newline at end of file
diff --git a/erpnext/hr/doctype/appointment_letter/appointment_letter.py b/erpnext/hr/doctype/appointment_letter/appointment_letter.py
new file mode 100644
index 0000000..85b82c5
--- /dev/null
+++ b/erpnext/hr/doctype/appointment_letter/appointment_letter.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class AppointmentLetter(Document):
+	pass
+
+@frappe.whitelist()
+def get_appointment_letter_details(template):
+	body = []
+	intro= frappe.get_list("Appointment Letter Template",
+		fields = ['introduction', 'closing_notes'],
+		filters={'name': template
+	})[0]
+	content = frappe.get_list("Appointment Letter content",
+		fields = ['title', 'description'],
+		filters={'parent': template
+	})
+	body.append(intro)
+	body.append({'description': content})
+	return body
diff --git a/erpnext/hr/doctype/appointment_letter/test_appointment_letter.py b/erpnext/hr/doctype/appointment_letter/test_appointment_letter.py
new file mode 100644
index 0000000..b9ce981
--- /dev/null
+++ b/erpnext/hr/doctype/appointment_letter/test_appointment_letter.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
+# See license.txt
+from __future__ import unicode_literals
+
+# import frappe
+import unittest
+
+class TestAppointmentLetter(unittest.TestCase):
+	pass
diff --git a/erpnext/hr/doctype/appointment_letter_content/__init__.py b/erpnext/hr/doctype/appointment_letter_content/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/hr/doctype/appointment_letter_content/__init__.py
diff --git a/erpnext/hr/doctype/appointment_letter_content/appointment_letter_content.json b/erpnext/hr/doctype/appointment_letter_content/appointment_letter_content.json
new file mode 100644
index 0000000..17a2b91
--- /dev/null
+++ b/erpnext/hr/doctype/appointment_letter_content/appointment_letter_content.json
@@ -0,0 +1,39 @@
+{
+ "actions": [],
+ "creation": "2019-12-26 12:22:16.575767",
+ "doctype": "DocType",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+  "title",
+  "description"
+ ],
+ "fields": [
+  {
+   "fieldname": "title",
+   "fieldtype": "Data",
+   "in_list_view": 1,
+   "label": "Title",
+   "reqd": 1
+  },
+  {
+   "fieldname": "description",
+   "fieldtype": "Long Text",
+   "in_list_view": 1,
+   "label": "Description",
+   "reqd": 1
+  }
+ ],
+ "istable": 1,
+ "links": [],
+ "modified": "2019-12-26 12:24:09.824084",
+ "modified_by": "Administrator",
+ "module": "HR",
+ "name": "Appointment Letter content",
+ "owner": "Administrator",
+ "permissions": [],
+ "quick_entry": 1,
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "track_changes": 1
+}
\ No newline at end of file
diff --git a/erpnext/hr/doctype/appointment_letter_content/appointment_letter_content.py b/erpnext/hr/doctype/appointment_letter_content/appointment_letter_content.py
new file mode 100644
index 0000000..a1a49e5
--- /dev/null
+++ b/erpnext/hr/doctype/appointment_letter_content/appointment_letter_content.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+# import frappe
+from frappe.model.document import Document
+
+class AppointmentLettercontent(Document):
+	pass
diff --git a/erpnext/hr/doctype/appointment_letter_template/__init__.py b/erpnext/hr/doctype/appointment_letter_template/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/hr/doctype/appointment_letter_template/__init__.py
diff --git a/erpnext/hr/doctype/appointment_letter_template/appointment_letter_template.js b/erpnext/hr/doctype/appointment_letter_template/appointment_letter_template.js
new file mode 100644
index 0000000..8270f7a
--- /dev/null
+++ b/erpnext/hr/doctype/appointment_letter_template/appointment_letter_template.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Appointment Letter Template', {
+	// refresh: function(frm) {
+
+	// }
+});
diff --git a/erpnext/hr/doctype/appointment_letter_template/appointment_letter_template.json b/erpnext/hr/doctype/appointment_letter_template/appointment_letter_template.json
new file mode 100644
index 0000000..c136fb2
--- /dev/null
+++ b/erpnext/hr/doctype/appointment_letter_template/appointment_letter_template.json
@@ -0,0 +1,69 @@
+{
+ "actions": [],
+ "autoname": "HR-APP-LETTER-TEMP-.#####",
+ "creation": "2019-12-26 12:20:14.219578",
+ "doctype": "DocType",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+  "introduction",
+  "terms",
+  "closing_notes"
+ ],
+ "fields": [
+  {
+   "fieldname": "introduction",
+   "fieldtype": "Long Text",
+   "in_list_view": 1,
+   "label": "Introduction",
+   "reqd": 1
+  },
+  {
+   "fieldname": "closing_notes",
+   "fieldtype": "Text",
+   "label": "Closing Notes"
+  },
+  {
+   "fieldname": "terms",
+   "fieldtype": "Table",
+   "label": "Terms",
+   "options": "Appointment Letter content",
+   "reqd": 1
+  }
+ ],
+ "links": [],
+ "modified": "2020-01-21 17:00:46.779420",
+ "modified_by": "Administrator",
+ "module": "HR",
+ "name": "Appointment Letter Template",
+ "owner": "Administrator",
+ "permissions": [
+  {
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "System Manager",
+   "share": 1,
+   "write": 1
+  },
+  {
+   "create": 1,
+   "delete": 1,
+   "email": 1,
+   "export": 1,
+   "print": 1,
+   "read": 1,
+   "report": 1,
+   "role": "HR Manager",
+   "share": 1,
+   "write": 1
+  }
+ ],
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "track_changes": 1
+}
\ No newline at end of file
diff --git a/erpnext/hr/doctype/appointment_letter_template/appointment_letter_template.py b/erpnext/hr/doctype/appointment_letter_template/appointment_letter_template.py
new file mode 100644
index 0000000..c23881f
--- /dev/null
+++ b/erpnext/hr/doctype/appointment_letter_template/appointment_letter_template.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+# import frappe
+from frappe.model.document import Document
+
+class AppointmentLetterTemplate(Document):
+	pass
diff --git a/erpnext/hr/doctype/appointment_letter_template/test_appointment_letter_template.py b/erpnext/hr/doctype/appointment_letter_template/test_appointment_letter_template.py
new file mode 100644
index 0000000..3d061ac
--- /dev/null
+++ b/erpnext/hr/doctype/appointment_letter_template/test_appointment_letter_template.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
+# See license.txt
+from __future__ import unicode_literals
+
+# import frappe
+import unittest
+
+class TestAppointmentLetterTemplate(unittest.TestCase):
+	pass
diff --git a/erpnext/hr/print_format/standard_appointment_letter/__init__.py b/erpnext/hr/print_format/standard_appointment_letter/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/hr/print_format/standard_appointment_letter/__init__.py
diff --git a/erpnext/hr/print_format/standard_appointment_letter/standard_appointment_letter.html b/erpnext/hr/print_format/standard_appointment_letter/standard_appointment_letter.html
new file mode 100644
index 0000000..d60582e
--- /dev/null
+++ b/erpnext/hr/print_format/standard_appointment_letter/standard_appointment_letter.html
@@ -0,0 +1,38 @@
+{%- from "templates/print_formats/standard_macros.html" import add_header -%}
+
+<div class="text-center" style="margin-bottom: 10%;"><h3>Appointment Letter</h3></div>
+<div class ='row' style="margin-bottom: 5%;">
+    <div class = "col-sm-6">
+        <b>{{ doc.applicant_name }},</b>
+    </div>
+    <div class="col-sm-6">
+        <span style = "float: right;"><b> Date: </b>{{ doc.appointment_date }}</span>
+    </div>
+</div>
+<div style="margin-bottom: 5%;">
+    {{ doc.introduction }}
+</div>
+<div style="margin-bottom: 5%;">
+    <ul>
+    {% for content in doc.terms %}
+        <li style="padding-bottom: 3%;">
+            <span>
+                <span><b>{{ content.title }}: </b></span> {{ content.description }}
+            </span>
+        </li>
+    {% endfor %}
+    </ul>
+</div>
+<div style="margin-bottom: 5%;">
+<span>Your sincerely,</span><br>
+<span><b>For {{ doc.company }}</b></span>
+</div>
+
+<div style="margin-bottom: 5%;">
+    <span>{{ doc.closing_notes }}</span>
+</div>
+
+<div>
+    <span><b>________________</b></span><br>
+    <span><b>{{ doc.applicant_name }}</b></span>
+</div>
\ No newline at end of file
diff --git a/erpnext/hr/print_format/standard_appointment_letter/standard_appointment_letter.json b/erpnext/hr/print_format/standard_appointment_letter/standard_appointment_letter.json
new file mode 100644
index 0000000..1813e71
--- /dev/null
+++ b/erpnext/hr/print_format/standard_appointment_letter/standard_appointment_letter.json
@@ -0,0 +1,23 @@
+{
+ "align_labels_right": 0,
+ "creation": "2019-12-26 15:22:44.200332",
+ "custom_format": 0,
+ "default_print_language": "en",
+ "disabled": 0,
+ "doc_type": "Appointment Letter",
+ "docstatus": 0,
+ "doctype": "Print Format",
+ "font": "Default",
+ "idx": 0,
+ "line_breaks": 0,
+ "modified": "2020-01-21 17:24:16.705082",
+ "modified_by": "Administrator",
+ "module": "HR",
+ "name": "Standard Appointment Letter",
+ "owner": "Administrator",
+ "print_format_builder": 0,
+ "print_format_type": "Jinja",
+ "raw_printing": 0,
+ "show_section_headings": 0,
+ "standard": "Yes"
+}
\ No newline at end of file