fix: Add back calculation for discount

(cherry picked from commit 067564bd260437290b7cb190fb1cdc02eb658d0a)
This commit is contained in:
Deepesh Garg 2022-03-25 12:17:51 +05:30 committed by mergify-bot
parent 174a6ec398
commit 54cdff7947

View File

@ -14,6 +14,31 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
frappe.model.round_floats_in(item, ["rate", "price_list_rate"]);
if(item.price_list_rate) {
if(item.rate > item.price_list_rate && has_margin_field) {
// if rate is greater than price_list_rate, set margin
// or set discount
item.discount_percentage = 0;
item.margin_type = 'Amount';
item.margin_rate_or_amount = flt(item.rate - item.price_list_rate,
precision("margin_rate_or_amount", item));
item.rate_with_margin = item.rate;
} else {
item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0,
precision("discount_percentage", item));
item.discount_amount = flt(item.price_list_rate) - flt(item.rate);
item.margin_type = '';
item.margin_rate_or_amount = 0;
item.rate_with_margin = 0;
}
} else {
item.discount_percentage = 0.0;
item.margin_type = '';
item.margin_rate_or_amount = 0;
item.rate_with_margin = 0;
}
item.base_rate_with_margin = item.rate_with_margin * flt(frm.doc.conversion_rate);
cur_frm.cscript.set_gross_profit(item);
cur_frm.cscript.calculate_taxes_and_totals();
cur_frm.cscript.calculate_stock_uom_rate(frm, cdt, cdn);