Skip to content
2 changes: 2 additions & 0 deletions erpnext/utilities/doctype/letter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
132 changes: 132 additions & 0 deletions erpnext/utilities/doctype/letter/letter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt

frappe.ui.form.on("Letter", {
refresh(frm) {
// Filter for recipient address
frm.set_query("recipient_address", () => {
if (!frm.doc.recipient_type || !frm.doc.recipient) {
return { filters: { name: "" } };
}
return {
query: "frappe.contacts.doctype.address.address.address_query",
filters: {
link_doctype: frm.doc.recipient_type,
link_name: frm.doc.recipient,
},
};
});

// Filter for company address
frm.set_query("company_address", () => {
if (!frm.doc.company) {
return { filters: { name: "" } };
}
return {
query: "frappe.contacts.doctype.address.address.address_query",
filters: {
link_doctype: "Company",
link_name: frm.doc.company,
},
};
});
},

recipient(frm) {
if (frm.doc.recipient_type && frm.doc.recipient) {
frappe.call({
method: "erpnext.utilities.doctype.letter.letter.get_recipient_details",
args: {
recipient_type: frm.doc.recipient_type,
recipient: frm.doc.recipient,
},
callback: function (r) {
if (r.message) {
frm.set_value("recipient_name", r.message.recipient_name);
if (r.message.language) {
frm.set_value("language", r.message.language);
}
}
},
});
} else {
frm.set_value("recipient_name", "");
frm.set_value("language", "");
}
frm.set_value("recipient_address", "");
frm.set_value("address_display", "");
},

recipient_type(frm) {
frm.set_value("recipient", "");
frm.set_value("recipient_name", "");
frm.set_value("recipient_address", "");
frm.set_value("address_display", "");
},

recipient_address(frm) {
if (frm.doc.recipient_address) {
frappe.call({
method: "frappe.contacts.doctype.address.address.get_address_display",
args: {
address_dict: frm.doc.recipient_address,
},
callback: function (r) {
if (r.message) {
frm.set_value("address_display", r.message);
}
},
});
} else {
frm.set_value("address_display", "");
}
},

company(frm) {
frm.set_value("company_address", "");
frm.set_value("company_address_display", "");

// Set default letter head from company
erpnext.utils.set_letter_head(frm);
},

company_address(frm) {
if (frm.doc.company_address) {
frappe.call({
method: "frappe.contacts.doctype.address.address.get_address_display",
args: {
address_dict: frm.doc.company_address,
},
callback: function (r) {
if (r.message) {
frm.set_value("company_address_display", r.message);
}
},
});
} else {
frm.set_value("company_address_display", "");
}
},

letter_template(frm) {
if (frm.doc.letter_template) {
frappe.call({
method: "erpnext.utilities.doctype.letter_template.letter_template.get_letter_template",
args: {
template_name: frm.doc.letter_template,
doc: frm.doc,
},
callback: function (r) {
if (r && r.message) {
if (r.message.subject) {
frm.set_value("subject", r.message.subject);
}
if (r.message.content) {
frm.set_value("content", r.message.content);
}
}
},
});
}
},
});
211 changes: 211 additions & 0 deletions erpnext/utilities/doctype/letter/letter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "naming_series:",
"creation": "2025-12-03 20:35:18.414308",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"section_break_letter",
"naming_series",
"recipient_type",
"recipient",
"recipient_name",
"recipient_address",
"address_display",
"column_break_pmit",
"letter_type",
"date",
"company",
"company_address",
"company_address_display",
"amended_from",
"letter_details_section",
"letter_template",
"subject",
"content",
"printing_settings_section",
"letter_head",
"column_break_ksdg",
"language"
],
"fields": [
{
"fieldname": "amended_from",
"fieldtype": "Link",
"label": "Amended From",
"no_copy": 1,
"options": "Letter",
"print_hide": 1,
"read_only": 1,
"search_index": 1
},
{
"fieldname": "recipient_type",
"fieldtype": "Select",
"in_filter": 1,
"in_list_view": 1,
"label": "Recipient Type",
"options": "Customer\nSupplier\nEmployee\nShareholder\nContact",
"reqd": 1
},
{
"fieldname": "recipient_address",
"fieldtype": "Link",
"label": "Recipient Address",
"options": "Address"
},
{
"fieldname": "column_break_pmit",
"fieldtype": "Column Break"
},
{
"fieldname": "recipient",
"fieldtype": "Dynamic Link",
"in_filter": 1,
"in_list_view": 1,
"label": "Recipient",
"options": "recipient_type",
"reqd": 1
},
{
"fieldname": "recipient_name",
"fieldtype": "Data",
"label": "Recipient Name",
"read_only": 1
},
{
"fieldname": "address_display",
"fieldtype": "Text Editor",
"label": "Recipient Address Details",
"read_only": 1
},
{
"fieldname": "company",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Company",
"options": "Company",
"reqd": 1
},
{
"fieldname": "naming_series",
"fieldtype": "Select",
"label": "Series",
"no_copy": 1,
"options": "L-.YY.-",
"print_hide": 1,
"reqd": 1,
"set_only_once": 1
},
{
"fieldname": "company_address",
"fieldtype": "Link",
"label": "Company Address",
"options": "Address"
},
{
"fieldname": "company_address_display",
"fieldtype": "Text Editor",
"label": "Company Address Details",
"read_only": 1
},
{
"fieldname": "letter_type",
"fieldtype": "Link",
"in_filter": 1,
"in_list_view": 1,
"label": "Letter Type",
"options": "Letter Type",
"reqd": 1
},
{
"default": "Today",
"fieldname": "date",
"fieldtype": "Date",
"in_list_view": 1,
"label": "Date",
"reqd": 1
},
{
"fieldname": "letter_details_section",
"fieldtype": "Section Break",
"label": "Letter Details"
},
{
"fieldname": "letter_template",
"fieldtype": "Link",
"label": "Letter Template",
"link_filters": "[[\"Letter Template\",\"letter_type\",\"=\",\"eval:doc.letter_type\"]]",
"options": "Letter Template"
},
{
"fieldname": "subject",
"fieldtype": "Data",
"label": "Subject"
},
{
"fieldname": "content",
"fieldtype": "Text Editor",
"label": "Content"
},
{
"fieldname": "section_break_letter",
"fieldtype": "Section Break"
},
{
"collapsible": 1,
"fieldname": "printing_settings_section",
"fieldtype": "Section Break",
"label": "Printing Settings"
},
{
"allow_on_submit": 1,
"fieldname": "letter_head",
"fieldtype": "Link",
"label": "Letter Head",
"options": "Letter Head",
"print_hide": 1
},
{
"fieldname": "column_break_ksdg",
"fieldtype": "Column Break"
},
{
"fieldname": "language",
"fieldtype": "Data",
"label": "Print Language",
"print_hide": 1
}
],
"grid_page_length": 50,
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2025-12-03 23:40:09.332016",
"modified_by": "Administrator",
"module": "Utilities",
"name": "Letter",
"naming_rule": "By \"Naming Series\" field",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"submit": 1,
"write": 1
}
],
"row_format": "Dynamic",
"rows_threshold_for_grid_search": 20,
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
Loading