Skip to content

Commit

Permalink
fix: pos payment using non-default mode of payment (#44920)
Browse files Browse the repository at this point in the history
* fix: pos payment using non-default mode of payment (#41108)

* fix: included css syntax

* refactor: created a function to sanitize the class name

* refactor: reusing method to sanitize class name

* refactor: function rename
  • Loading branch information
diptanilsaha authored Dec 30, 2024
1 parent 867aa9d commit 98cbb7e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions erpnext/selling/page/point_of_sale/pos_payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ erpnext.PointOfSale.Payment = class {
frappe.ui.form.on("Sales Invoice Payment", "amount", (frm, cdt, cdn) => {
// for setting correct amount after loyalty points are redeemed
const default_mop = locals[cdt][cdn];
const mode = default_mop.mode_of_payment.replace(/ +/g, "_").toLowerCase();
const mode = this.sanitize_mode_of_payment(default_mop.mode_of_payment);
if (this[`${mode}_control`] && this[`${mode}_control`].get_value() != default_mop.amount) {
this[`${mode}_control`].set_value(default_mop.amount);
}
Expand Down Expand Up @@ -388,7 +388,7 @@ erpnext.PointOfSale.Payment = class {
this.$payment_modes.html(
`${payments
.map((p, i) => {
const mode = p.mode_of_payment.replace(/ +/g, "_").toLowerCase();
const mode = this.sanitize_mode_of_payment(p.mode_of_payment);
const payment_type = p.type;
const margin = i % 2 === 0 ? "pr-2" : "pl-2";
const amount = p.amount > 0 ? format_currency(p.amount, currency) : "";
Expand All @@ -407,7 +407,7 @@ erpnext.PointOfSale.Payment = class {
);

payments.forEach((p) => {
const mode = p.mode_of_payment.replace(/ +/g, "_").toLowerCase();
const mode = this.sanitize_mode_of_payment(p.mode_of_payment);
const me = this;
this[`${mode}_control`] = frappe.ui.form.make_control({
df: {
Expand Down Expand Up @@ -442,7 +442,7 @@ erpnext.PointOfSale.Payment = class {
const doc = this.events.get_frm().doc;
const payments = doc.payments;
payments.forEach((p) => {
const mode = p.mode_of_payment.replace(/ +/g, "_").toLowerCase();
const mode = this.sanitize_mode_of_payment(p.mode_of_payment);
if (p.default) {
setTimeout(() => {
this.$payment_modes.find(`.${mode}.mode-of-payment-control`).parent().click();
Expand Down Expand Up @@ -612,4 +612,12 @@ erpnext.PointOfSale.Payment = class {
toggle_component(show) {
show ? this.$component.css("display", "flex") : this.$component.css("display", "none");
}

sanitize_mode_of_payment(mode_of_payment) {
return mode_of_payment
.replace(/ +/g, "_")
.replace(/[^\p{L}\p{N}_-]/gu, "")
.replace(/^[^_a-zA-Z\p{L}]+/u, "")
.toLowerCase();
}
};

0 comments on commit 98cbb7e

Please sign in to comment.