chore: Code Cleanup

- Validate capacity < stock level only on new rule
- Mention stock uom while validating capacity in new rule
- Separate function to format and display unassigned items
- Format ORM args
diff --git a/erpnext/stock/doctype/putaway_rule/putaway_rule.py b/erpnext/stock/doctype/putaway_rule/putaway_rule.py
index 73534aa..606e190 100644
--- a/erpnext/stock/doctype/putaway_rule/putaway_rule.py
+++ b/erpnext/stock/doctype/putaway_rule/putaway_rule.py
@@ -38,10 +38,13 @@
 				title=_("Invalid Warehouse"))
 
 	def validate_capacity(self):
+		stock_uom = frappe.db.get_value("Item", self.item_code, "stock_uom")
 		balance_qty = get_stock_balance(self.item_code, self.warehouse, nowdate())
-		if flt(self.stock_capacity) < flt(balance_qty):
-			frappe.throw(_("Warehouse Capacity for Item '{0}' must be greater than the existing stock level of {1} qty.")
-				.format(self.item_code, frappe.bold(balance_qty)), title=_("Insufficient Capacity"))
+
+		if flt(self.stock_capacity) < flt(balance_qty) and self.get('__islocal'):
+			frappe.throw(_("Warehouse Capacity for Item '{0}' must be greater than the existing stock level of {1} {2}.")
+				.format(self.item_code, frappe.bold(balance_qty), stock_uom),
+				title=_("Insufficient Capacity"))
 
 		if not self.capacity:
 			frappe.throw(_("Capacity must be greater than 0"), title=_("Invalid"))
@@ -49,10 +52,10 @@
 	def set_stock_capacity(self):
 		self.stock_capacity = (flt(self.conversion_factor) or 1) * flt(self.capacity)
 
-@frappe.whitelist()
 def get_ordered_putaway_rules(item_code, company):
 	"""Returns an ordered list of putaway rules to apply on an item."""
-	rules = frappe.get_all("Putaway Rule", fields=["name", "item_code", "stock_capacity", "priority", "warehouse"],
+	rules = frappe.get_all("Putaway Rule",
+		fields=["name", "item_code", "stock_capacity", "priority", "warehouse"],
 		filters={"item_code": item_code, "company": company, "disable": 0},
 		order_by="priority asc, capacity desc")
 
@@ -145,27 +148,29 @@
 			items_not_accomodated.append([item.item_code, pending_qty])
 
 	if items_not_accomodated:
-		msg = _("The following Items, having Putaway Rules, could not be accomodated:") + "<br><br>"
-		formatted_item_rows = ""
-
-		for entry in items_not_accomodated:
-			item_link = frappe.utils.get_link_to_form("Item", entry[0])
-			formatted_item_rows += """
-				<td>{0}</td>
-				<td>{1}</td>
-			</tr>""".format(item_link, frappe.bold(entry[1]))
-
-		msg += """
-			<table class="table">
-				<thead>
-					<td>{0}</td>
-					<td>{1}</td>
-				</thead>
-				{2}
-			</table>
-		""".format(_("Item"), _("Unassigned Qty"), formatted_item_rows)
-
-		frappe.msgprint(msg, title=_("Insufficient Capacity"), is_minimizable=True, wide=True)
+		format_unassigned_items_error(items_not_accomodated)
 
 	return updated_table if updated_table else items
-	# TODO: check pricing rule, item tax impact
\ No newline at end of file
+
+def format_unassigned_items_error(items_not_accomodated):
+	msg = _("The following Items, having Putaway Rules, could not be accomodated:") + "<br><br>"
+	formatted_item_rows = ""
+
+	for entry in items_not_accomodated:
+		item_link = frappe.utils.get_link_to_form("Item", entry[0])
+		formatted_item_rows += """
+			<td>{0}</td>
+			<td>{1}</td>
+		</tr>""".format(item_link, frappe.bold(entry[1]))
+
+	msg += """
+		<table class="table">
+			<thead>
+				<td>{0}</td>
+				<td>{1}</td>
+			</thead>
+			{2}
+		</table>
+	""".format(_("Item"), _("Unassigned Qty"), formatted_item_rows)
+
+	frappe.msgprint(msg, title=_("Insufficient Capacity"), is_minimizable=True, wide=True)
\ No newline at end of file