Merge pull request #30413 from frappe/mergify/bp/develop/pr-30406
fix: Rate change issue on save and mapping from other doc (backport #30406)
diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py
index 2166633..d6296eb 100644
--- a/erpnext/controllers/sales_and_purchase_return.py
+++ b/erpnext/controllers/sales_and_purchase_return.py
@@ -399,6 +399,8 @@
}
}, target_doc, set_missing_values)
+ doclist.set_onload('ignore_price_list', True)
+
return doclist
def get_rate_for_return(voucher_type, voucher_no, item_code, return_against=None,
diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py
index 19acc10..29da5f1 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -114,20 +114,16 @@
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:
+ 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"))
- if abs(item.discount_percentage) > 0:
- item.discount_amount = item.price_list_rate * (item.discount_percentage / 100.0)
+ item.discount_amount = item.price_list_rate * (item.discount_percentage / 100.0)
- elif item.discount_amount or item.pricing_rules:
+ 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',
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 43ee5b3..19e12e3 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -1042,9 +1042,9 @@
var me = this;
this.set_dynamic_labels();
var company_currency = this.get_company_currency();
- // Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
+ // Added `ignore_price_list` to determine if document is loading after mapping from another doc
if(this.frm.doc.currency && this.frm.doc.currency !== company_currency
- && !this.frm.doc.ignore_pricing_rule) {
+ && !this.frm.doc.__onload.ignore_price_list) {
this.get_exchange_rate(transaction_date, this.frm.doc.currency, company_currency,
function(exchange_rate) {
@@ -1144,8 +1144,8 @@
this.set_dynamic_labels();
var company_currency = this.get_company_currency();
- // Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
- if(this.frm.doc.price_list_currency !== company_currency && !this.frm.doc.ignore_pricing_rule) {
+ // Added `ignore_price_list` to determine if document is loading after mapping from another doc
+ if(this.frm.doc.price_list_currency !== company_currency && !this.frm.doc.__onload.ignore_price_list) {
this.get_exchange_rate(this.frm.doc.posting_date, this.frm.doc.price_list_currency, company_currency,
function(exchange_rate) {
me.frm.set_value("plc_conversion_rate", exchange_rate);