Merge pull request #28021 from frappe/mergify/bp/version-13-pre-release/pr-28005
fix: Fetch thumbnail from Item master instead of regenerating (backport #28005)
This commit is contained in:
@@ -147,7 +147,7 @@ class WebsiteItem(WebsiteGenerator):
|
||||
|
||||
def make_thumbnail(self):
|
||||
"""Make a thumbnail of `website_image`"""
|
||||
if frappe.flags.in_import:
|
||||
if frappe.flags.in_import or frappe.flags.in_migrate:
|
||||
return
|
||||
|
||||
import requests.exceptions
|
||||
|
||||
@@ -325,3 +325,4 @@ erpnext.patches.v13_0.add_default_interview_notification_templates
|
||||
erpnext.patches.v13_0.trim_sales_invoice_custom_field_length
|
||||
erpnext.patches.v13_0.enable_scheduler_job_for_item_reposting
|
||||
erpnext.patches.v13_0.requeue_failed_reposts
|
||||
erpnext.patches.v13_0.fetch_thumbnail_in_website_items
|
||||
@@ -14,8 +14,9 @@ def execute():
|
||||
item_fields = ["item_code", "item_name", "item_group", "stock_uom", "brand", "image",
|
||||
"has_variants", "variant_of", "description", "weightage"]
|
||||
web_fields_to_map = ["route", "slideshow", "website_image_alt",
|
||||
"website_warehouse", "web_long_description", "website_content"]
|
||||
"website_warehouse", "web_long_description", "website_content", "thumbnail"]
|
||||
|
||||
# get all valid columns (fields) from Item master DB schema
|
||||
item_table_fields = frappe.db.sql("desc `tabItem`", as_dict=1)
|
||||
item_table_fields = [d.get('Field') for d in item_table_fields]
|
||||
|
||||
@@ -42,37 +43,30 @@ def execute():
|
||||
fields=item_fields,
|
||||
or_filters=or_filters
|
||||
)
|
||||
total_count = len(items)
|
||||
|
||||
count = 0
|
||||
for item in items:
|
||||
for count, item in enumerate(items, start=1):
|
||||
if frappe.db.exists("Website Item", {"item_code": item.item_code}):
|
||||
# if website item already exists check for empty thumbnail
|
||||
web_item_doc = frappe.get_doc("Website Item", {"item_code": item.item_code})
|
||||
if web_item_doc.website_image and not web_item_doc.thumbnail:
|
||||
web_item_doc.make_thumbnail()
|
||||
web_item_doc.save()
|
||||
else:
|
||||
# else make new website item from item (publish item)
|
||||
website_item = make_website_item(item, save=False)
|
||||
website_item.ranking = item.get("weightage")
|
||||
for field in web_fields_to_map:
|
||||
website_item.update({field: item.get(field)})
|
||||
website_item.save()
|
||||
continue
|
||||
|
||||
# move Website Item Group & Website Specification table to Website Item
|
||||
for doctype in ("Website Item Group", "Item Website Specification"):
|
||||
web_item, item_code = website_item.name, item.item_code
|
||||
frappe.db.sql(f"""
|
||||
Update
|
||||
`tab{doctype}`
|
||||
set
|
||||
parenttype = 'Website Item',
|
||||
parent = '{web_item}'
|
||||
where
|
||||
parenttype = 'Item'
|
||||
and parent = '{item_code}'
|
||||
""")
|
||||
# make new website item from item (publish item)
|
||||
website_item = make_website_item(item, save=False)
|
||||
website_item.ranking = item.get("weightage")
|
||||
|
||||
for field in web_fields_to_map:
|
||||
website_item.update({field: item.get(field)})
|
||||
|
||||
website_item.save()
|
||||
|
||||
# move Website Item Group & Website Specification table to Website Item
|
||||
for doctype in ("Website Item Group", "Item Website Specification"):
|
||||
frappe.db.set_value(
|
||||
doctype,
|
||||
{"parenttype": "Item", "parent": item.item_code}, # filters
|
||||
{"parenttype": "Website Item", "parent": website_item.name} # value dict
|
||||
)
|
||||
|
||||
count += 1
|
||||
if count % 20 == 0: # commit after every 20 items
|
||||
frappe.db.commit()
|
||||
frappe.db.commit()
|
||||
|
||||
frappe.utils.update_progress_bar('Creating Website Items', count, total_count)
|
||||
16
erpnext/patches/v13_0/fetch_thumbnail_in_website_items.py
Normal file
16
erpnext/patches/v13_0/fetch_thumbnail_in_website_items.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
if frappe.db.has_column("Item", "thumbnail"):
|
||||
website_item = frappe.qb.DocType("Website Item").as_("wi")
|
||||
item = frappe.qb.DocType("Item")
|
||||
|
||||
frappe.qb.update(website_item).inner_join(item).on(
|
||||
website_item.item_code == item.item_code
|
||||
).set(
|
||||
website_item.thumbnail, item.thumbnail
|
||||
).where(
|
||||
website_item.website_image.notnull()
|
||||
& website_item.thumbnail.isnull()
|
||||
).run()
|
||||
Reference in New Issue
Block a user