From fd3adbb6fe4a567fe3176bb27c8ed5c23de5ca66 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 22 Feb 2022 16:25:32 +0530 Subject: [PATCH 1/4] fix: Item discounts for quotation (cherry picked from commit 3a547cb0d965b8012136d06adc9d7c7b94700660) # Conflicts: # erpnext/selling/doctype/quotation/quotation.js --- erpnext/controllers/taxes_and_totals.py | 2 +- erpnext/selling/doctype/quotation/quotation.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 08d1dcea7dc..d1904747918 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -116,7 +116,7 @@ class calculate_taxes_and_totals(object): if item.discount_percentage == 100: item.rate = 0.0 elif item.price_list_rate: - if not item.rate or (item.pricing_rules and item.discount_percentage > 0): + if item.pricing_rules or 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) diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 474cf56fc1b..0ff00c09762 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -38,6 +38,7 @@ frappe.ui.form.on('Quotation', { } }); +<<<<<<< HEAD erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ onload: function(doc, dt, dn) { var me = this; @@ -45,6 +46,13 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ }, party_name: function() { +======= +erpnext.selling.QuotationController = class QuotationController extends erpnext.selling.SellingController { + onload(doc, dt, dn) { + super.onload(doc, dt, dn); + } + party_name() { +>>>>>>> 3a547cb0d9 (fix: Item discounts for quotation) var me = this; erpnext.utils.get_party_details(this.frm, null, null, function() { me.apply_price_list(); From dfbd0ebf910e65eeb8a94043ebcd9ebe5a96d46a Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 1 Mar 2022 11:48:28 +0530 Subject: [PATCH 2/4] fix: apply margin on duplicated doc too (cherry picked from commit bbc4710fa31357cad038f2b515ae07ed09bd2c5e) --- erpnext/controllers/taxes_and_totals.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index d1904747918..692af71a57a 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -116,11 +116,11 @@ class calculate_taxes_and_totals(object): if item.discount_percentage == 100: item.rate = 0.0 elif item.price_list_rate: - if item.pricing_rules or item.discount_percentage > 0: + if item.pricing_rules or abs(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.pricing_rules: + elif item.discount_amount or 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', 'POS Invoice Item', 'Purchase Invoice Item', 'Purchase Order Item', 'Purchase Receipt Item']: From 9af14ec0d0de06b0df422ca482428c430b4771ed Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 1 Mar 2022 23:09:59 +0530 Subject: [PATCH 3/4] fix: Test cases with discount (cherry picked from commit d95f8934aa5cafdddd02568841786081f90c214a) --- erpnext/controllers/taxes_and_totals.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 692af71a57a..36e4f0a759d 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -113,17 +113,24 @@ class calculate_taxes_and_totals(object): for item in self.doc.get("items"): self.doc.round_floats_in(item) + if not item.rate: + item.rate = item.price_list_rate + if item.discount_percentage == 100: item.rate = 0.0 elif item.price_list_rate: if item.pricing_rules or abs(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) + + if abs(item.discount_percentage) > 0: + item.discount_amount = item.price_list_rate * (item.discount_percentage / 100.0) + elif item.discount_amount or 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', 'POS Invoice Item', 'Purchase Invoice Item', 'Purchase Order Item', 'Purchase Receipt Item']: + if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item', + 'POS Invoice Item', 'Purchase Invoice Item', 'Purchase Order Item', 'Purchase Receipt 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")) From ba4d49640467b148a804a4788766048e08992cdb Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Tue, 8 Mar 2022 09:55:36 +0530 Subject: [PATCH 4/4] fix: Resolve conflicts --- erpnext/selling/doctype/quotation/quotation.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 0ff00c09762..474cf56fc1b 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -38,7 +38,6 @@ frappe.ui.form.on('Quotation', { } }); -<<<<<<< HEAD erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ onload: function(doc, dt, dn) { var me = this; @@ -46,13 +45,6 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ }, party_name: function() { -======= -erpnext.selling.QuotationController = class QuotationController extends erpnext.selling.SellingController { - onload(doc, dt, dn) { - super.onload(doc, dt, dn); - } - party_name() { ->>>>>>> 3a547cb0d9 (fix: Item discounts for quotation) var me = this; erpnext.utils.get_party_details(this.frm, null, null, function() { me.apply_price_list();