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:
Nabin Hait 2019-05-01 13:44:21 +05:30 committed by GitHub
commit cc6ee8e16e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 7 deletions

View File

@ -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

View File

@ -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);
},

View File

@ -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;

View File

@ -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');
},