fix(pos): coupon code is applied even if ignore pricing rule is check

This commit is contained in:
Saqib Ansari 2022-02-25 15:18:06 +05:30
parent 69c34cd7ae
commit 81514516f3
2 changed files with 25 additions and 18 deletions

View File

@ -2285,13 +2285,17 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
} }
coupon_code() { coupon_code() {
var me = this; if (this.frm.doc.coupon_code || this.frm._last_coupon_code) {
frappe.run_serially([ // reset pricing rules if coupon code is set or is unset
() => this.frm.doc.ignore_pricing_rule=1, const _ignore_pricing_rule = this.frm.doc.ignore_pricing_rule;
() => me.ignore_pricing_rule(), return frappe.run_serially([
() => this.frm.doc.ignore_pricing_rule=0, () => this.frm.doc.ignore_pricing_rule=1,
() => me.apply_pricing_rule() () => this.frm.trigger('ignore_pricing_rule'),
]); () => this.frm.doc.ignore_pricing_rule=_ignore_pricing_rule,
() => this.frm.trigger('apply_pricing_rule'),
() => this.frm._last_coupon_code = this.frm.doc.coupon_code
]);
}
} }
}; };

View File

@ -170,17 +170,20 @@ erpnext.PointOfSale.Payment = class {
}); });
frappe.ui.form.on('POS Invoice', 'coupon_code', (frm) => { frappe.ui.form.on('POS Invoice', 'coupon_code', (frm) => {
if (!frm.doc.ignore_pricing_rule) { if (!frm.doc.ignore_pricing_rule && frm.doc.coupon_code) {
if (frm.doc.coupon_code) { frappe.run_serially([
frappe.run_serially([ () => frm.doc.ignore_pricing_rule=1,
() => frm.doc.ignore_pricing_rule=1, () => frm.trigger('ignore_pricing_rule'),
() => frm.trigger('ignore_pricing_rule'), () => frm.doc.ignore_pricing_rule=0,
() => frm.doc.ignore_pricing_rule=0, () => frm.trigger('apply_pricing_rule'),
() => frm.trigger('apply_pricing_rule'), () => frm.save(),
() => frm.save(), () => this.update_totals_section(frm.doc)
() => this.update_totals_section(frm.doc) ]);
]); } else if (frm.doc.ignore_pricing_rule && frm.doc.coupon_code) {
} frappe.show_alert({
message: __("Ignore Pricing Rule is enabled. Cannot apply coupon code."),
indicator: "orange"
});
} }
}); });