From f6ab5005a4508fe7fe3773d43f260d56f87544d3 Mon Sep 17 00:00:00 2001 From: Diptanil Saha Date: Tue, 11 Feb 2025 16:04:36 +0530 Subject: [PATCH] fix: added validation for required invoice_fields in POS (#45780) fix: added missing validation for required invoice_fields --- .../selling/page/point_of_sale/pos_payment.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/erpnext/selling/page/point_of_sale/pos_payment.js b/erpnext/selling/page/point_of_sale/pos_payment.js index 7e8b86fcd9..0e7b7ad223 100644 --- a/erpnext/selling/page/point_of_sale/pos_payment.js +++ b/erpnext/selling/page/point_of_sale/pos_payment.js @@ -42,6 +42,7 @@ erpnext.PointOfSale.Payment = class { } make_invoice_fields_control() { + this.reqd_invoice_fields = []; frappe.db.get_doc("POS Settings", undefined).then((doc) => { const fields = doc.invoice_fields; if (!fields.length) return; @@ -68,6 +69,9 @@ erpnext.PointOfSale.Payment = class { } }; } + if (df.reqd && (df.fieldtype !== "Button" || !df.read_only)) { + this.reqd_invoice_fields.push({ fieldname: df.fieldname, label: df.label }); + } this[`${df.fieldname}_field`] = frappe.ui.form.make_control({ df: { @@ -203,6 +207,10 @@ erpnext.PointOfSale.Payment = class { const paid_amount = doc.paid_amount; const items = doc.items; + if (!this.validate_reqd_invoice_fields()) { + return; + } + if (!items.length || (paid_amount == 0 && doc.additional_discount_percentage != 100)) { const message = items.length ? __("You cannot submit the order without payment.") : __("You cannot submit empty order."); frappe.show_alert({ message, indicator: "orange" }); @@ -581,4 +589,20 @@ erpnext.PointOfSale.Payment = class { .replace(/^[^_a-zA-Z\p{L}]+/u, "") .toLowerCase(); } + + validate_reqd_invoice_fields() { + const doc = this.events.get_frm().doc; + let validation_flag = true; + for (let field of this.reqd_invoice_fields) { + if (!doc[field.fieldname]) { + validation_flag = false; + frappe.show_alert({ + message: __("{0} is a mandatory field.", [field.label]), + indicator: "orange", + }); + frappe.utils.play_sound("error"); + } + } + return validation_flag; + } }; -- GitLab