[fix] validate that Item's website image is public
This commit is contained in:
parent
2af44ffd06
commit
b3051ab84d
@ -10,6 +10,9 @@ frappe.ui.form.on("Item", {
|
||||
frm.fields_dict["attributes"].grid.set_column_disp("attribute_value", true);
|
||||
}
|
||||
|
||||
// should never check Private
|
||||
frm.fields_dict["website_image"].df.is_private = 0;
|
||||
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
|
@ -47,8 +47,6 @@ class Item(WebsiteGenerator):
|
||||
|
||||
if not self.stock_uom:
|
||||
msgprint(_("Please enter default Unit of Measure"), raise_exception=1)
|
||||
if self.image and not self.website_image:
|
||||
self.website_image = self.image
|
||||
|
||||
self.check_warehouse_is_set_for_stock_item()
|
||||
self.validate_uom()
|
||||
@ -68,6 +66,7 @@ class Item(WebsiteGenerator):
|
||||
self.validate_has_variants()
|
||||
self.validate_attributes()
|
||||
self.validate_variant_attributes()
|
||||
self.validate_website_image()
|
||||
self.make_thumbnail()
|
||||
|
||||
if not self.get("__islocal"):
|
||||
@ -83,6 +82,29 @@ class Item(WebsiteGenerator):
|
||||
self.update_variants()
|
||||
self.update_template_item()
|
||||
|
||||
def validate_website_image(self):
|
||||
"""Validate if the website image is a public file"""
|
||||
auto_set_website_image = False
|
||||
if not self.website_image and self.image:
|
||||
auto_set_website_image = True
|
||||
self.website_image = self.image
|
||||
|
||||
file = frappe.db.get_value("File", filters={
|
||||
"file_url": self.website_image,
|
||||
"attached_to_doctype": self.doctype,
|
||||
"attached_to_name": self.name
|
||||
}, fieldname=["name", "is_private"], as_dict=True)
|
||||
|
||||
if not file:
|
||||
self.website_image = None
|
||||
if not auto_set_website_image:
|
||||
frappe.msgprint(_("Website Image {0} attached to Item {1} cannot be found").format(self.website_image, self.name))
|
||||
|
||||
elif file.is_private:
|
||||
self.website_image = None
|
||||
if not auto_set_website_image:
|
||||
frappe.msgprint(_("Website Image should be a public file or website URL"))
|
||||
|
||||
def make_thumbnail(self):
|
||||
"""Make a thumbnail of `website_image`"""
|
||||
import requests.exceptions
|
||||
@ -383,7 +405,7 @@ class Item(WebsiteGenerator):
|
||||
for d in self.get("reorder_levels"):
|
||||
if d.warehouse_reorder_level and not d.warehouse_reorder_qty:
|
||||
frappe.throw(_("Row #{0}: Please set reorder quantity").format(d.idx))
|
||||
|
||||
|
||||
|
||||
def validate_warehouse_for_reorder(self):
|
||||
warehouse = []
|
||||
|
Loading…
Reference in New Issue
Block a user