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 b95b13ecd8)

# Conflicts:
#	erpnext/selling/page/point_of_sale/pos_payment.js

* fix: resolved merge conflict

---------

Co-authored-by: Diptanil Saha <diptanil@frappe.io>
This commit is contained in:
mergify[bot]
2025-02-11 17:55:07 +05:30
committed by GitHub
parent 179cb1e6e5
commit 4f9a7f5065

View File

@@ -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;
}
};