diff --git a/erpnext_germany/erpnext_germany/doctype/business_letter/business_letter.json b/erpnext_germany/erpnext_germany/doctype/business_letter/business_letter.json
index eeed443..ca44c4d 100644
--- a/erpnext_germany/erpnext_germany/doctype/business_letter/business_letter.json
+++ b/erpnext_germany/erpnext_germany/doctype/business_letter/business_letter.json
@@ -76,7 +76,8 @@
{
"fieldname": "link_title",
"fieldtype": "Data",
- "label": "Link Title"
+ "label": "Link Title",
+ "read_only": 1
},
{
"fieldname": "link_name",
@@ -141,7 +142,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
- "modified": "2024-02-05 17:35:31.350359",
+ "modified": "2024-02-05 19:07:34.724842",
"modified_by": "Administrator",
"module": "ERPNext Germany",
"name": "Business Letter",
@@ -161,7 +162,9 @@
"write": 1
}
],
+ "show_title_field_in_link": 1,
"sort_field": "modified",
"sort_order": "DESC",
- "states": []
+ "states": [],
+ "title_field": "subject_preview"
}
\ No newline at end of file
diff --git a/erpnext_germany/erpnext_germany/doctype/business_letter/business_letter.py b/erpnext_germany/erpnext_germany/doctype/business_letter/business_letter.py
index 4df7991..695c6a3 100644
--- a/erpnext_germany/erpnext_germany/doctype/business_letter/business_letter.py
+++ b/erpnext_germany/erpnext_germany/doctype/business_letter/business_letter.py
@@ -2,13 +2,16 @@
# For license information, please see license.txt
import frappe
+from frappe import _
from frappe.model.document import Document
+from frappe.desk.doctype.notification_log.notification_log import get_title
class BusinessLetter(Document):
def before_validate(self):
self.set_subject_preview()
self.set_content_preview()
+ self.set_link_title()
def set_subject_preview(self):
self.subject_preview = (
@@ -20,6 +23,12 @@ def set_content_preview(self):
frappe.render_template(self.content, self.get_context()) if self.content else " "
)
+ def set_link_title(self):
+ if self.link_name:
+ self.link_title = get_title(self.link_document_type, self.link_name)
+ else:
+ self.link_title = None
+
def get_context(self):
address = frappe.get_doc("Address", self.address) if self.address else None
contact = frappe.get_doc("Contact", self.contact) if self.contact else None
@@ -33,6 +42,40 @@ def get_context(self):
"reference": reference,
}
+ def on_submit(self):
+ self.add_submit_comments()
+
+ def on_cancel(self):
+ self.add_cancel_comments()
+
+ def add_submit_comments(self):
+ msg = _(
+ "submitted Business Letter: {1}"
+ ).format(self.name, self.subject_preview)
+
+ if self.contact:
+ frappe.get_doc("Contact", self.contact).add_comment("Info", msg)
+
+ if self.address:
+ frappe.get_doc("Address", self.address).add_comment("Info", msg)
+
+ if self.link_name:
+ frappe.get_doc(self.link_document_type, self.link_name).add_comment("Info", msg)
+
+ def add_cancel_comments(self):
+ msg = _(
+ "canceled Business Letter: {1}"
+ ).format(self.name, self.subject_preview)
+
+ if self.contact:
+ frappe.get_doc("Contact", self.contact).add_comment("Info", msg)
+
+ if self.address:
+ frappe.get_doc("Address", self.address).add_comment("Info", msg)
+
+ if self.link_name:
+ frappe.get_doc(self.link_document_type, self.link_name).add_comment("Info", msg)
+
@frappe.whitelist()
def get_template(self):
subject = frappe.get_value("Business Letter Template", self.template, "subject")