Merge branch 'develop' into subcontracting
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index c71ea36..2610c86 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -322,9 +322,9 @@
 	return frappe.db.sql(
 		"""select name from tabAccount
 		where is_group = 1 and docstatus != 2 and company = %s
-		and %s like %s order by name limit %s, %s"""
+		and %s like %s order by name limit %s offset %s"""
 		% ("%s", searchfield, "%s", "%s", "%s"),
-		(filters["company"], "%%%s%%" % txt, start, page_len),
+		(filters["company"], "%%%s%%" % txt, page_len, start),
 		as_list=1,
 	)
 
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 1451189..8f0fe51 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -1239,7 +1239,7 @@
 			AND jv.docstatus = 1
 			AND jv.`{0}` LIKE %(txt)s
 		ORDER BY jv.name DESC
-		LIMIT %(offset)s, %(limit)s
+		LIMIT %(limit)s offset %(offset)s
 		""".format(
 			searchfield
 		),
diff --git a/erpnext/accounts/doctype/payment_order/payment_order.py b/erpnext/accounts/doctype/payment_order/payment_order.py
index 3c45d20..ff9615d 100644
--- a/erpnext/accounts/doctype/payment_order/payment_order.py
+++ b/erpnext/accounts/doctype/payment_order/payment_order.py
@@ -39,7 +39,7 @@
 	return frappe.db.sql(
 		""" select mode_of_payment from `tabPayment Order Reference`
 		where parent = %(parent)s and mode_of_payment like %(txt)s
-		limit %(start)s, %(page_len)s""",
+		limit %(page_len)s offset %(start)s""",
 		{"parent": filters.get("parent"), "start": start, "page_len": page_len, "txt": "%%%s%%" % txt},
 	)
 
@@ -51,7 +51,7 @@
 		""" select supplier from `tabPayment Order Reference`
 		where parent = %(parent)s and supplier like %(txt)s and
 		(payment_reference is null or payment_reference='')
-		limit %(start)s, %(page_len)s""",
+		limit %(page_len)s offset %(start)s""",
 		{"parent": filters.get("parent"), "start": start, "page_len": page_len, "txt": "%%%s%%" % txt},
 	)
 
diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.py b/erpnext/accounts/doctype/pos_profile/pos_profile.py
index e83dc0f..e8aee73 100644
--- a/erpnext/accounts/doctype/pos_profile/pos_profile.py
+++ b/erpnext/accounts/doctype/pos_profile/pos_profile.py
@@ -173,7 +173,7 @@
 		where
 			pfu.parent = pf.name and pfu.user = %(user)s and pf.company = %(company)s
 			and (pf.name like %(txt)s)
-			and pf.disabled = 0 limit %(start)s, %(page_len)s""",
+			and pf.disabled = 0 limit %(page_len)s offset %(start)s""",
 		args,
 	)
 
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index f4a44bd..e39f22b 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -211,7 +211,7 @@
 	else:
 		party_details.update(get_company_address(company))
 
