File api (#15637)

* file-api: major refactor

migrate from file_manager.py to file.py

Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>

* file-api: migrate to file-api

remove file_manager stuff and migrate to file-api

Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
diff --git a/erpnext/accounts/doctype/bank_statement_transaction_entry/bank_statement_transaction_entry.py b/erpnext/accounts/doctype/bank_statement_transaction_entry/bank_statement_transaction_entry.py
index 7a7d7d2..46ee79c 100644
--- a/erpnext/accounts/doctype/bank_statement_transaction_entry/bank_statement_transaction_entry.py
+++ b/erpnext/accounts/doctype/bank_statement_transaction_entry/bank_statement_transaction_entry.py
@@ -405,9 +405,9 @@
 		from frappe.utils.xlsxutils import read_xlsx_file_from_attached_file
 		rows = read_xlsx_file_from_attached_file(file_id=filename)
 	elif (filename.lower().endswith("csv")):
-		from frappe.utils.file_manager import get_file_path
 		from frappe.utils.csvutils import read_csv_content
-		filepath = get_file_path(filename)
+		_file = frappe.get_doc("File", {"file_name": filename})
+		filepath = _file.get_full_path()
 		with open(filepath,'rb') as csvfile:
 			rows = read_csv_content(csvfile.read())
 	elif (filename.lower().endswith("xls")):
@@ -427,8 +427,8 @@
 	return transactions
 
 def get_rows_from_xls_file(filename):
-	from frappe.utils.file_manager import get_file_path
-	filepath = get_file_path(filename)
+	_file = frappe.get_doc("File", {"file_name": filename})
+	filepath = _file.get_full_path()
 	import xlrd
 	book = xlrd.open_workbook(filepath)
 	sheets = book.sheets()
diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py
index 2356401..c236822 100644
--- a/erpnext/hub_node/api.py
+++ b/erpnext/hub_node/api.py
@@ -10,7 +10,6 @@
 from frappe import _
 from frappe.frappeclient import FrappeClient
 from frappe.desk.form.load import get_attachments
-from frappe.utils.file_manager import get_file_path
 from six import string_types
 
 current_user = frappe.session.user
diff --git a/erpnext/patches/v5_4/fix_missing_item_images.py b/erpnext/patches/v5_4/fix_missing_item_images.py
index c0a2513..c6fe578 100644
--- a/erpnext/patches/v5_4/fix_missing_item_images.py
+++ b/erpnext/patches/v5_4/fix_missing_item_images.py
@@ -2,7 +2,7 @@
 import frappe
 import os
 from frappe.utils import get_files_path
-from frappe.utils.file_manager import get_content_hash
+from frappe.core.doctype.file.file import get_content_hash
 
 def execute():
 	files_path = get_files_path()
diff --git a/erpnext/setup/setup_wizard/operations/company_setup.py b/erpnext/setup/setup_wizard/operations/company_setup.py
index 7f9795b..3f0bb14 100644
--- a/erpnext/setup/setup_wizard/operations/company_setup.py
+++ b/erpnext/setup/setup_wizard/operations/company_setup.py
@@ -5,7 +5,6 @@
 import frappe
 from frappe import _
 from frappe.utils import cstr, getdate
-from frappe.utils.file_manager import save_file
 from .default_website import website_maker
 from erpnext.accounts.doctype.account.account import RootNotEditable
 
@@ -107,10 +106,16 @@
 		attach_logo = args.get("attach_logo").split(",")
 		if len(attach_logo)==3:
 			filename, filetype, content = attach_logo
-			fileurl = save_file(filename, content, "Website Settings", "Website Settings",
-				decode=True).file_url
+			_file = frappe.get_doc({
+				"doctype": "File",
+				"file_name": filename,
+				"attached_to_doctype": "Website Settings",
+				"attached_to_name": "Website Settings",
+				"decode": True})
+			_file.save()
+			fileurl = _file.file_url
 			frappe.db.set_value("Website Settings", "Website Settings", "brand_html",
-				"<img src='{0}' style='max-width: 40px; max-height: 25px;'> {1}".format(fileurl, args.get("company_name")	))
+				"<img src='{0}' style='max-width: 40px; max-height: 25px;'> {1}".format(fileurl, args.get("company_name")))
 
 def create_website(args):
 	website_maker(args)
@@ -121,4 +126,4 @@
 		fy = cstr(start_year)
 	else:
 		fy = cstr(start_year) + '-' + cstr(start_year + 1)
-	return fy
\ No newline at end of file
+	return fy
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index 5cbdd4c..73fd30e 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -256,7 +256,7 @@
 						"file_url": self.website_image,
 						"attached_to_doctype": "Item",
 						"attached_to_name": self.name
-					}).insert()
+					}).save()
 
 				except IOError:
 					self.website_image = None