Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions pdf_on_submit/attach_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,32 @@
from frappe.utils.weasyprint import PrintFormatGenerator


def attach_pdf(doc, event=None):
settings = frappe.get_single("PDF on Submit Settings")
enabled_doctypes = settings.get("enabled_for", {"document_type": doc.doctype})
def iter_matching_enabled_doctypes(doc, settings=None):
"""
Yield enabled_doctype configuration rows whose filters match this document,
in table order (idx).
"""
if settings is None:
settings = frappe.get_single("PDF on Submit Settings")

if not enabled_doctypes:
if not settings.enabled_for:
return

for dt_settings in enabled_doctypes:
process_enabled_doctype(doc, dt_settings, settings.create_pdf_in_background)
for row in settings.get("enabled_for", {"document_type": doc.doctype}):
if row.filters:
filters = json.loads(row.filters)
if filters and not evaluate_filters(doc, filters):
continue
yield row


def process_enabled_doctype(doc, settings, in_background):
if settings.filters:
filters = json.loads(settings.filters)
if filters:
condition_met = evaluate_filters(doc, filters)
if not condition_met:
return
def attach_pdf(doc, event=None):
settings = frappe.get_single("PDF on Submit Settings")
for row in iter_matching_enabled_doctypes(doc, settings):
process_enabled_doctype(doc, row, settings.create_pdf_in_background)


def process_enabled_doctype(doc, settings, in_background):
auto_name = settings.auto_name
print_format = settings.print_format or doc.meta.default_print_format or "Standard"
letter_head = settings.letter_head or None
Expand Down
4 changes: 2 additions & 2 deletions pdf_on_submit/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

# include js, css files in header of desk.html
# app_include_css = "/assets/pdf_on_submit/css/pdf_on_submit.css"
# app_include_js = "/assets/pdf_on_submit/js/pdf_on_submit.js"
app_include_js = "/assets/pdf_on_submit/js/pdf_button_utils.js"
extend_bootinfo = "pdf_on_submit.utils.extend_boot_info"

# include js, css files in header of web template
# web_include_css = "/assets/pdf_on_submit/css/pdf_on_submit.css"
# web_include_js = "/assets/pdf_on_submit/js/pdf_on_submit.js"

# include js in page
# page_js = {"page" : "public/js/file.js"}

# include js in doctype views
# doctype_js = {"doctype" : "public/js/doctype.js"}
# doctype_list_js = {"doctype" : "public/js/doctype_list.js"}
Expand Down
58 changes: 43 additions & 15 deletions pdf_on_submit/locale/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PDF on Submit VERSION\n"
"Report-Msgid-Bugs-To: hallo@alyf.de\n"
"POT-Creation-Date: 2026-04-14 22:05+0053\n"
"POT-Creation-Date: 2026-06-12 12:27+0053\n"
"PO-Revision-Date: 2024-07-20 23:34+0053\n"
"Last-Translator: hallo@alyf.de\n"
"Language-Team: hallo@alyf.de\n"
Expand All @@ -16,6 +16,10 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.13.1\n"

#: pdf_on_submit/public/js/pdf_button_utils.js:73
msgid "Additional print formats"
msgstr "Weitere Druckformate"

#. Label of a Select field in DocType 'Enabled DocType'
#: pdf_on_submit/pdf_on_submit/doctype/enabled_doctype/enabled_doctype.json
msgid "Attach To Field"
Expand All @@ -26,10 +30,16 @@ msgstr "An Feld anhängen"
msgid "Create PDF In Background"
msgstr "PDF im Hintergrund erstellen"

#: pdf_on_submit/attach_pdf.py:90
#: pdf_on_submit/attach_pdf.py:97
msgid "Creating PDF ..."
msgstr "Erstelle PDF ..."

#. Description of the 'Show PDF Button' (Check) field in DocType 'PDF on Submit
#. Settings'
#: pdf_on_submit/pdf_on_submit/doctype/pdf_on_submit_settings/pdf_on_submit_settings.json
msgid "Displays a PDF button on the Form View for each enabled DocType."
msgstr "Zeigt eine PDF-Schaltfläche in der Formularansicht für jeden aktivierten Dokumenttyp an."

#. Name of a DocType
#: pdf_on_submit/pdf_on_submit/doctype/enabled_doctype/enabled_doctype.json
msgid "Enabled DocType"
Expand All @@ -40,10 +50,14 @@ msgstr "Aktivierter Dokumenttyp"
msgid "Enabled For"
msgstr "Aktiviert für"

#: pdf_on_submit/attach_pdf.py:117
#: pdf_on_submit/attach_pdf.py:124
msgid "Failed to attach XML to PDF for Sales Invoice {0}"
msgstr "Fehler beim Anhängen von XML an PDF für Verkaufsrechnung {0}"

#: pdf_on_submit/public/js/pdf_button_utils.js:85
msgid "Failed to generate PDF. {0}"
msgstr "PDF-Erstellung fehlgeschlagen. {0}"

