fix: on changing qty free item not removed (#21251)
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 0c63c33..8e8c48f 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -559,7 +559,13 @@
}
},
() => me.conversion_factor(doc, cdt, cdn, true),
- () => me.remove_pricing_rule(item)
+ () => me.remove_pricing_rule(item),
+ () => {
+ if (item.apply_rule_on_other_items) {
+ let key = item.name;
+ me.apply_rule_on_other_items({key: item});
+ }
+ }
]);
}
}
@@ -1394,20 +1400,22 @@
apply_rule_on_other_items: function(args) {
const me = this;
- const fields = ["discount_percentage", "discount_amount", "rate"];
+ const fields = ["discount_percentage", "pricing_rules", "discount_amount", "rate"];
for(var k in args) {
let data = args[k];
- me.frm.doc.items.forEach(d => {
- if (in_list(data.apply_rule_on_other_items, d[data.apply_rule_on])) {
- for(var k in data) {
- if (in_list(fields, k)) {
- frappe.model.set_value(d.doctype, d.name, k, data[k]);
+ if (data && data.apply_rule_on_other_items) {
+ me.frm.doc.items.forEach(d => {
+ if (in_list(data.apply_rule_on_other_items, d[data.apply_rule_on])) {
+ for(var k in data) {
+ if (in_list(fields, k) && data[k]) {
+ frappe.model.set_value(d.doctype, d.name, k, data[k]);
+ }
}
}
- }
- });
+ });
+ }
}
},