perf: Fetching exchange rate on every line item slows down PO (#25345)

* fix: Dont fetch exchange rates for each line item once fetched at parent
`

* perf: Use price list conversion rate from parent

- If price list conversion rate exists in args already from earlier call, use that
- `get_price_list_currency_and_exchange_rate` wont be called for each child row

Co-authored-by: Nabin Hait <nabinhait@gmail.com>
This commit is contained in:
Marica 2021-04-19 11:05:21 +05:30 committed by GitHub
parent dcdd3bebbe
commit e8bc912ffc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -1103,6 +1103,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
to_currency: to_currency, to_currency: to_currency,
args: args args: args
}, },
freeze: true,
freeze_message: __("Fetching exchange rates ..."),
callback: function(r) { callback: function(r) {
callback(flt(r.message)); callback(flt(r.message));
} }

View File

@ -609,8 +609,12 @@ def get_price_list_rate(args, item_doc, out):
meta = frappe.get_meta(args.parenttype or args.doctype) meta = frappe.get_meta(args.parenttype or args.doctype)
if meta.get_field("currency") or args.get('currency'): if meta.get_field("currency") or args.get('currency'):
pl_details = get_price_list_currency_and_exchange_rate(args) if not args.get("price_list_currency") or not args.get("plc_conversion_rate"):
args.update(pl_details) # if currency and plc_conversion_rate exist then
# `get_price_list_currency_and_exchange_rate` has already been called
pl_details = get_price_list_currency_and_exchange_rate(args)
args.update(pl_details)
if meta.get_field("currency"): if meta.get_field("currency"):
validate_conversion_rate(args, meta) validate_conversion_rate(args, meta)
@ -1000,6 +1004,8 @@ def apply_price_list(args, as_doc=False):
args = process_args(args) args = process_args(args)
parent = get_price_list_currency_and_exchange_rate(args) parent = get_price_list_currency_and_exchange_rate(args)
args.update(parent)
children = [] children = []
if "items" in args: if "items" in args:
@ -1064,7 +1070,7 @@ def get_price_list_currency_and_exchange_rate(args):
return frappe._dict({ return frappe._dict({
"price_list_currency": price_list_currency, "price_list_currency": price_list_currency,
"price_list_uom_dependant": price_list_uom_dependant, "price_list_uom_dependant": price_list_uom_dependant,
"plc_conversion_rate": plc_conversion_rate "plc_conversion_rate": plc_conversion_rate or 1
}) })
@frappe.whitelist() @frappe.whitelist()