Skip to content

feat: add optional PDF Button for Sales and Purchase Doctypes (backport #75)#80

Merged
barredterra merged 3 commits into
version-15from
mergify/bp/version-15/pr-75
Jun 12, 2026
Merged

feat: add optional PDF Button for Sales and Purchase Doctypes (backport #75)#80
barredterra merged 3 commits into
version-15from
mergify/bp/version-15/pr-75

Conversation

@mergify

@mergify mergify Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Usecase:

PDF on Submit tries to minimize the clicks needed to create and attach a PDF. In most cases users want to see the PDF as a form of Preview before submission though. Since the PDF On Submit Settings allow now multiple prints with filters and differ from the ERPNext default print it can become cumbersome for the User to go to "Print -> Select the correct format and letterhead -> Press PDF Button"

Solution:

Optionally add a simple "PDF" Button for all enabled Doctypes

Features of the Button:

  • Fetches first Print Format in PDF on Submit settings that matches, or falls back to ERPNext Default Format in case filters don't match any format
  • Opens a popup with the print, similar to PDF Button in print preview
  • Add a Checkbox in PDF On Submit Settings to toggle the feature
  • Check Print Permissions

PDF on Submit Settings:
image

Button in Form:
image

Tested

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: barredterra <14891507+barredterra@users.noreply.github.com>
(cherry picked from commit 114c2d1)

# Conflicts:
#	pdf_on_submit/locale/de.po
#	pdf_on_submit/locale/main.pot
#	pdf_on_submit/pdf_on_submit/doctype/pdf_on_submit_settings/pdf_on_submit_settings.json
@mergify mergify Bot added the conflicts label Jun 12, 2026
@mergify

This comment was marked as resolved.

@greptile-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — all conflict markers from a previous revision are resolved, the permission guard on the new API endpoint is correct, and the JS popup flow works correctly for the happy path.

The change is well-structured: a shared generator is extracted cleanly, the boot-info hook is straightforward, and the permission checks on the new endpoint are adequate. The one notable edge case — a misleading error dialog when the user closes the blank popup tab before the XHR returns — is a minor UX issue that does not affect data integrity or security.

pdf_on_submit/public/js/pdf_button_utils.js — the popup-closed race condition noted in the inline comment is worth a quick fix before ship.

Sequence Diagram

sequenceDiagram
    participant U as User (Browser)
    participant JS as pdf_button_utils.js
    participant FrappeUI as Frappe Form
    participant API as /api/method/get_print_details
    participant PY as utils.py
    participant Settings as PDF on Submit Settings
    participant PdfAPI as /api/method/download_pdf

    Note over U,JS: App boot
    JS->>JS: Read frappe.boot.pdf_on_submit
    JS->>FrappeUI: Register refresh handler for each enabled_doctype

    Note over U,FrappeUI: User opens a form
    FrappeUI->>JS: refresh event
    JS->>JS: Check frm.is_new() and frm.has_perm(print)
    JS->>FrappeUI: frm.page.add_button(PDF)

    Note over U,PdfAPI: User clicks PDF button
    U->>JS: click
    JS->>U: window.open("", "_blank") popup
    JS->>API: POST get_print_details(doctype, docname)
    API->>PY: get_print_details()
    PY->>PY: frappe.has_permission(doctype, print, docname)
    PY->>Settings: frappe.get_single()
    PY->>PY: iter_matching_enabled_doctypes(doc, settings)
    PY-->>API: "[{print_format, letter_head}, ...]"
    API-->>JS: matches[]
    JS->>popup: "popup.location.href = build_pdf_url(frm, first)"
    popup->>PdfAPI: "GET download_pdf?doctype=...&format=..."
    PdfAPI-->>popup: PDF bytes
    alt multiple matches
        JS->>U: frappe.msgprint with links to additional formats
    end
Loading

Reviews (2): Last reviewed commit: "chore: resolve conflicts" | Re-trigger Greptile

Comment thread pdf_on_submit/locale/de.po Outdated
Comment thread pdf_on_submit/public/js/pdf_button_utils.js
@barredterra barredterra self-assigned this Jun 12, 2026
@barredterra

Copy link
Copy Markdown
Member

@greptileai

@barredterra barredterra merged commit 659cfe2 into version-15 Jun 12, 2026
7 checks passed
@barredterra barredterra deleted the mergify/bp/version-15/pr-75 branch June 12, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants