From 4f37ba9cfedf52973b0f91e7fc27ced7d556e9dc Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 14 Feb 2023 19:34:36 +0100 Subject: [PATCH 1/3] fix: change parameter name for letter head To match changes from https://github.com/frappe/frappe/pull/19627 (cherry picked from commit f7fd30fecfb2cb570cf212d011dee5f1fcb13cf0) --- .../doctype/request_for_quotation/request_for_quotation.js | 2 +- .../doctype/request_for_quotation/request_for_quotation.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js index a9f5afb2e98..7f8dd56f51d 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js @@ -129,7 +129,7 @@ frappe.ui.form.on("Request for Quotation",{ supplier: data.supplier, print_format: data.print_format || "Standard", language: data.language || frappe.boot.lang, - letter_head: data.letter_head || frm.doc.letter_head || "", + letterhead: data.letter_head || frm.doc.letter_head || "", }).toString() ) ); diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py index 8e9ded98421..332705e9339 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py @@ -388,7 +388,7 @@ def create_rfq_items(sq_doc, supplier, data): @frappe.whitelist() -def get_pdf(doctype, name, supplier, print_format=None, language=None, letter_head=None): +def get_pdf(doctype, name, supplier, print_format=None, language=None, letterhead=None): # permissions get checked in `download_pdf` if doc := get_rfq_doc(doctype, name, supplier): download_pdf( @@ -397,7 +397,7 @@ def get_pdf(doctype, name, supplier, print_format=None, language=None, letter_he print_format, doc=doc, language=language, - letter_head=letter_head or None, + letterhead=letterhead or None, ) From 1e2611fb1edac4cf6d9009674f5ad8400ef1705f Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 14 Feb 2023 19:53:03 +0100 Subject: [PATCH 2/3] refactor: download RFQ PDF (cherry picked from commit 8e40c04494930c20b37bc48212639326e8f3857f) --- .../request_for_quotation.js | 1 - .../request_for_quotation.py | 35 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js index 7f8dd56f51d..2f0b7862a82 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js @@ -124,7 +124,6 @@ frappe.ui.form.on("Request for Quotation",{ frappe.urllib.get_full_url( "/api/method/erpnext.buying.doctype.request_for_quotation.request_for_quotation.get_pdf?" + new URLSearchParams({ - doctype: frm.doc.doctype, name: frm.doc.name, supplier: data.supplier, print_format: data.print_format || "Standard", diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py index 332705e9339..7927beb8233 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py @@ -3,6 +3,7 @@ import json +from typing import Optional import frappe from frappe import _ @@ -388,24 +389,26 @@ def create_rfq_items(sq_doc, supplier, data): @frappe.whitelist() -def get_pdf(doctype, name, supplier, print_format=None, language=None, letterhead=None): - # permissions get checked in `download_pdf` - if doc := get_rfq_doc(doctype, name, supplier): - download_pdf( - doctype, - name, - print_format, - doc=doc, - language=language, - letterhead=letterhead or None, - ) - - -def get_rfq_doc(doctype, name, supplier): +def get_pdf( + name: str, + supplier: str, + print_format: Optional[str] = None, + language: Optional[str] = None, + letterhead: Optional[str] = None, +): + doc = frappe.get_doc("Request for Quotation", name) if supplier: - doc = frappe.get_doc(doctype, name) doc.update_supplier_part_no(supplier) - return doc + + # permissions get checked in `download_pdf` + download_pdf( + doc.doctype, + doc.name, + print_format, + doc=doc, + language=language, + letterhead=letterhead or None, + ) @frappe.whitelist() From bb174f931db4fea93984f6083a2d4de15030f150 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Tue, 14 Feb 2023 19:53:39 +0100 Subject: [PATCH 3/3] test: download RFQ PDF (cherry picked from commit d5b7f2e49e5d8c88d72815ff702823a86f2587de) --- .../request_for_quotation/test_request_for_quotation.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py index 064b806e953..d250e6f18a9 100644 --- a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py @@ -8,6 +8,7 @@ from frappe.utils import nowdate from erpnext.buying.doctype.request_for_quotation.request_for_quotation import ( create_supplier_quotation, + get_pdf, make_supplier_quotation_from_rfq, ) from erpnext.crm.doctype.opportunity.opportunity import make_request_for_quotation as make_rfq @@ -124,6 +125,11 @@ class TestRequestforQuotation(FrappeTestCase): rfq.status = "Draft" rfq.submit() + def test_get_pdf(self): + rfq = make_request_for_quotation() + get_pdf(rfq.name, rfq.get("suppliers")[0].supplier) + self.assertEqual(frappe.local.response.type, "pdf") + def make_request_for_quotation(**args): """