Merge pull request #17154 from nabinhait/item-discount
fix: Calculate rate based on discount on server side, only if not rate or pricing rule applied
This commit is contained in:
commit
cc6ee8e16e
@ -59,19 +59,21 @@ class calculate_taxes_and_totals(object):
|
||||
|
||||
if item.discount_percentage == 100:
|
||||
item.rate = 0.0
|
||||
elif (not item.rate or item.discount_percentage > 0) and item.price_list_rate:
|
||||
elif item.price_list_rate:
|
||||
if not item.rate or (item.pricing_rules and item.discount_percentage > 0):
|
||||
item.rate = flt(item.price_list_rate *
|
||||
(1.0 - (item.discount_percentage / 100.0)), item.precision("rate"))
|
||||
item.discount_amount = item.price_list_rate * (item.discount_percentage / 100.0)
|
||||
elif item.discount_amount and item.price_list_rate:
|
||||
elif item.discount_amount and item.pricing_rules:
|
||||
item.rate = item.price_list_rate - item.discount_amount
|
||||
|
||||
if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item']:
|
||||
item.rate_with_margin, item.base_rate_with_margin = self.calculate_margin(item)
|
||||
|
||||
if flt(item.rate_with_margin) > 0:
|
||||
item.rate = flt(item.rate_with_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate"))
|
||||
item.discount_amount = item.rate_with_margin - item.rate
|
||||
elif flt(item.price_list_rate) > 0:
|
||||
item.discount_amount = item.price_list_rate - item.rate
|
||||
elif flt(item.price_list_rate) > 0 and not item.discount_amount:
|
||||
item.discount_amount = item.price_list_rate - item.rate
|
||||
|
||||
|
@ -147,6 +147,8 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
},
|
||||
|
||||
discount_amount: function(doc, cdt, cdn) {
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
item.discount_percentage = 0.0;
|
||||
this.price_list_rate(doc, cdt, cdn);
|
||||
},
|
||||
|
||||
|
@ -23,6 +23,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
} 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;
|
||||
|
@ -145,6 +145,8 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
},
|
||||
|
||||
discount_amount: function(doc, cdt, cdn) {
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
item.discount_percentage = 0.0;
|
||||
this.apply_discount_on_item(doc, cdt, cdn, 'discount_amount');
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user