Skip to content

Commit 7dd2b0c

Browse files
fix: pos payment using non-default mode of payment (backport frappe#44920) (frappe#44971)
fix: pos payment using non-default mode of payment (frappe#44920) * fix: pos payment using non-default mode of payment (frappe#41108) * fix: included css syntax * refactor: created a function to sanitize the class name * refactor: reusing method to sanitize class name * refactor: function rename (cherry picked from commit 98cbb7e) Co-authored-by: Diptanil Saha <[email protected]>
1 parent 3a361ea commit 7dd2b0c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

erpnext/selling/page/point_of_sale/pos_payment.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ erpnext.PointOfSale.Payment = class {
235235
frappe.ui.form.on("Sales Invoice Payment", "amount", (frm, cdt, cdn) => {
236236
// for setting correct amount after loyalty points are redeemed
237237
const default_mop = locals[cdt][cdn];
238-
const mode = default_mop.mode_of_payment.replace(/ +/g, "_").toLowerCase();
238+
const mode = this.sanitize_mode_of_payment(default_mop.mode_of_payment);
239239
if (this[`${mode}_control`] && this[`${mode}_control`].get_value() != default_mop.amount) {
240240
this[`${mode}_control`].set_value(default_mop.amount);
241241
}
@@ -388,7 +388,7 @@ erpnext.PointOfSale.Payment = class {
388388
this.$payment_modes.html(
389389
`${payments
390390
.map((p, i) => {
391-
const mode = p.mode_of_payment.replace(/ +/g, "_").toLowerCase();
391+
const mode = this.sanitize_mode_of_payment(p.mode_of_payment);
392392
const payment_type = p.type;
393393
const margin = i % 2 === 0 ? "pr-2" : "pl-2";
394394
const amount = p.amount > 0 ? format_currency(p.amount, currency) : "";
@@ -407,7 +407,7 @@ erpnext.PointOfSale.Payment = class {
407407
);
408408

409409
payments.forEach((p) => {
410-
const mode = p.mode_of_payment.replace(/ +/g, "_").toLowerCase();
410+
const mode = this.sanitize_mode_of_payment(p.mode_of_payment);
411411
const me = this;
412412
this[`${mode}_control`] = frappe.ui.form.make_control({
413413
df: {
@@ -442,7 +442,7 @@ erpnext.PointOfSale.Payment = class {
442442
const doc = this.events.get_frm().doc;
443443
const payments = doc.payments;
444444
payments.forEach((p) => {
445-
const mode = p.mode_of_payment.replace(/ +/g, "_").toLowerCase();
445+
const mode = this.sanitize_mode_of_payment(p.mode_of_payment);
446446
if (p.default) {
447447
setTimeout(() => {
448448
this.$payment_modes.find(`.${mode}.mode-of-payment-control`).parent().click();
@@ -612,4 +612,12 @@ erpnext.PointOfSale.Payment = class {
612612
toggle_component(show) {
613613
show ? this.$component.css("display", "flex") : this.$component.css("display", "none");
614614
}
615+
616+
sanitize_mode_of_payment(mode_of_payment) {
617+
return mode_of_payment
618+
.replace(/ +/g, "_")
619+
.replace(/[^\p{L}\p{N}_-]/gu, "")
620+
.replace(/^[^_a-zA-Z\p{L}]+/u, "")
621+
.toLowerCase();
622+
}
615623
};

0 commit comments

Comments
 (0)