feat: company-driven letter head and Thai address template
- Letter Head fixture renders company details (logo, name, tax id, address, phone, email) from the printed document's company via a jinja helper instead of hardcoded values; falls back to the default company for doctypes without a company field. - Register fixtures in hooks (Letter Head, Address Template); they were never imported before. - Preserve the fixture's `source = HTML` on import: LetterHead.before_insert forces "Image" and fixture import is delete + insert. - Thailand Address Template: two-line address, phone/fax/email lines kept.
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"country": "Thailand",
|
||||||
|
"docstatus": 0,
|
||||||
|
"doctype": "Address Template",
|
||||||
|
"is_default": 1,
|
||||||
|
"modified": "2026-09-09 17:23:33.559202",
|
||||||
|
"name": "Thailand",
|
||||||
|
"template": "{{ address_line1 }}{% if address_line2 %} {{ address_line2 }}{% endif %}<br>\n{% if county %}{{ county }} {% endif -%}{{ city }}{% if state %} {{ state }}{% endif -%}{% if pincode %} {{ pincode }}{% endif -%}{% if country != \"Thailand\" %} {{ country }}{% endif %}<br>\n{% if phone or fax or email_id %}<br>{% endif -%}\n{% if phone %}{{ _(\"Phone\") }}: {{ phone }}<br>{% endif -%}\n{% if fax %}{{ _(\"Fax\") }}: {{ fax }}<br>{% endif -%}\n{% if email_id %}{{ _(\"Email\") }}: {{ email_id }}<br>{% endif -%}\n"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"align": "Left",
|
"align": "Left",
|
||||||
"content": "<style>\n .bpt-title{\n display: -webkit-box !important;\n -webkit-box-align: center !important; \n -webkit-box-pack: justify !important;\n }\n</style>\n<div class=\"bpt-title\">\n <img alt=\"Poysound\" height=\"125\" src=\"/private/files/Logo%20Poy%20Sound-02.png\">\n <div class=\"text-right\" style=\"width: 500px; margin-right: 1px;\">\n <h1>\n Poysound Co., Ltd.\n </h1>\n <small style=\"\">\n <div>ID: 0505569007038</div>\n <div>เลขที่ 58/1 ซอย 1 ถนนราชเชียงแสน ตำบลหายยา</div>\n <div>อำเภอเมือง จังหวัดเชียงใหม่ 50100</div>\n <div>Phone: 098-614-5144</div>\n <div>Email: record@poyfestival.com</div>\n </small>\n </div>\n \n</div>",
|
"content": "<style>\n .bpt-title{\n display: -webkit-box !important;\n -webkit-box-align: center !important;\n -webkit-box-pack: justify !important;\n }\n</style>\n{% set company = get_letter_head_company(doc) %}\n{% if company %}\n<div class=\"bpt-title\">\n {% if company.company_logo %}\n <img alt=\"{{ company.company_name }}\" height=\"125\" src=\"{{ company.company_logo }}\">\n {% endif %}\n <div class=\"text-right\" style=\"width: 500px; margin-right: 1px;\">\n <h1>{{ company.company_name }}</h1>\n <small>\n {% if company.tax_id %}<div>ID: {{ company.tax_id }}</div>{% endif %}\n {% if company.address %}<div>{{ company.address }}</div>{% endif %}\n {% if company.phone_no %}<div>Phone: {{ company.phone_no }}</div>{% endif %}\n {% if company.email %}<div>Email: {{ company.email }}</div>{% endif %}\n </small>\n </div>\n</div>\n{% endif %}\n",
|
||||||
"disabled": 0,
|
"disabled": 0,
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"doctype": "Letter Head",
|
"doctype": "Letter Head",
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
"image_width": 0.0,
|
"image_width": 0.0,
|
||||||
"is_default": 1,
|
"is_default": 1,
|
||||||
"letter_head_name": "Default Letter Head",
|
"letter_head_name": "Default Letter Head",
|
||||||
"modified": "2026-09-04 21:09:13.657598",
|
"modified": "2026-09-09 17:12:12.886614",
|
||||||
"name": "Default Letter Head",
|
"name": "Default Letter Head",
|
||||||
"source": "HTML"
|
"source": "HTML"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ app_license = "gpl-3.0"
|
|||||||
# Apps
|
# Apps
|
||||||
# ------------------
|
# ------------------
|
||||||
|
|
||||||
# required_apps = []
|
required_apps = ["erpnext"]
|
||||||
|
|
||||||
# Each item in the list will be shown as an app in the apps page
|
# Each item in the list will be shown as an app in the apps page
|
||||||
# add_to_apps_screen = [
|
# add_to_apps_screen = [
|
||||||
@@ -74,10 +74,17 @@ app_license = "gpl-3.0"
|
|||||||
# ----------
|
# ----------
|
||||||
|
|
||||||
# add methods and filters to jinja environment
|
# add methods and filters to jinja environment
|
||||||
# jinja = {
|
jinja = {
|
||||||
# "methods": "default_thai_company.utils.jinja_methods",
|
"methods": ["default_thai_company.utils.get_letter_head_company"],
|
||||||
# "filters": "default_thai_company.utils.jinja_filters"
|
}
|
||||||
# }
|
|
||||||
|
# Fixtures
|
||||||
|
# --------
|
||||||
|
|
||||||
|
fixtures = [
|
||||||
|
{"doctype": "Letter Head", "filters": [["name", "in", ["Default Letter Head"]]]},
|
||||||
|
{"doctype": "Address Template", "filters": [["name", "in", ["Thailand"]]]},
|
||||||
|
]
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
# ------------
|
# ------------
|
||||||
@@ -137,13 +144,12 @@ app_license = "gpl-3.0"
|
|||||||
# ---------------
|
# ---------------
|
||||||
# Hook on document methods and events
|
# Hook on document methods and events
|
||||||
|
|
||||||
# doc_events = {
|
doc_events = {
|
||||||
# "*": {
|
"Letter Head": {
|
||||||
# "on_update": "method",
|
"before_import": "default_thai_company.utils.stash_letter_head_source",
|
||||||
# "on_cancel": "method",
|
"before_insert": "default_thai_company.utils.restore_letter_head_source",
|
||||||
# "on_trash": "method"
|
}
|
||||||
# }
|
}
|
||||||
# }
|
|
||||||
|
|
||||||
# Scheduled Tasks
|
# Scheduled Tasks
|
||||||
# ---------------
|
# ---------------
|
||||||
@@ -246,4 +252,3 @@ app_license = "gpl-3.0"
|
|||||||
# ------------
|
# ------------
|
||||||
# List of apps whose translatable strings should be excluded from this app's translations.
|
# List of apps whose translatable strings should be excluded from this app's translations.
|
||||||
# ignore_translatable_strings_from = []
|
# ignore_translatable_strings_from = []
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import frappe
|
||||||
|
from erpnext import get_default_company
|
||||||
|
from frappe.contacts.doctype.address.address import get_default_address, render_address
|
||||||
|
|
||||||
|
|
||||||
|
def get_letter_head_company(doc=None):
|
||||||
|
"""Company details for the Letter Head template.
|
||||||
|
|
||||||
|
Resolves the company from the printed document's `company` field, falling
|
||||||
|
back to the user's/global default company for documents without one.
|
||||||
|
Returns None when no company can be resolved.
|
||||||
|
"""
|
||||||
|
company_name = (doc.get("company") if doc else None) or get_default_company()
|
||||||
|
if not company_name or not frappe.db.exists("Company", company_name):
|
||||||
|
return None
|
||||||
|
|
||||||
|
company = frappe.get_cached_doc("Company", company_name)
|
||||||
|
address_name = get_default_address("Company", company_name)
|
||||||
|
|
||||||
|
return frappe._dict(
|
||||||
|
name=company.name,
|
||||||
|
company_name=company.company_name,
|
||||||
|
tax_id=company.tax_id,
|
||||||
|
phone_no=company.phone_no,
|
||||||
|
email=company.email,
|
||||||
|
website=company.website,
|
||||||
|
company_logo=company.company_logo,
|
||||||
|
address=render_address(address_name, check_permissions=False) if address_name else None,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def stash_letter_head_source(doc, method=None):
|
||||||
|
"""Fixture import re-inserts the Letter Head; remember the fixture's `source`."""
|
||||||
|
doc.flags.fixture_source = doc.source
|
||||||
|
|
||||||
|
|
||||||
|
def restore_letter_head_source(doc, method=None):
|
||||||
|
"""LetterHead.before_insert forces `source = "Image"`; restore the fixture's value."""
|
||||||
|
if doc.flags.fixture_source:
|
||||||
|
doc.source = doc.flags.fixture_source
|
||||||
Reference in New Issue
Block a user