From 4f9a7f50653109c547b4465a9bf867d11e15bf9c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 11 Feb 2025 17:55:07 +0530 Subject: [PATCH] fix: added validation for required invoice_fields in POS (backport #45780) (#45868) * fix: added validation for required invoice_fields in POS (#45780) fix: added missing validation for required invoice_fields (cherry picked from commit b95b13ecd880a595275a795b7da45dede0756c44) # Conflicts: # erpnext/selling/page/point_of_sale/pos_payment.js * fix: resolved merge conflict --------- Co-authored-by: Diptanil Saha --- .../selling/page/point_of_sale/pos_payment.js | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/erpnext/selling/page/point_of_sale/pos_payment.js b/erpnext/selling/page/point_of_sale/pos_payment.js index 0adbf2280dc..33dd0489ba2 100644 --- a/erpnext/selling/page/point_of_sale/pos_payment.js +++ b/erpnext/selling/page/point_of_sale/pos_payment.js @@ -41,6 +41,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; @@ -67,6 +68,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: { @@ -204,7 +208,11 @@ erpnext.PointOfSale.Payment = class { const paid_amount = doc.paid_amount; const items = doc.items; - if (paid_amount == 0 || !items.length) { + 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."); @@ -620,4 +628,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; + } };