Skip to content

Commit

Permalink
fix: remove free item row only if pricing rule matches
Browse files Browse the repository at this point in the history
(cherry picked from commit fea20db)
  • Loading branch information
GursheenK authored and mergify[bot] committed Feb 29, 2024
1 parent 930df21 commit 6352bfe
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions erpnext/public/js/controllers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,8 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
}

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){
let me = this;
return this.frm.call({
Expand All @@ -1533,7 +1535,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
},
callback: function(r) {
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();
if(me.frm.doc.apply_discount_on) me.frm.trigger("apply_discount_on");
}
Expand Down Expand Up @@ -1791,7 +1793,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
});
}

remove_pricing_rule(item) {
remove_pricing_rule(item, removed_pricing_rule) {
let me = this;
const fields = ["discount_percentage",
"discount_amount", "margin_rate_or_amount", "rate_with_margin"];
Expand All @@ -1800,7 +1802,8 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
let items = [];

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);
}
});
Expand Down

0 comments on commit 6352bfe

Please sign in to comment.