fix: deprecated fetching item price based on min_qty (#20347)
diff --git a/erpnext/stock/doctype/item_price/item_price.py b/erpnext/stock/doctype/item_price/item_price.py
index 4c496cb..957c415 100644
--- a/erpnext/stock/doctype/item_price/item_price.py
+++ b/erpnext/stock/doctype/item_price/item_price.py
@@ -13,7 +13,7 @@
class ItemPrice(Document):
-
+
def validate(self):
self.validate_item()
self.validate_dates()
@@ -51,7 +51,7 @@
def check_duplicates(self):
conditions = "where item_code=%(item_code)s and price_list=%(price_list)s and name != %(name)s"
- for field in ['uom', 'min_qty', 'valid_from',
+ for field in ['uom', 'valid_from',
'valid_upto', 'packing_unit', 'customer', 'supplier']:
if self.get(field):
conditions += " and {0} = %({1})s".format(field, field)
diff --git a/erpnext/stock/doctype/item_price/test_item_price.py b/erpnext/stock/doctype/item_price/test_item_price.py
index 3782f54..702acc3 100644
--- a/erpnext/stock/doctype/item_price/test_item_price.py
+++ b/erpnext/stock/doctype/item_price/test_item_price.py
@@ -21,7 +21,7 @@
def test_addition_of_new_fields(self):
# Based on https://github.com/frappe/erpnext/issues/8456
test_fields_existance = [
- 'supplier', 'customer', 'uom', 'min_qty', 'lead_time_days',
+ 'supplier', 'customer', 'uom', 'lead_time_days',
'packing_unit', 'valid_from', 'valid_upto', 'note'
]
doc_fields = frappe.copy_doc(test_records[1]).__dict__.keys()
@@ -43,7 +43,6 @@
args = {
"price_list": doc.price_list,
- "min_qty": doc.min_qty,
"customer": doc.customer,
"uom": "_Test UOM",
"transaction_date": '2017-04-18',
@@ -58,7 +57,6 @@
doc = frappe.copy_doc(test_records[2])
args = {
"price_list": doc.price_list,
- "min_qty": 30,
"customer": doc.customer,
"uom": "_Test UOM",
"transaction_date": '2017-04-18',
@@ -74,7 +72,6 @@
args = {
"price_list": doc.price_list,
- "min_qty": doc.min_qty,
"customer": "_Test Customer",
"uom": "_Test UOM",
"transaction_date": '2017-04-18',
@@ -90,7 +87,6 @@
args = {
"price_list": doc.price_list,
- "min_qty": doc.min_qty,
"qty": 7,
"uom": "_Test UOM",
"transaction_date": "01-15-2019"
@@ -105,7 +101,6 @@
args = {
"price_list": doc.price_list,
- "min_qty": doc.min_qty,
"customer": "_Test Customer",
"uom": "_Test UOM",
"transaction_date": "2017-04-25",
@@ -121,7 +116,6 @@
args = {
"price_list": doc.price_list,
- "min_qty": doc.min_qty,
"uom": "_Test UOM",
"qty": 7,
}
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 2975f93..d0efaa2 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -583,7 +583,7 @@
Get name, price_list_rate from Item Price based on conditions
Check if the desired qty is within the increment of the packing list.
:param args: dict (or frappe._dict) with mandatory fields price_list, uom
- optional fields min_qty, transaction_date, customer, supplier
+ optional fields transaction_date, customer, supplier
:param item_code: str, Item Doctype field item_code
"""
@@ -601,24 +601,16 @@
else:
conditions += " and (customer is null or customer = '') and (supplier is null or supplier = '')"
- if args.get('min_qty'):
- conditions += " and ifnull(min_qty, 0) <= %(min_qty)s"
-
if args.get('transaction_date'):
conditions += """ and %(transaction_date)s between
ifnull(valid_from, '2000-01-01') and ifnull(valid_upto, '2500-12-31')"""
return frappe.db.sql(""" select name, price_list_rate, uom
from `tabItem Price` {conditions}
- order by valid_from desc, min_qty desc, uom desc """.format(conditions=conditions), args)
+ order by valid_from desc, uom desc """.format(conditions=conditions), args)
def get_price_list_rate_for(args, item_code):
"""
- Return Price Rate based on min_qty of each Item Price Rate.\
- For example, desired qty is 10 and Item Price Rates exists
- for min_qty 9 and min_qty 20. It returns Item Price Rate for qty 9 as
- the best fit in the range of avaliable min_qtyies
-
:param customer: link to Customer DocType
:param supplier: link to Supplier DocType
:param price_list: str (Standard Buying or Standard Selling)
@@ -632,8 +624,6 @@
"customer": args.get('customer'),
"supplier": args.get('supplier'),
"uom": args.get('uom'),
- "min_qty": args.get('qty') if args.get('price_list_uom_dependant')\
- else flt(args.get('qty')) * flt(args.get("conversion_factor", 1)),
"transaction_date": args.get('transaction_date'),
}
@@ -649,9 +639,6 @@
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")