From 54f2d5352295a22f9d0819af0f175f8db7174904 Mon Sep 17 00:00:00 2001 From: Don-Leopardo <46027152+Don-Leopardo@users.noreply.github.com> Date: Tue, 7 Jan 2020 03:05:57 -0300 Subject: [PATCH] fix: get_item_price not working properly (#20206) * fix: min_qty not working without party and valid_from not being used to order results * fix: fetch price on item qty change --- erpnext/public/js/controllers/transaction.js | 2 +- erpnext/stock/get_item_details.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 8870d75e39a..512bcf9f4fb 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -968,7 +968,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ qty: function(doc, cdt, cdn) { let item = frappe.get_doc(cdt, cdn); - this.conversion_factor(doc, cdt, cdn, true); + this.conversion_factor(doc, cdt, cdn, false); this.apply_pricing_rule(item, true); }, diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 4abd8553919..6fc6990df76 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -608,7 +608,7 @@ def get_item_price(args, item_code, ignore_party=False): return frappe.db.sql(""" select name, price_list_rate, uom from `tabItem Price` {conditions} - order by uom desc, min_qty desc """.format(conditions=conditions), args) + order by uom desc, min_qty desc, valid_from desc """.format(conditions=conditions), args) def get_price_list_rate_for(args, item_code): """ @@ -641,10 +641,15 @@ def get_price_list_rate_for(args, item_code): if desired_qty and check_packing_list(price_list_rate[0][0], desired_qty, item_code): item_price_data = price_list_rate else: - for field in ["customer", "supplier", "min_qty"]: + for field in ["customer", "supplier"]: del item_price_args[field] general_price_list_rate = get_item_price(item_price_args, item_code, ignore_party=args.get("ignore_party")) + + if not general_price_list_rate: + del item_price_args["min_qty"] + general_price_list_rate = get_item_price(item_price_args, item_code, ignore_party=args.get("ignore_party")) + if not general_price_list_rate and args.get("uom") != args.get("stock_uom"): item_price_args["uom"] = args.get("stock_uom") general_price_list_rate = get_item_price(item_price_args, item_code, ignore_party=args.get("ignore_party"))