From baff8de0d36190dfd235f95767d7284455233bb6 Mon Sep 17 00:00:00 2001 From: kurogeek Date: Tue, 22 Sep 2026 03:57:40 +0000 Subject: [PATCH] fix: certificate button only on paid Purchase Invoices The certificate is issued when the tax is withheld, i.e. on payment; show the button once the submitted invoice's status is Paid. --- README.md | 2 +- .../public/js/purchase_invoice.js | 19 +++---------------- default_thai_company/translations/th.csv | 1 - 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index a544adf..b9fe9e6 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ without a Thai system font. Switch a user or the print language to `th` to use i ### Withholding tax certificate -A Purchase Invoice with *Apply Tax Withholding Amount* gets a **Withholding Tax Certificate** +A paid Purchase Invoice with *Apply Tax Withholding Amount* gets a **Withholding Tax Certificate** button that downloads the Revenue Department's Sec. 50 bis form (หนังสือรับรองการหักภาษี ณ ที่จ่าย, two copies) as a PDF: the *Withholding Tax Certificate* print format lays the invoice's data over the official form (`public/images`). The row the payment is reported on comes from diff --git a/default_thai_company/public/js/purchase_invoice.js b/default_thai_company/public/js/purchase_invoice.js index 565ac2d..1376e84 100644 --- a/default_thai_company/public/js/purchase_invoice.js +++ b/default_thai_company/public/js/purchase_invoice.js @@ -1,23 +1,10 @@ frappe.ui.form.on("Purchase Invoice", { refresh(frm) { - frm.events.toggle_withholding_certificate(frm); - }, - - apply_tds(frm) { - frm.events.toggle_withholding_certificate(frm); - }, - - toggle_withholding_certificate(frm) { - const label = __("Withholding Tax Certificate"); - frm.remove_custom_button(label); - if (!frm.doc.apply_tds || frm.is_new() || frm.doc.docstatus === 2) return; + // The certificate is issued once the tax has been withheld, i.e. on payment. + if (!frm.doc.apply_tds || frm.doc.docstatus !== 1 || frm.doc.status !== "Paid") return; // The Withholding Tax Certificate print format renders the Revenue Department's // Sec. 50 bis form (fixtures/print_format.json) as a PDF. - frm.add_custom_button(label, () => { - if (frm.is_dirty()) { - frappe.msgprint(__("Please save the document before generating the certificate.")); - return; - } + frm.add_custom_button(__("Withholding Tax Certificate"), () => { const params = new URLSearchParams({ doctype: frm.doctype, name: frm.docname, diff --git a/default_thai_company/translations/th.csv b/default_thai_company/translations/th.csv index 8e210ef..9073651 100644 --- a/default_thai_company/translations/th.csv +++ b/default_thai_company/translations/th.csv @@ -61,7 +61,6 @@ Withholding Tax Receivable,ภาษีถูกหัก ณ ที่จ่า Output VAT,ภาษีขาย Input VAT,ภาษีซื้อ Withholding Tax Certificate,หนังสือรับรองการหักภาษี ณ ที่จ่าย -Please save the document before generating the certificate.,กรุณาบันทึกเอกสารก่อนออกหนังสือรับรองการหักภาษี ณ ที่จ่าย Type of Income Paid,ประเภทเงินได้พึงประเมินที่จ่าย Salary and Wages - Sec. 40(1),เงินเดือน ค่าจ้าง ฯลฯ ตามมาตรา 40(1) Fees and Commissions - Sec. 40(2),ค่าธรรมเนียม ค่านายหน้า ฯลฯ ตามมาตรา 40(2)