From 905c0ff9783e516837d06c31beb99fd70118370f Mon Sep 17 00:00:00 2001 From: Chinmay Pai Date: Mon, 15 Oct 2018 05:08:53 +0000 Subject: [PATCH] File api (#15637) * file-api: major refactor migrate from file_manager.py to file.py Signed-off-by: Chinmay Pai * file-api: migrate to file-api remove file_manager stuff and migrate to file-api Signed-off-by: Chinmay Pai --- .../bank_statement_transaction_entry.py | 8 ++++---- erpnext/hub_node/api.py | 1 - erpnext/patches/v5_4/fix_missing_item_images.py | 2 +- .../setup_wizard/operations/company_setup.py | 15 ++++++++++----- erpnext/stock/doctype/item/item.py | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) 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 7a7d7d226c8..46ee79c9c94 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 @@ def get_transaction_entries(filename, headers): 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 @@ def get_transaction_entries(filename, headers): 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 23564010e7d..c236822490d 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -10,7 +10,6 @@ import requests 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 c0a25132ff2..c6fe57896fa 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 @@ from __future__ import print_function, unicode_literals 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 7f9795bcfd3..3f0bb146499 100644 --- a/erpnext/setup/setup_wizard/operations/company_setup.py +++ b/erpnext/setup/setup_wizard/operations/company_setup.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals 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 @@ def create_logo(args): 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", - " {1}".format(fileurl, args.get("company_name") )) + " {1}".format(fileurl, args.get("company_name"))) def create_website(args): website_maker(args) @@ -121,4 +126,4 @@ def get_fy_details(fy_start_date, fy_end_date): 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 5cbdd4c04db..73fd30e37b7 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -256,7 +256,7 @@ class Item(WebsiteGenerator): "file_url": self.website_image, "attached_to_doctype": "Item", "attached_to_name": self.name - }).insert() + }).save() except IOError: self.website_image = None