-	if doctype and doctype in ["Delivery Note", "Sales Invoice", "Sales Order"]:
+	if doctype and doctype in ["Delivery Note", "Sales Invoice", "Sales Order", "Quotation"]:
 		if party_details.company_address:
 			party_details.update(
 				get_fetch_values(doctype, "company_address", party_details.company_address)
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py
index dd10c93..6cf5837 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.py
@@ -197,7 +197,7 @@
 				if not item.fg_item:
 					frappe.throw(
 						_("Row #{0}: Finished Good Item is not specified for service item {1}").format(
-							 item.idx, item.item_code
+							item.idx, item.item_code
 						)
 					)
 				else:
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
index d39aec1..67affe7 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
@@ -285,7 +285,7 @@
 		"""select `tabContact`.name from `tabContact`, `tabDynamic Link`
 		where `tabDynamic Link`.link_doctype = 'Supplier' and (`tabDynamic Link`.link_name=%(name)s
 		and `tabDynamic Link`.link_name like %(txt)s) and `tabContact`.name = `tabDynamic Link`.parent
-		limit %(start)s, %(page_len)s""",
+		limit %(page_len)s offset %(start)s""",
 		{"start": start, "page_len": page_len, "txt": "%%%s%%" % txt, "name": filters.get("supplier")},
 	)
 
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index eeb5a7f..1497b18 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -33,7 +33,7 @@
 			if(locate(%(_txt)s, employee_name), locate(%(_txt)s, employee_name), 99999),
 			idx desc,
 			name, employee_name
-		limit %(start)s, %(page_len)s""".format(
+		limit %(page_len)s offset %(start)s""".format(
 			**{
 				"fields": ", ".join(fields),
 				"key": searchfield,
@@ -65,7 +65,7 @@
 			if(locate(%(_txt)s, company_name), locate(%(_txt)s, company_name), 99999),
 			idx desc,
 			name, lead_name
-		limit %(start)s, %(page_len)s""".format(
+		limit %(page_len)s offset %(start)s""".format(
 			**{"fields": ", ".join(fields), "key": searchfield, "mcond": get_match_cond(doctype)}
 		),
 		{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
@@ -100,7 +100,7 @@
 			if(locate(%(_txt)s, customer_name), locate(%(_txt)s, customer_name), 99999),
 			idx desc,
 			name, customer_name
-		limit %(start)s, %(page_len)s""".format(
+		limit %(page_len)s offset %(start)s""".format(
 			**{
 				"fields": ", ".join(fields),
 				"scond": searchfields,
@@ -137,7 +137,7 @@
 			if(locate(%(_txt)s, supplier_name), locate(%(_txt)s, supplier_name), 99999),
 			idx desc,
 			name, supplier_name
-		limit %(start)s, %(page_len)s """.format(
+		limit %(page_len)s offset %(start)s""".format(
 			**{"field": ", ".join(fields), "key": searchfield, "mcond": get_match_cond(doctype)}
 		),
 		{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
@@ -167,7 +167,7 @@
 				AND `{searchfield}` LIKE %(txt)s
 				{mcond}
 			ORDER BY idx DESC, name
-			LIMIT %(offset)s, %(limit)s
+			LIMIT %(limit)s offset %(offset)s
 		""".format(
 				account_type_condition=account_type_condition,
 				searchfield=searchfield,
@@ -351,7 +351,7 @@
 			if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
 			idx desc,
 			`tabProject`.name asc
-		limit {start}, {page_len}""".format(
+		limit {page_len} offset {start}""".format(
 			fields=", ".join(["`tabProject`.{0}".format(f) for f in fields]),
 			cond=cond,
 			scond=searchfields,
@@ -383,7 +383,7 @@
 					and return_against in (select name from `tabDelivery Note` where per_billed < 100)
 				)
 			)
-			%(mcond)s order by `tabDelivery Note`.`%(key)s` asc limit %(start)s, %(page_len)s
+			%(mcond)s order by `tabDelivery Note`.`%(key)s` asc limit %(page_len)s offset %(start)s
 	"""
 		% {
 			"fields": ", ".join(["`tabDelivery Note`.{0}".format(f) for f in fields]),
@@ -456,7 +456,7 @@
 				{match_conditions}
 			group by batch_no {having_clause}
 			order by batch.expiry_date, sle.batch_no desc
-			limit %(start)s, %(page_len)s""".format(
+			limit %(page_len)s offset %(start)s""".format(
 				search_columns=search_columns,
 				cond=cond,
 				match_conditions=get_match_cond(doctype),
@@ -483,7 +483,7 @@
 			{match_conditions}
 
 			order by expiry_date, name desc
-			limit %(start)s, %(page_len)s""".format(
+			limit %(page_len)s offset %(start)s""".format(
 				cond,
 				search_columns=search_columns,
 				search_cond=search_cond,
@@ -662,7 +662,7 @@
 			{fcond} {mcond}
 		order by ifnull(`tabBin`.actual_qty, 0) desc
 		limit
-			{start}, {page_len}
+			{page_len} offset {start}
 		""".format(
 		bin_conditions=get_filters_cond(
 			doctype, filter_dict.get("Bin"), bin_conditions, ignore_permissions=True
diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py
index 3c0a10e..517e080 100644
--- a/erpnext/controllers/status_updater.py
+++ b/erpnext/controllers/status_updater.py
@@ -35,7 +35,8 @@
 		["Draft", None],
 		["Open", "eval:self.docstatus==1"],
 		["Lost", "eval:self.status=='Lost'"],
-		["Ordered", "has_sales_order"],
+		["Partially Ordered", "is_partially_ordered"],
+		["Ordered", "is_fully_ordered"],
 		["Cancelled", "eval:self.docstatus==2"],
 	],
 	"Sales Order": [
diff --git a/erpnext/controllers/tests/test_subcontracting_controller.py b/erpnext/controllers/tests/test_subcontracting_controller.py
index cbdd191..4ef3d64 100644
--- a/erpnext/controllers/tests/test_subcontracting_controller.py
+++ b/erpnext/controllers/tests/test_subcontracting_controller.py
@@ -724,6 +724,57 @@
 			self.assertEqual(value.qty, details.qty)
 			self.assertEqual(value.batch_no, details.batch_no)
 
+	def test_sco_supplied_qty(self):
+		"""
+		Check if 'Supplied Qty' in SCO's Supplied Items table is reset on submit/cancel.
+		"""
+		set_backflush_based_on("Material Transferred for Subcontract")
+		service_items = [
+			{
+				"warehouse": "_Test Warehouse - _TC",
+				"item_code": "Subcontracted Service Item 1",
+				"qty": 5,
+				"rate": 100,
+				"fg_item": "Subcontracted Item SA1",
+				"fg_item_qty": 5,
+			},
+			{
+				"warehouse": "_Test Warehouse - _TC",
+				"item_code": "Subcontracted Service Item 5",
+				"qty": 6,
+				"rate": 100,
+				"fg_item": "Subcontracted Item SA5",
+				"fg_item_qty": 6,
+			},
+		]
+		sco = get_subcontracting_order(service_items=service_items)
+		rm_items = [
+			{"item_code": "Subcontracted SRM Item 1", "qty": 5, "main_item_code": "Subcontracted Item SA1"},
+			{"item_code": "Subcontracted SRM Item 2", "qty": 5, "main_item_code": "Subcontracted Item SA1"},
+			{"item_code": "Subcontracted SRM Item 3", "qty": 5, "main_item_code": "Subcontracted Item SA1"},
+			{"item_code": "Subcontracted SRM Item 5", "qty": 6, "main_item_code": "Subcontracted Item SA5"},
+			{"item_code": "Subcontracted SRM Item 4", "qty": 6, "main_item_code": "Subcontracted Item SA5"},
+		]
+		itemwise_details = make_stock_in_entry(rm_items=rm_items)
+
+		for item in rm_items:
+			item["sco_rm_detail"] = sco.items[0].name if item.get("qty") == 5 else sco.items[1].name
+
+		se = make_stock_transfer_entry(
+			sco_no=sco.name,
+			rm_items=rm_items,
+			itemwise_details=copy.deepcopy(itemwise_details),
+		)
+
+		sco.reload()
+		for item in sco.get("supplied_items"):
+			self.assertIn(item.supplied_qty, [5.0, 6.0])
+
+		se.cancel()
+		sco.reload()
+		for item in sco.get("supplied_items"):
+			self.assertEqual(item.supplied_qty, 0.0)
+
 
 def add_second_row_in_scr(scr):
 	item_dict = {}
diff --git a/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.py b/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.py
index 3fe2198..da28343 100644
--- a/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.py
+++ b/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.py
@@ -102,7 +102,7 @@
 	return frappe.db.sql(
 		"""select name from `tabWork Order`
 		where name like %(name)s and {0} and produced_qty > qty and docstatus = 1
-		order by name limit {1}, {2}""".format(
+		order by name limit {2} offset {1}""".format(
 			cond, start, page_len
 		),
 		{"name": "%%%s%%" % txt},
diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py
index 620fcad..1524fb7 100644
--- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py
+++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py
@@ -970,7 +970,7 @@
 		and name not in
 			(select reference_name from `tabJournal Entry Account`
 				where reference_type="Payroll Entry")
-		order by name limit %(start)s, %(page_len)s""".format(
+		order by name limit %(page_len)s offset %(start)s""".format(
 			key=searchfield
 		),
 		{"txt": "%%%s%%" % txt, "start": start, "page_len": page_len},
@@ -1039,7 +1039,7 @@
 			if(locate(%(_txt)s, employee_name), locate(%(_txt)s, employee_name), 99999),
 			idx desc,
 			name, employee_name
-		limit %(start)s, %(page_len)s""".format(
+		limit %(page_len)s offset %(start)s""".format(
 			**{
 				"key": searchfield,
 				"fcond": get_filters_cond(doctype, filters, conditions),
diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py
index 8a8e1d1..c613fe6 100644
--- a/erpnext/projects/doctype/project/project.py
+++ b/erpnext/projects/doctype/project/project.py
@@ -391,7 +391,7 @@
 			if(locate(%(_txt)s, full_name), locate(%(_txt)s, full_name), 99999),
 			idx desc,
 			name, full_name
-		limit %(start)s, %(page_len)s""".format(
+		limit %(page_len)s offset %(start)s""".format(
 			**{
 				"key": searchfield,
 				"fcond": get_filters_cond(doctype, filters, conditions),
diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py
index 4575fb5..0e409fc 100755
--- a/erpnext/projects/doctype/task/task.py
+++ b/erpnext/projects/doctype/task/task.py
@@ -288,7 +288,7 @@
 			%(mcond)s
 			{search_condition}
 		order by name
-		limit %(start)s, %(page_len)s""".format(
+		limit %(page_len)s offset %(start)s""".format(
 			search_columns=search_columns, search_condition=search_cond
 		),
 		{
diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py
index 2ef966b..88d5bee 100644
--- a/erpnext/projects/doctype/timesheet/timesheet.py
+++ b/erpnext/projects/doctype/timesheet/timesheet.py
@@ -328,7 +328,7 @@
 			ts.status in ('Submitted', 'Payslip') and tsd.parent = ts.name and
 			tsd.docstatus = 1 and ts.total_billable_amount > 0
 			and tsd.parent LIKE %(txt)s {condition}
-			order by tsd.parent limit %(start)s, %(page_len)s""".format(
+			order by tsd.parent limit %(page_len)s offset %(start)s""".format(
 			condition=condition
 		),
 		{
@@ -515,7 +515,7 @@
 					tsd.project IN %(projects)s
 				)
 			ORDER BY `end_date` ASC
-			LIMIT {0}, {1}
+			LIMIT {1} offset {0}
 		""".format(
 				limit_start, limit_page_length
 			),
diff --git a/erpnext/projects/utils.py b/erpnext/projects/utils.py
index 000ea66..3cc4da4 100644
--- a/erpnext/projects/utils.py
+++ b/erpnext/projects/utils.py
@@ -25,7 +25,7 @@
 			case when `%s` like %s then 0 else 1 end,
 			`%s`,
 			subject
-		limit %s, %s"""
+		limit %s offset %s"""
 		% (searchfield, "%s", "%s", match_conditions, "%s", searchfield, "%s", searchfield, "%s", "%s"),
-		(search_string, search_string, order_by_string, order_by_string, start, page_len),
+		(search_string, search_string, order_by_string, order_by_string, page_len, start),
 	)
diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py
index ee48ccb..0262469 100644
--- a/erpnext/regional/india/utils.py
+++ b/erpnext/regional/india/utils.py
@@ -287,7 +287,7 @@
 		return party_details
 
 	if (
-		doctype in ("Sales Invoice", "Delivery Note", "Sales Order")
+		doctype in ("Sales Invoice", "Delivery Note", "Sales Order", "Quotation")
 		and party_details.company_gstin
 		and party_details.company_gstin[:2] != party_details.place_of_supply[:2]
 	) or (
diff --git a/erpnext/selling/doctype/product_bundle/product_bundle.py b/erpnext/selling/doctype/product_bundle/product_bundle.py
index 575b956..ac83c0f 100644
--- a/erpnext/selling/doctype/product_bundle/product_bundle.py
+++ b/erpnext/selling/doctype/product_bundle/product_bundle.py
@@ -78,7 +78,7 @@
 	return frappe.db.sql(
 		"""select name, item_name, description from tabItem
 		where is_stock_item=0 and name not in (select name from `tabProduct Bundle`)
-		and %s like %s %s limit %s, %s"""
+		and %s like %s %s limit %s offset %s"""
 		% (searchfield, "%s", get_match_cond(doctype), "%s", "%s"),
-		("%%%s%%" % txt, start, page_len),
+		("%%%s%%" % txt, page_len, start),
 	)
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index 34e9a52..70ae085 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -20,6 +20,20 @@
 
 		frm.set_df_property('packed_items', 'cannot_add_rows', true);
 		frm.set_df_property('packed_items', 'cannot_delete_rows', true);
+
+		frm.set_query('company_address', function(doc) {
+			if(!doc.company) {
+				frappe.throw(__('Please set Company'));
+			}
+
+			return {
+				query: 'frappe.contacts.doctype.address.address.address_query',
+				filters: {
+					link_doctype: 'Company',
+					link_name: doc.company
+				}
+			};
+		});
 	},
 
 	refresh: function(frm) {
@@ -70,7 +84,7 @@
 			}
 		}
 
-		if(doc.docstatus == 1 && doc.status!=='Lost') {
+		if(doc.docstatus == 1 && !(['Lost', 'Ordered']).includes(doc.status)) {
 			if(!doc.valid_till || frappe.datetime.get_diff(doc.valid_till, frappe.datetime.get_today()) >= 0) {
 				cur_frm.add_custom_button(__('Sales Order'),
 					cur_frm.cscript['Make Sales Order'], __('Create'));
diff --git a/erpnext/selling/doctype/quotation/quotation.json b/erpnext/selling/doctype/quotation/quotation.json
index 75443ab..5dfd8f2 100644
--- a/erpnext/selling/doctype/quotation/quotation.json
+++ b/erpnext/selling/doctype/quotation/quotation.json
@@ -897,7 +897,7 @@
    "no_copy": 1,
    "oldfieldname": "status",
    "oldfieldtype": "Select",
-   "options": "Draft\nOpen\nReplied\nOrdered\nLost\nCancelled\nExpired",
+   "options": "Draft\nOpen\nReplied\nPartially Ordered\nOrdered\nLost\nCancelled\nExpired",
    "print_hide": 1,
    "read_only": 1,
    "reqd": 1
@@ -986,7 +986,7 @@
  "idx": 82,
  "is_submittable": 1,
  "links": [],
- "modified": "2022-04-07 11:01:31.157084",
+ "modified": "2022-06-11 20:35:32.635804",
  "modified_by": "Administrator",
  "module": "Selling",
  "name": "Quotation",
diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py
index 548813d..d5fd946 100644
--- a/erpnext/selling/doctype/quotation/quotation.py
+++ b/erpnext/selling/doctype/quotation/quotation.py
@@ -70,8 +70,32 @@
 					title=_("Unpublished Item"),
 				)
 
-	def has_sales_order(self):
-		return frappe.db.get_value("Sales Order Item", {"prevdoc_docname": self.name, "docstatus": 1})
+	def get_ordered_status(self):
+		ordered_items = frappe._dict(
+			frappe.db.get_all(
+				"Sales Order Item",
+				{"prevdoc_docname": self.name, "docstatus": 1},
+				["item_code", "sum(qty)"],
+				group_by="item_code",
+				as_list=1,
+			)
+		)
+
+		status = "Open"
+		if ordered_items:
+			status = "Ordered"
+
+			for item in self.get("items"):
+				if item.qty > ordered_items.get(item.item_code, 0.0):
+					status = "Partially Ordered"
+
+		return status
+
+	def is_fully_ordered(self):
+		return self.get_ordered_status() == "Ordered"
+
+	def is_partially_ordered(self):
+		return self.get_ordered_status() == "Partially Ordered"
 
 	def update_lead(self):
 		if self.quotation_to == "Lead" and self.party_name:
diff --git a/erpnext/selling/doctype/quotation/quotation_list.js b/erpnext/selling/doctype/quotation/quotation_list.js
index 4c8f9c4..32fce1f 100644
--- a/erpnext/selling/doctype/quotation/quotation_list.js
+++ b/erpnext/selling/doctype/quotation/quotation_list.js
@@ -25,6 +25,8 @@
 	get_indicator: function(doc) {
 		if(doc.status==="Open") {
 			return [__("Open"), "orange", "status,=,Open"];
+		} else if (doc.status==="Partially Ordered") {
+			return [__("Partially Ordered"), "yellow", "status,=,Partially Ordered"];
 		} else if(doc.status==="Ordered") {
 			return [__("Ordered"), "green", "status,=,Ordered"];
 		} else if(doc.status==="Lost") {
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 99afe81..13d5069 100644
--- a/erpnext/selling/page/point_of_sale/point_of_sale.py
+++ b/erpnext/selling/page/point_of_sale/point_of_sale.py
@@ -107,7 +107,7 @@
 		ORDER BY
 			item.name asc
 		LIMIT
-			{start}, {page_length}""".format(
+			{page_length} offset {start}""".format(
 			start=start,
 			page_length=page_length,
 			lft=lft,
@@ -204,7 +204,7 @@
 
 	return frappe.db.sql(
 		""" select distinct name from `tabItem Group`
-			where {condition} and (name like %(txt)s) limit {start}, {page_len}""".format(
+			where {condition} and (name like %(txt)s) limit {page_len} offset {start}""".format(
 			condition=cond, start=start, page_len=page_len
 		),
 		{"txt": "%%%s%%" % txt},
diff --git a/erpnext/setup/doctype/party_type/party_type.py b/erpnext/setup/doctype/party_type/party_type.py
index d07ab08..cf7cba8 100644
--- a/erpnext/setup/doctype/party_type/party_type.py
+++ b/erpnext/setup/doctype/party_type/party_type.py
@@ -21,7 +21,7 @@
 	return frappe.db.sql(
 		"""select name from `tabParty Type`
 			where `{key}` LIKE %(txt)s {cond}
-			order by name limit %(start)s, %(page_len)s""".format(
+			order by name limit %(page_len)s offset %(start)s""".format(
 			key=searchfield, cond=cond
 		),
 		{"txt": "%" + txt + "%", "start": start, "page_len": page_len},
diff --git a/erpnext/stock/doctype/item_alternative/item_alternative.py b/erpnext/stock/doctype/item_alternative/item_alternative.py
index 0f93bb9..fb1a28d 100644
--- a/erpnext/stock/doctype/item_alternative/item_alternative.py
+++ b/erpnext/stock/doctype/item_alternative/item_alternative.py
@@ -77,7 +77,7 @@
 		union
 			(select item_code from `tabItem Alternative`
 			where alternative_item_code = %(item_code)s and item_code like %(txt)s
-			and two_way = 1) limit {0}, {1}
+			and two_way = 1) limit {1} offset {0}
 		""".format(
 			start, page_len
 		),
diff --git a/erpnext/stock/doctype/packing_slip/packing_slip.py b/erpnext/stock/doctype/packing_slip/packing_slip.py
index e9ccf5f..e5b9de8 100644
--- a/erpnext/stock/doctype/packing_slip/packing_slip.py
+++ b/erpnext/stock/doctype/packing_slip/packing_slip.py
@@ -203,7 +203,7 @@
 				where name in ( select item_code FROM `tabDelivery Note Item`
 	 						where parent= %s)
 	 			and %s like "%s" %s
-	 			limit  %s, %s """
+	 			limit  %s offset %s """
 		% ("%s", searchfield, "%s", get_match_cond(doctype), "%s", "%s"),
-		((filters or {}).get("delivery_note"), "%%%s%%" % txt, start, page_len),
+		((filters or {}).get("delivery_note"), "%%%s%%" % txt, page_len, start),
 	)
diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.py b/erpnext/stock/doctype/quality_inspection/quality_inspection.py
index 331d3e8..13abfad 100644
--- a/erpnext/stock/doctype/quality_inspection/quality_inspection.py
+++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.py
@@ -232,7 +232,7 @@
 					FROM `tab{doc}`
 					WHERE parent=%(parent)s and docstatus < 2 and item_code like %(txt)s
 					{qi_condition} {cond} {mcond}
-					ORDER BY item_code limit {start}, {page_len}
+					ORDER BY item_code limit {page_len} offset {start}
 				""".format(
 					doc=filters.get("from"),
 					cond=cond,
@@ -252,7 +252,7 @@
 					WHERE name = %(reference_name)s and docstatus < 2 and production_item like %(txt)s
 					{qi_condition} {cond} {mcond}
 					ORDER BY production_item
-					LIMIT {start}, {page_len}
+					limit {page_len} offset {start}
 				""".format(
 					doc=filters.get("from"),
 					cond=cond,
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 19f0561..6599edd 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -2005,24 +2005,30 @@
 		):
 
 			# Get SCO Supplied Items Details
-			parent = frappe.qb.DocType("Subcontracting Order")
-			child = frappe.qb.DocType("Subcontracting Order Supplied Item")
-			item_wh = (
-				frappe.qb.from_(parent)
-				.inner_join(child)
-				.on(parent.name == child.parent)
-				.select(child.rm_item_code, child.reserve_warehouse)
-				.where(parent.name == self.subcontracting_order)
-			).run(as_list=True)
+			sco_supplied_items = frappe.db.get_all(
+				"Subcontracting Order Supplied Item",
+				filters={"parent": self.subcontracting_order},
+				fields=["name", "rm_item_code", "reserve_warehouse"],
+			)
 
-			item_wh = frappe._dict(item_wh)
-
+			# Get Items Supplied in Stock Entries against SCO
 			supplied_items = get_supplied_items(self.subcontracting_order)
-			for name, item in supplied_items.items():
-				frappe.db.set_value("Subcontracting Order Supplied Item", name, item)
 
-			# Update reserved sub contracted quantity in bin based on Supplied Item Details and
+			for row in sco_supplied_items:
+				key, item = row.name, {}
+				if not supplied_items.get(key):
+					# no stock transferred against SCO Supplied Items row
+					item = {"supplied_qty": 0, "returned_qty": 0, "total_supplied_qty": 0}
+				else:
+					item = supplied_items.get(key)
+
+				frappe.db.set_value("Subcontracting Order Supplied Item", row.name, item)
+
+			# RM Item-Reserve Warehouse Dict
+			item_wh = {x.get("rm_item_code"): x.get("reserve_warehouse") for x in sco_supplied_items}
+
 			for d in self.get("items"):
+				# Update reserved sub contracted quantity in bin based on Supplied Item Details and
 				item_code = d.get("original_item") or d.get("item_code")
 				reserve_warehouse = item_wh.get(item_code)
 				if not (reserve_warehouse and item_code):
diff --git a/erpnext/templates/pages/product_search.py b/erpnext/templates/pages/product_search.py
index 3ed056f..0768cc3 100644
--- a/erpnext/templates/pages/product_search.py
+++ b/erpnext/templates/pages/product_search.py
@@ -56,7 +56,10 @@
 		search = "%" + cstr(search) + "%"
 
 	# order by
-	query += """ ORDER BY ranking desc, modified desc limit %s, %s""" % (cint(start), cint(limit))
+	query += """ ORDER BY ranking desc, modified desc limit %s offset %s""" % (
+		cint(limit),
+		cint(start),
+	)
 
 	return frappe.db.sql(query, {"search": search}, as_dict=1)  # nosemgrep
 
diff --git a/erpnext/utilities/bot.py b/erpnext/utilities/bot.py
deleted file mode 100644
index 5c2e576..0000000
--- a/erpnext/utilities/bot.py
+++ /dev/null
@@ -1,46 +0,0 @@
-# Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and Contributors
-# See license.txt
-
-
-import frappe
-from frappe import _
-from frappe.utils.bot import BotParser
-
-
-class FindItemBot(BotParser):
-	def get_reply(self):
-		if self.startswith("where is", "find item", "locate"):
-			if not frappe.has_permission("Warehouse"):
-				raise frappe.PermissionError
-
-			item = "%{0}%".format(self.strip_words(self.query, "where is", "find item", "locate"))
-			items = frappe.db.sql(
-				"""select name from `tabItem` where item_code like %(txt)s
-				or item_name like %(txt)s or description like %(txt)s""",
-				dict(txt=item),
-			)
-
-			if items:
-				out = []
-				warehouses = frappe.get_all("Warehouse")
-				for item in items:
-					found = False
-					for warehouse in warehouses:
-						qty = frappe.db.get_value(
-							"Bin", {"item_code": item[0], "warehouse": warehouse.name}, "actual_qty"
-						)
-						if qty:
-							out.append(
-								_("{0} units of [{1}](/app/Form/Item/{1}) found in [{2}](/app/Form/Warehouse/{2})").format(
-									qty, item[0], warehouse.name
-								)
-							)
-							found = True
-
-					if not found:
-						out.append(_("[{0}](/app/Form/Item/{0}) is out of stock").format(item[0]))
-
-				return "\n\n".join(out)
-
-			else:
-				return _("Did not find any item called {0}").format(item)