Skip to content

Commit

Permalink
Merge pull request #42170 from frappe/mergify/bp/version-15-hotfix/pr…
Browse files Browse the repository at this point in the history
…-42165

fix: multiple free items on same Item Group (backport #42165)
  • Loading branch information
ruthra-kumar authored Jul 3, 2024
2 parents de130cb + 9352863 commit fcfe78b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions erpnext/public/js/controllers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -1750,12 +1750,15 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
apply_product_discount(args) {
const items = this.frm.doc.items.filter(d => (d.is_free_item)) || [];

const exist_items = items.map(row => (row.item_code, row.pricing_rules));
const exist_items = items.map(row => { return {item_code: row.item_code, pricing_rules: row.pricing_rules};});

args.free_item_data.forEach(pr_row => {
let row_to_modify = {};
if (!items || !in_list(exist_items, (pr_row.item_code, pr_row.pricing_rules))) {

// If there are no free items, or if the current free item doesn't exist in the table, add it
if (!items || !exist_items.filter(e_row => {
return e_row.item_code == pr_row.item_code && e_row.pricing_rules == pr_row.pricing_rules;
}).length) {
row_to_modify = frappe.model.add_child(this.frm.doc,
this.frm.doc.doctype + ' Item', 'items');

Expand Down

0 comments on commit fcfe78b

Please sign in to comment.