From debd08c3f9f5cc9daf3762c7e5d5ca3d8582749d Mon Sep 17 00:00:00 2001 From: Diptanil Saha Date: Tue, 11 Feb 2025 16:04:36 +0530 Subject: [PATCH 1/2] 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 --- .../selling/page/point_of_sale/pos_payment.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/erpnext/selling/page/point_of_sale/pos_payment.js b/erpnext/selling/page/point_of_sale/pos_payment.js index 0adbf2280dc9..e9d277428843 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,15 @@ erpnext.PointOfSale.Payment = class { const paid_amount = doc.paid_amount; const items = doc.items; +<<<<<<< HEAD if (paid_amount == 0 || !items.length) { +======= + if (!this.validate_reqd_invoice_fields()) { + return; + } + + if (!items.length || (paid_amount == 0 && doc.additional_discount_percentage != 100)) { +>>>>>>> b95b13ecd8 (fix: added validation for required invoice_fields in POS (#45780)) const message = items.length ? __("You cannot submit the order without payment.") : __("You cannot submit empty order."); @@ -620,4 +632,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; + } }; From f2ac773734888daec511fe5759702cc822747b9e Mon Sep 17 00:00:00 2001 From: Diptanil Saha Date: Tue, 11 Feb 2025 16:40:43 +0530 Subject: [PATCH 2/2] fix: resolved merge conflict --- erpnext/selling/page/point_of_sale/pos_payment.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/erpnext/selling/page/point_of_sale/pos_payment.js b/erpnext/selling/page/point_of_sale/pos_payment.js index e9d277428843..33dd0489ba2e 100644 --- a/erpnext/selling/page/point_of_sale/pos_payment.js +++ b/erpnext/selling/page/point_of_sale/pos_payment.js @@ -208,15 +208,11 @@ erpnext.PointOfSale.Payment = class { const paid_amount = doc.paid_amount; const items = doc.items; -<<<<<<< HEAD - if (paid_amount == 0 || !items.length) { -======= if (!this.validate_reqd_invoice_fields()) { return; } if (!items.length || (paid_amount == 0 && doc.additional_discount_percentage != 100)) { ->>>>>>> b95b13ecd8 (fix: added validation for required invoice_fields in POS (#45780)) const message = items.length ? __("You cannot submit the order without payment.") : __("You cannot submit empty order.");