#. Description of the 'Attach To Field' (Select) field in DocType 'Enabled
#. DocType'
#: pdf_on_submit/pdf_on_submit/doctype/enabled_doctype/enabled_doctype.json
Expand All @@ -53,12 +67,12 @@ msgid ""
msgstr ""

#: pdf_on_submit/pdf_on_submit/doctype/pdf_on_submit_settings/pdf_on_submit_settings.py:45
msgid ""
"It is not allowed to set the attach field {0} in the DocType {1} multiple "
"times."
msgstr ""
"Es ist nicht erlaubt, das Anhang-Feld {0} im DocType {1} mehrfach "
"festzulegen."
msgid "It is not allowed to set the attach field {0} in the DocType {1} multiple times."
msgstr "Es ist nicht erlaubt, das Anhang-Feld {0} im DocType {1} mehrfach festzulegen."

#: pdf_on_submit/public/js/pdf_button_utils.js:75
msgid "More formats are configured for this document. Click to open:"
msgstr "Für dieses Dokument sind weitere Formate konfiguriert. Zum Öffnen anklicken:"

#. Description of the 'Auto Name' (Data) field in DocType 'Enabled DocType'
#: pdf_on_submit/pdf_on_submit/doctype/enabled_doctype/enabled_doctype.json
Expand All @@ -69,25 +83,39 @@ msgstr ""
"Optionen:\n"
"<ol><li><b>format:BEISPIEL-{MM}-{feldname1}-{feldname2}-{#####}</b> - Ersetzt alle in geschweiften Klammern stehenden Wörter (Feldnamen, Datumsangaben (DD, MM, YY), Nummernkreise) durch ihren Wert. Außerhalb der geschweiften Klammern können beliebige Zeichen verwendet werden.</li></ol>"

#: pdf_on_submit/utils.py:29
msgid "No permission to print this document"
msgstr "Keine Berechtigung zum Drucken dieses Dokuments"

#. Content of the 'filter_description' (HTML) field in DocType 'Enabled
#. DocType'
#: pdf_on_submit/pdf_on_submit/doctype/enabled_doctype/enabled_doctype.json
msgid ""
"Optional: create PDF only if the submitted document matches these "
"filters.<br><br>"
msgstr ""
"Optional: PDF nur erstellen, wenn das eingereichte Dokument diesen Filtern "
"entspricht.<br><br>"
msgid "Optional: create PDF only if the submitted document matches these filters.<br><br>"
msgstr "Optional: PDF nur erstellen, wenn das eingereichte Dokument diesen Filtern entspricht.<br><br>"

#. Name of a DocType
#: pdf_on_submit/pdf_on_submit/doctype/pdf_on_submit_settings/pdf_on_submit_settings.json
msgid "PDF on Submit Settings"
msgstr "PDF-on-Submit-Einstellungen"

#: pdf_on_submit/public/js/pdf_button_utils.js:44
msgid "Please allow popups for this site and try again."
msgstr "Bitte Popups für diese Seite erlauben und erneut versuchen."

#: pdf_on_submit/public/js/pdf_button_utils.js:42
msgid "Popup Blocked"
msgstr "Popup blockiert"

#: pdf_on_submit/pdf_on_submit/doctype/pdf_on_submit_settings/pdf_on_submit_settings.py:16
msgid "Row #{0}: invalid filters for <b>{1}</b>: {2}"
msgstr "Zeile #{0}: Ungültige Filter für <b>{1}</b>: {2}"

#. Label of a Check field in DocType 'PDF on Submit Settings'
#: pdf_on_submit/pdf_on_submit/doctype/pdf_on_submit_settings/pdf_on_submit_settings.json
msgid "Show PDF Button"
msgstr "PDF-Schaltfläche anzeigen"

#: pdf_on_submit/pdf_on_submit/doctype/pdf_on_submit_settings/pdf_on_submit_settings.py:55
msgid "{0} is not a valid field for DocType {1}."
msgstr "{0} ist kein gültiges Feld für DocType {1}."

43 changes: 39 additions & 4 deletions pdf_on_submit/locale/main.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ msgid ""
msgstr ""
"Project-Id-Version: PDF on Submit VERSION\n"
"Report-Msgid-Bugs-To: hallo@alyf.de\n"
"POT-Creation-Date: 2026-04-14 22:05+0053\n"
"PO-Revision-Date: 2026-04-14 22:05+0053\n"
"POT-Creation-Date: 2026-06-12 12:27+0053\n"
"PO-Revision-Date: 2026-06-12 12:27+0053\n"
"Last-Translator: hallo@alyf.de\n"
"Language-Team: hallo@alyf.de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.13.1\n"

#: pdf_on_submit/public/js/pdf_button_utils.js:73
msgid "Additional print formats"
msgstr ""

