[Fix] BOM update tool, too many writes in one request. Please send smaller requests (#15432)

diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py
index a515724..93cabb0 100644
--- a/erpnext/accounts/doctype/sales_invoice/pos.py
+++ b/erpnext/accounts/doctype/sales_invoice/pos.py
@@ -506,7 +506,7 @@
 			frappe.db.commit()
 			name_list.append(name)
 	except Exception:
-		frappe.log_error(frappe.get_traceback())
 		frappe.db.rollback()
+		frappe.log_error(frappe.get_traceback())
 
 	return name_list
diff --git a/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py b/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py
index c91bb8f..3f6cb44 100644
--- a/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py
+++ b/erpnext/manufacturing/doctype/bom_update_tool/bom_update_tool.py
@@ -16,16 +16,23 @@
 		self.update_new_bom()
 		bom_list = self.get_parent_boms(self.new_bom)
 		updated_bom = []
+
 		for bom in bom_list:
-			bom_obj = frappe.get_doc("BOM", bom)
-			bom_obj.get_doc_before_save()
-			updated_bom = bom_obj.update_cost_and_exploded_items(updated_bom)
-			bom_obj.calculate_cost()
-			bom_obj.update_parent_cost()
-			bom_obj.db_update()
-			if (getattr(bom_obj.meta, 'track_changes', False)
-				and bom_obj._doc_before_save and not bom_obj.flags.ignore_version):
-				bom_obj.save_version()
+			try:
+				bom_obj = frappe.get_doc("BOM", bom)
+				bom_obj.get_doc_before_save()
+				updated_bom = bom_obj.update_cost_and_exploded_items(updated_bom)
+				bom_obj.calculate_cost()
+				bom_obj.update_parent_cost()
+				bom_obj.db_update()
+				if (getattr(bom_obj.meta, 'track_changes', False)
+					and bom_obj._doc_before_save and not bom_obj.flags.ignore_version):
+					bom_obj.save_version()
+
+				frappe.db.commit()
+			except Exception:
+				frappe.db.rollback()
+				frappe.log_error(frappe.get_traceback())
 
 	def validate_bom(self):
 		if cstr(self.current_bom) == cstr(self.new_bom):