diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 9fabb2bdc89..1dd6febc0e7 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -152,7 +152,7 @@ def _get_pricing_rules(apply_on, args, values): and {child_doc}.parent = `tabPricing Rule`.name and `tabPricing Rule`.disable = 0 and `tabPricing Rule`.{transaction_type} = 1 {warehouse_cond} {conditions} - order by `tabPricing Rule`.priority desc, + order by coalesce(`tabPricing Rule`.priority, '') desc, `tabPricing Rule`.name desc""".format( child_doc=child_doc, apply_on_field=apply_on_field, diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.py b/erpnext/selling/page/point_of_sale/point_of_sale.py index a96fc309687..8f0bc136458 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -231,6 +231,7 @@ def get_items( .where(ItemPrice.selling == 1) .where((ItemPrice.valid_from <= current_date) | (ItemPrice.valid_from.isnull())) .where((ItemPrice.valid_upto >= current_date) | (ItemPrice.valid_upto.isnull())) + .orderby(ItemPrice.valid_from.isnull(), order=Order.asc) .orderby(ItemPrice.valid_from, order=Order.desc) ).run(as_dict=True) diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index cd706b800a5..951023d8bb7 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -2432,6 +2432,8 @@ def get_serial_nos_based_on_filters(filters, fields, order_by, kwargs): if kwargs.based_on == "LIFO": query = query.orderby(order_by_column, order=frappe.query_builder.Order.desc) else: + if order_by == "amc_expiry_date": + query = query.orderby(order_by_column.isnull(), order=frappe.query_builder.Order.desc) query = query.orderby(order_by_column) for key, value in filters.items(): diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 11990db26b8..4ec75996608 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -1121,17 +1121,20 @@ def insert_item_price(ctx: ItemDetailsCtx): or getdate() ) - item_prices = frappe.get_all( - "Item Price", - filters={ - "item_code": ctx.item_code, - "price_list": ctx.price_list, - "currency": ctx.currency, - "uom": ctx.stock_uom, - }, - fields=["name", "price_list_rate", "valid_from", "valid_upto"], - order_by="valid_from desc, creation desc", - ) + ip = frappe.qb.DocType("Item Price") + item_prices = ( + frappe.qb.from_(ip) + .select(ip.name, ip.price_list_rate, ip.valid_from, ip.valid_upto) + .where( + (ip.item_code == ctx.item_code) + & (ip.price_list == ctx.price_list) + & (ip.currency == ctx.currency) + & (ip.uom == ctx.stock_uom) + ) + .orderby(ip.valid_from.isnull(), order=frappe.qb.asc) + .orderby(ip.valid_from, order=frappe.qb.desc) + .orderby(ip.creation, order=frappe.qb.desc) + ).run(as_dict=True) item_price = next( ( row @@ -1233,6 +1236,7 @@ def get_item_price( & (ip.price_list == pctx.price_list) & (IfNull(ip.uom, "").isin(["", pctx.uom])) ) + .orderby(ip.valid_from.isnull(), order=frappe.qb.asc) .orderby(ip.valid_from, order=frappe.qb.desc) .orderby(IfNull(ip.batch_no, ""), order=frappe.qb.desc) .orderby(ip.uom, order=frappe.qb.desc)