mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-22 14:39:19 +00:00
fix: Fetch thumbnail from Item master instead of regenerating
(cherry picked from commit 94177c0764)
This commit is contained in:
@@ -147,7 +147,7 @@ class WebsiteItem(WebsiteGenerator):
|
|||||||
|
|
||||||
def make_thumbnail(self):
|
def make_thumbnail(self):
|
||||||
"""Make a thumbnail of `website_image`"""
|
"""Make a thumbnail of `website_image`"""
|
||||||
if frappe.flags.in_import:
|
if frappe.flags.in_import or frappe.flags.in_migrate:
|
||||||
return
|
return
|
||||||
|
|
||||||
import requests.exceptions
|
import requests.exceptions
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ def execute():
|
|||||||
item_fields = ["item_code", "item_name", "item_group", "stock_uom", "brand", "image",
|
item_fields = ["item_code", "item_name", "item_group", "stock_uom", "brand", "image",
|
||||||
"has_variants", "variant_of", "description", "weightage"]
|
"has_variants", "variant_of", "description", "weightage"]
|
||||||
web_fields_to_map = ["route", "slideshow", "website_image_alt",
|
web_fields_to_map = ["route", "slideshow", "website_image_alt",
|
||||||
"website_warehouse", "web_long_description", "website_content"]
|
"website_warehouse", "web_long_description", "website_content", "thumbnail"]
|
||||||
|
|
||||||
item_table_fields = frappe.db.sql("desc `tabItem`", as_dict=1)
|
item_table_fields = frappe.db.sql("desc `tabItem`", as_dict=1)
|
||||||
item_table_fields = [d.get('Field') for d in item_table_fields]
|
item_table_fields = [d.get('Field') for d in item_table_fields]
|
||||||
@@ -47,16 +47,26 @@ def execute():
|
|||||||
for item in items:
|
for item in items:
|
||||||
if frappe.db.exists("Website Item", {"item_code": item.item_code}):
|
if frappe.db.exists("Website Item", {"item_code": item.item_code}):
|
||||||
# if website item already exists check for empty thumbnail
|
# if website item already exists check for empty thumbnail
|
||||||
web_item_doc = frappe.get_doc("Website Item", {"item_code": item.item_code})
|
# if empty, fetch thumbnail from Item master
|
||||||
if web_item_doc.website_image and not web_item_doc.thumbnail:
|
web_item_doc = frappe.db.get_values(
|
||||||
web_item_doc.make_thumbnail()
|
"Website Item",
|
||||||
web_item_doc.save()
|
filters={
|
||||||
|
"item_code": item.item_code
|
||||||
|
},
|
||||||
|
fieldname=["website_image", "thumbnail", "name"]
|
||||||
|
)[0]
|
||||||
|
|
||||||
|
if web_item_doc.get("website_image") and not web_item_doc.get("thumbnail"):
|
||||||
|
thumbnail = frappe.db.get_value("Item", item.item_code, "thumbnail")
|
||||||
|
frappe.db.set_value("Website Item", web_item_doc.name, "thumbnail", thumbnail)
|
||||||
else:
|
else:
|
||||||
# else make new website item from item (publish item)
|
# else make new website item from item (publish item)
|
||||||
website_item = make_website_item(item, save=False)
|
website_item = make_website_item(item, save=False)
|
||||||
website_item.ranking = item.get("weightage")
|
website_item.ranking = item.get("weightage")
|
||||||
|
|
||||||
for field in web_fields_to_map:
|
for field in web_fields_to_map:
|
||||||
website_item.update({field: item.get(field)})
|
website_item.update({field: item.get(field)})
|
||||||
|
|
||||||
website_item.save()
|
website_item.save()
|
||||||
|
|
||||||
# move Website Item Group & Website Specification table to Website Item
|
# move Website Item Group & Website Specification table to Website Item
|
||||||
|
|||||||
Reference in New Issue
Block a user