Skip to content

Commit

Permalink
feat: add info to referenced docs on submit and cancel
Browse files Browse the repository at this point in the history
(cherry picked from commit b147151)
  • Loading branch information
scdanieli authored and mergify[bot] committed Mar 12, 2024
1 parent fb3dbe0 commit 9f2940b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
{
"fieldname": "link_title",
"fieldtype": "Data",
"label": "Link Title"
"label": "Link Title",
"read_only": 1
},
{
"fieldname": "link_name",
Expand Down Expand Up @@ -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",
Expand All @@ -161,7 +162,9 @@
"write": 1
}
],
"show_title_field_in_link": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": []
"states": [],
"title_field": "subject_preview"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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
Expand All @@ -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: <a href='/app/business-letter/{0}'><strong>{1}</strong></a>"
).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: <a href='/app/business-letter/{0}'><strong>{1}</strong></a>"
).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")
Expand Down

0 comments on commit 9f2940b

Please sign in to comment.