refactor: create_letter_head for readability

This commit is contained in:
khushi8112
2025-09-25 13:13:37 +05:30
parent 4aa31d6d58
commit fe8e834b68

View File

@@ -284,34 +284,26 @@ def update_pegged_currencies():
def create_letter_head(): def create_letter_head():
base_path = frappe.get_app_path("erpnext", "accounts", "letterhead") base_path = frappe.get_app_path("erpnext", "accounts", "letterhead")
letterhead_with_background_colour = frappe.read_file(
os.path.join(base_path, "letterhead_with_background_colour.html")
)
letterhead_plain = frappe.read_file(os.path.join(base_path, "letterhead_plain.html"))
if not frappe.db.exists("Letter Head", "Letterhead with background colour"): letterheads = {
doc = frappe.get_doc( "Letterhead with background colour": "letterhead_with_background_colour.html",
{ "Letterhead Plain": "letterhead_plain.html",
"doctype": "Letter Head", }
"letter_head_name": "Letterhead with background colour",
"source": "HTML",
"content": letterhead_with_background_colour,
}
)
doc.insert(ignore_permissions=True)
frappe.db.commit()
if not frappe.db.exists("Letter Head", "Letterhead Plain"): for name, filename in letterheads.items():
doc = frappe.get_doc( if not frappe.db.exists("Letter Head", name):
{ content = frappe.read_file(os.path.join(base_path, filename))
"doctype": "Letter Head", doc = frappe.get_doc(
"letter_head_name": "Letterhead plain", {
"source": "HTML", "doctype": "Letter Head",
"content": letterhead_plain, "letter_head_name": name,
} "source": "HTML",
) "content": content,
doc.insert(ignore_permissions=True) }
frappe.db.commit() )
doc.insert(ignore_permissions=True)
frappe.db.commit()
DEFAULT_ROLE_PROFILES = { DEFAULT_ROLE_PROFILES = {