feat: recursive product discount
This commit is contained in:
@@ -577,7 +577,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
var d = locals[cdt][cdn];
|
||||
me.add_taxes_from_item_tax_template(d.item_tax_rate);
|
||||
if (d.free_item_data) {
|
||||
me.apply_product_discount(d.free_item_data);
|
||||
me.apply_product_discount(d);
|
||||
}
|
||||
},
|
||||
() => {
|
||||
@@ -1204,7 +1204,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
|
||||
calculate_stock_uom_rate: function(doc, cdt, cdn) {
|
||||
let item = frappe.get_doc(cdt, cdn);
|
||||
item.stock_uom_rate = flt(item.rate)/flt(item.conversion_factor);
|
||||
item.stock_uom_rate = flt(item.rate)/flt(item.conversion_factor);
|
||||
refresh_field("stock_uom_rate", item.name, item.parentfield);
|
||||
},
|
||||
service_stop_date: function(frm, cdt, cdn) {
|
||||
@@ -1545,7 +1545,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
}
|
||||
|
||||
if (d.free_item_data) {
|
||||
me.apply_product_discount(d.free_item_data);
|
||||
me.apply_product_discount(d);
|
||||
}
|
||||
|
||||
if (d.apply_rule_on_other_items) {
|
||||
@@ -1579,20 +1579,30 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
}
|
||||
},
|
||||
|
||||
apply_product_discount: function(free_item_data) {
|
||||
const items = this.frm.doc.items.filter(d => (d.item_code == free_item_data.item_code
|
||||
&& d.is_free_item)) || [];
|
||||
apply_product_discount: function(args) {
|
||||
const items = this.frm.doc.items.filter(d => (d.is_free_item)) || [];
|
||||
|
||||
if (!items.length) {
|
||||
let row_to_modify = frappe.model.add_child(this.frm.doc,
|
||||
this.frm.doc.doctype + ' Item', 'items');
|
||||
const exist_items = items.map(row => row.item_code);
|
||||
|
||||
for (let key in free_item_data) {
|
||||
row_to_modify[key] = free_item_data[key];
|
||||
args.free_item_data.forEach(pr_row => {
|
||||
let row_to_modify = {};
|
||||
if (!items || !in_list(exist_items, pr_row.item_code)) {
|
||||
|
||||
row_to_modify = frappe.model.add_child(this.frm.doc,
|
||||
this.frm.doc.doctype + ' Item', 'items');
|
||||
|
||||
} else if(items) {
|
||||
row_to_modify = items.filter(d => d.item_code === pr_row.item_code)[0];
|
||||
}
|
||||
} if (items && items.length && free_item_data) {
|
||||
items[0].qty = free_item_data.qty
|
||||
}
|
||||
|
||||
for (let key in pr_row) {
|
||||
row_to_modify[key] = pr_row[key];
|
||||
}
|
||||
});
|
||||
|
||||
// free_item_data is a temporary variable
|
||||
args.free_item_data = '';
|
||||
refresh_field('items');
|
||||
},
|
||||
|
||||
apply_price_list: function(item, reset_plc_conversion) {
|
||||
|
||||
Reference in New Issue
Block a user