From 6e344db222c88f9fafe787c8a9f24097e666b6cb Mon Sep 17 00:00:00 2001 From: Safwan Samsudeen Date: Fri, 27 Feb 2026 18:38:58 +0530 Subject: [PATCH] fix: support options fix: bundle files --- frappe/printing/page/print/print.js | 15 ++++---- .../public/js/frappe/form/controls/barcode.js | 2 +- frappe/public/js/print.bundle.js | 25 +++++++++++++ .../print_formats/standard_macros.html | 3 +- frappe/www/printview.html | 37 +------------------ 5 files changed, 36 insertions(+), 46 deletions(-) create mode 100644 frappe/public/js/print.bundle.js diff --git a/frappe/printing/page/print/print.js b/frappe/printing/page/print/print.js index a46299a371..5d682e41f3 100644 --- a/frappe/printing/page/print/print.js +++ b/frappe/printing/page/print/print.js @@ -500,15 +500,14 @@ frappe.ui.form.PrintView = class { .find("body") .html(``); const iframeDoc = this.$print_format_body[0]; - const script = iframeDoc.createElement("script"); - script.src = "https://cdn.jsdelivr.net/npm/jsbarcode@3/dist/JsBarcode.all.min.js"; - script.onload = () => { - iframeDoc.querySelectorAll("svg[data-barcode-value]").forEach((el) => { - JsBarcode(el, el.dataset.barcodeValue, { width: 3, height: 50, fontSize: 16 }); - el.setAttribute("width", "100%"); + iframeDoc.querySelectorAll("svg[data-barcode-value]").forEach((el) => { + const get_options = frappe.ui.form.ControlBarcode.prototype.get_options.bind({ + df: { options: el.dataset.options }, }); - }; - iframeDoc.head.appendChild(script); + console.log(get_options(el.dataset.barcodeValue)); + JsBarcode(el, el.dataset.barcodeValue, get_options(el.dataset.barcodeValue)); + el.setAttribute("width", "100%"); + }); this.show_footer(); this.$print_format_body.find(".print-format").css({ diff --git a/frappe/public/js/frappe/form/controls/barcode.js b/frappe/public/js/frappe/form/controls/barcode.js index a819384773..06a547395d 100644 --- a/frappe/public/js/frappe/form/controls/barcode.js +++ b/frappe/public/js/frappe/form/controls/barcode.js @@ -64,7 +64,7 @@ frappe.ui.form.ControlBarcode = class ControlBarcode extends frappe.ui.form.Cont options.height = "50"; if (frappe.utils.is_json(this.df.options)) { - options = JSON.parse(this.df.options); + Object.assign(options, JSON.parse(this.df.options)); if (options.format && options.format === "EAN") { options.format = value.length == 8 ? "EAN8" : "EAN13"; } diff --git a/frappe/public/js/print.bundle.js b/frappe/public/js/print.bundle.js new file mode 100644 index 0000000000..de1eb49f73 --- /dev/null +++ b/frappe/public/js/print.bundle.js @@ -0,0 +1,25 @@ +import JsBarcode from "jsbarcode"; + +function get_options(value, df_options = null) { + let options = {}; + options.fontSize = "16"; + options.width = "3"; + options.height = "50"; + if (df_options) { + Object.assign(options, JSON.parse(df_options)); + if (options.format && options.format === "EAN") { + options.format = value.length == 8 ? "EAN8" : "EAN13"; + } + } + return options; +} + +window.render_barcode = (el) => { + const value = el.dataset.barcodeValue; + try { + JsBarcode(el, value, get_options(value, el.dataset.options)); + el.setAttribute("width", "100%"); + } catch (e) { + console.log(e); + } +}; diff --git a/frappe/templates/print_formats/standard_macros.html b/frappe/templates/print_formats/standard_macros.html index 1f4d2fab96..5fb9d608bb 100644 --- a/frappe/templates/print_formats/standard_macros.html +++ b/frappe/templates/print_formats/standard_macros.html @@ -158,8 +158,7 @@ data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}" {% elif df.fieldtype=="Barcode" %} - - + {% elif df.fieldtype in ("Attach", "Attach Image") and frappe.utils.is_image(doc[df.fieldname]) %} diff --git a/frappe/www/printview.html b/frappe/www/printview.html index f599388137..ffa89d677e 100644 --- a/frappe/www/printview.html +++ b/frappe/www/printview.html @@ -6,41 +6,7 @@ {{ title }} {{ include_style('print.bundle.css') }} - - + {{ include_script('print.bundle.js') }} {% if print_style %}