#. Label of a Select field in DocType 'Enabled DocType'
#: pdf_on_submit/pdf_on_submit/doctype/enabled_doctype/enabled_doctype.json
msgid "Attach To Field"
Expand All @@ -26,10 +30,16 @@ msgstr ""
msgid "Create PDF In Background"
msgstr ""

#: pdf_on_submit/attach_pdf.py:90
#: pdf_on_submit/attach_pdf.py:97
msgid "Creating PDF ..."
msgstr ""

#. Description of the 'Show PDF Button' (Check) field in DocType 'PDF on Submit
#. Settings'
#: pdf_on_submit/pdf_on_submit/doctype/pdf_on_submit_settings/pdf_on_submit_settings.json
msgid "Displays a PDF button on the Form View for each enabled DocType."
msgstr ""

#. Name of a DocType
#: pdf_on_submit/pdf_on_submit/doctype/enabled_doctype/enabled_doctype.json
msgid "Enabled DocType"
Expand All @@ -40,10 +50,14 @@ msgstr ""
msgid "Enabled For"
msgstr ""

#: pdf_on_submit/attach_pdf.py:117
#: pdf_on_submit/attach_pdf.py:124
msgid "Failed to attach XML to PDF for Sales Invoice {0}"
msgstr ""

#: pdf_on_submit/public/js/pdf_button_utils.js:85
msgid "Failed to generate PDF. {0}"
msgstr ""

#. Description of the 'Attach To Field' (Select) field in DocType 'Enabled
#. DocType'
#: pdf_on_submit/pdf_on_submit/doctype/enabled_doctype/enabled_doctype.json
Expand All @@ -56,13 +70,21 @@ msgstr ""
msgid "It is not allowed to set the attach field {0} in the DocType {1} multiple times."
msgstr ""

#: pdf_on_submit/public/js/pdf_button_utils.js:75
msgid "More formats are configured for this document. Click to open:"
msgstr ""

#. Description of the 'Auto Name' (Data) field in DocType 'Enabled DocType'
#: pdf_on_submit/pdf_on_submit/doctype/enabled_doctype/enabled_doctype.json
msgid ""
"Naming Options:\n"
"<ol><li><b>format:EXAMPLE-{MM}-{fieldname1}-{fieldname2}-{#####}</b> - Replace all braced words (fieldnames, date words (DD, MM, YY), series) with their value. Outside braces, any characters can be used.</li></ol>"
msgstr ""

#: pdf_on_submit/utils.py:29
msgid "No permission to print this document"
msgstr ""

#. Content of the 'filter_description' (HTML) field in DocType 'Enabled
#. DocType'
#: pdf_on_submit/pdf_on_submit/doctype/enabled_doctype/enabled_doctype.json
Expand All @@ -74,10 +96,23 @@ msgstr ""
msgid "PDF on Submit Settings"
msgstr ""

#: pdf_on_submit/public/js/pdf_button_utils.js:44
msgid "Please allow popups for this site and try again."
msgstr ""

#: pdf_on_submit/public/js/pdf_button_utils.js:42
msgid "Popup Blocked"
msgstr ""

#: pdf_on_submit/pdf_on_submit/doctype/pdf_on_submit_settings/pdf_on_submit_settings.py:16
msgid "Row #{0}: invalid filters for <b>{1}</b>: {2}"
msgstr ""

#. Label of a Check field in DocType 'PDF on Submit Settings'
#: pdf_on_submit/pdf_on_submit/doctype/pdf_on_submit_settings/pdf_on_submit_settings.json
msgid "Show PDF Button"
msgstr ""

#: pdf_on_submit/pdf_on_submit/doctype/pdf_on_submit_settings/pdf_on_submit_settings.py:55
msgid "{0} is not a valid field for DocType {1}."
msgstr ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"section_break_1",
"enabled_for",
"section_break_8",
"create_pdf_in_background"
"create_pdf_in_background",
"column_break_eoam",
"show_pdf_button"
],
"fields": [
{
Expand All @@ -31,12 +33,23 @@
"fieldtype": "Table",
"label": "Enabled For",
"options": "Enabled DocType"
},
{
"fieldname": "column_break_eoam",
"fieldtype": "Column Break"
},
{
"default": "0",
"description": "Displays a PDF button on the Form View for each enabled DocType.",
"fieldname": "show_pdf_button",
"fieldtype": "Check",
"label": "Show PDF Button"
}
],
"icon": "octicon octicon-file-pdf",
"issingle": 1,
"links": [],
"modified": "2021-01-13 15:44:40.308041",
"modified": "2026-05-27 09:19:52.227943",
"modified_by": "Administrator",
"module": "PDF on Submit",
"name": "PDF on Submit Settings",
Expand All @@ -62,7 +75,9 @@
}
],
"quick_entry": 1,
"sort_field": "modified",
"row_format": "Dynamic",
"sort_field": "creation",
"sort_order": "ASC",
"states": [],
"track_changes": 1
}
}
Loading
Loading