Skip to content

Commit

Permalink
Merge pull request #43176 from ljain112/fix-pos-discount
Browse files Browse the repository at this point in the history
fix: hide and reset discount control on new POS order
  • Loading branch information
vorasmit authored Sep 16, 2024
2 parents 705d3de + 5b0053f commit d9d8404
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions erpnext/selling/page/point_of_sale/pos_item_cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,28 +389,14 @@ erpnext.PointOfSale.ItemCart = class {
placeholder: discount ? discount + "%" : __("Enter discount percentage."),
input_class: "input-xs",
onchange: function () {
if (flt(this.value) != 0) {
frappe.model.set_value(
frm.doc.doctype,
frm.doc.name,
"additional_discount_percentage",
flt(this.value)
);
me.hide_discount_control(this.value);
} else {
frappe.model.set_value(
frm.doc.doctype,
frm.doc.name,
"additional_discount_percentage",
0
);
me.$add_discount_elem.css({
border: "1px dashed var(--gray-500)",
padding: "var(--padding-sm) var(--padding-md)",
});
me.$add_discount_elem.html(`${me.get_discount_icon()} ${__("Add Discount")}`);
me.discount_field = undefined;
}
this.value = flt(this.value);
frappe.model.set_value(
frm.doc.doctype,
frm.doc.name,
"additional_discount_percentage",
flt(this.value)
);
me.hide_discount_control(this.value);
},
},
parent: this.$add_discount_elem.find(".add-discount-field"),
Expand All @@ -421,9 +407,13 @@ erpnext.PointOfSale.ItemCart = class {
}

hide_discount_control(discount) {
if (!discount) {
this.$add_discount_elem.css({ padding: "0px", border: "none" });
this.$add_discount_elem.html(`<div class="add-discount-field"></div>`);
if (!flt(discount)) {
this.$add_discount_elem.css({
border: "1px dashed var(--gray-500)",
padding: "var(--padding-sm) var(--padding-md)",
});
this.$add_discount_elem.html(`${this.get_discount_icon()} ${__("Add Discount")}`);
this.discount_field = undefined;
} else {
this.$add_discount_elem.css({
border: "1px dashed var(--dark-green-500)",
Expand Down Expand Up @@ -1051,6 +1041,7 @@ erpnext.PointOfSale.ItemCart = class {
this.highlight_checkout_btn(false);
}

this.hide_discount_control(frm.doc.additional_discount_percentage);
this.update_totals_section(frm);

if (frm.doc.docstatus === 1) {
Expand Down

0 comments on commit d9d8404

Please sign in to comment.