fix: remove free item row only if pricing rule matches
This commit is contained in:
parent
6f5815e44f
commit
fea20db262
@ -1523,6 +1523,8 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
}
|
}
|
||||||
|
|
||||||
remove_pricing_rule_for_item(item) {
|
remove_pricing_rule_for_item(item) {
|
||||||
|
// capture pricing rule before removing it to delete free items
|
||||||
|
let removed_pricing_rule = item.pricing_rules;
|
||||||
if (item.pricing_rules){
|
if (item.pricing_rules){
|
||||||
let me = this;
|
let me = this;
|
||||||
return this.frm.call({
|
return this.frm.call({
|
||||||
@ -1543,7 +1545,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if (!r.exc && r.message) {
|
if (!r.exc && r.message) {
|
||||||
me.remove_pricing_rule(r.message);
|
me.remove_pricing_rule(r.message, removed_pricing_rule);
|
||||||
me.calculate_taxes_and_totals();
|
me.calculate_taxes_and_totals();
|
||||||
if(me.frm.doc.apply_discount_on) me.frm.trigger("apply_discount_on");
|
if(me.frm.doc.apply_discount_on) me.frm.trigger("apply_discount_on");
|
||||||
}
|
}
|
||||||
@ -1801,7 +1803,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_pricing_rule(item) {
|
remove_pricing_rule(item, removed_pricing_rule) {
|
||||||
let me = this;
|
let me = this;
|
||||||
const fields = ["discount_percentage",
|
const fields = ["discount_percentage",
|
||||||
"discount_amount", "margin_rate_or_amount", "rate_with_margin"];
|
"discount_amount", "margin_rate_or_amount", "rate_with_margin"];
|
||||||
@ -1810,7 +1812,8 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
let items = [];
|
let items = [];
|
||||||
|
|
||||||
me.frm.doc.items.forEach(d => {
|
me.frm.doc.items.forEach(d => {
|
||||||
if(d.item_code != item.remove_free_item || !d.is_free_item) {
|
// if same item was added a free item through a different pricing rule, keep it
|
||||||
|
if(d.item_code != item.remove_free_item || !d.is_free_item || removed_pricing_rule?.includes(d.pricing_rules)) {
|
||||||
items.push(d);
|
items.push(d);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user