diff --git a/erpnext/patches.txt b/erpnext/patches.txt index b36f74b959..aec2f26908 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -228,3 +228,4 @@ erpnext.patches.v6_4.set_user_in_contact erpnext.patches.v6_4.make_image_thumbnail #2015-10-20 erpnext.patches.v6_5.show_in_website_for_template_item erpnext.patches.v6_4.fix_expense_included_in_valuation +erpnext.patches.v6_6.fix_website_image diff --git a/erpnext/patches/v6_6/__init__.py b/erpnext/patches/v6_6/__init__.py new file mode 100644 index 0000000000..baffc48825 --- /dev/null +++ b/erpnext/patches/v6_6/__init__.py @@ -0,0 +1 @@ +from __future__ import unicode_literals diff --git a/erpnext/patches/v6_6/fix_website_image.py b/erpnext/patches/v6_6/fix_website_image.py new file mode 100644 index 0000000000..b3b4cab18a --- /dev/null +++ b/erpnext/patches/v6_6/fix_website_image.py @@ -0,0 +1,32 @@ +from __future__ import unicode_literals +import frappe +from frappe.utils import encode + +def execute(): + """Fix the File records created via item.py even if the website_image file didn't exist""" + for item in frappe.db.sql_list("""select name from `tabItem` + where website_image is not null and website_image != '' + and website_image like '/files/%' + and exists ( + select name from `tabFile` + where attached_to_doctype='Item' + and attached_to_name=`tabItem`.name + and file_url=`tabItem`.website_image + and (file_name is null or file_name = '') + )"""): + + item = frappe.get_doc("Item", item) + file = frappe.get_doc("File", { + "attached_to_doctype": "Item", + "attached_to_name": item.name, + "file_url": item.website_image + }) + + try: + file.validate_file() + except IOError: + print encode(item.website_image), "does not exist" + file.delete() + item.db_set("website_image", None, update_modified=False) + + diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 0f1f0e0808..c62195767b 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -104,12 +104,16 @@ class Item(WebsiteGenerator): # for CSV import if not file_doc: - file_doc = frappe.get_doc({ - "doctype": "File", - "file_url": self.website_image, - "attached_to_doctype": "Item", - "attached_to_name": self.name - }).insert() + try: + file_doc = frappe.get_doc({ + "doctype": "File", + "file_url": self.website_image, + "attached_to_doctype": "Item", + "attached_to_name": self.name + }).insert() + + except IOError: + self.website_image = None if file_doc: if not file_doc.thumbnail_url: