Merge pull request #22067 from marination/item-attribute
fix: Misleading Error message for Item Attribute.
This commit is contained in:
commit
407c7bc113
@ -70,7 +70,7 @@ def validate_item_variant_attributes(item, args=None):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
attributes_list = attribute_values.get(attribute.lower(), [])
|
attributes_list = attribute_values.get(attribute.lower(), [])
|
||||||
validate_item_attribute_value(attributes_list, attribute, value, item.name)
|
validate_item_attribute_value(attributes_list, attribute, value, item.name, from_variant=True)
|
||||||
|
|
||||||
def validate_is_incremental(numeric_attribute, attribute, value, item):
|
def validate_is_incremental(numeric_attribute, attribute, value, item):
|
||||||
from_range = numeric_attribute.from_range
|
from_range = numeric_attribute.from_range
|
||||||
@ -93,13 +93,20 @@ def validate_is_incremental(numeric_attribute, attribute, value, item):
|
|||||||
.format(attribute, from_range, to_range, increment, item),
|
.format(attribute, from_range, to_range, increment, item),
|
||||||
InvalidItemAttributeValueError, title=_('Invalid Attribute'))
|
InvalidItemAttributeValueError, title=_('Invalid Attribute'))
|
||||||
|
|
||||||
def validate_item_attribute_value(attributes_list, attribute, attribute_value, item):
|
def validate_item_attribute_value(attributes_list, attribute, attribute_value, item, from_variant=True):
|
||||||
allow_rename_attribute_value = frappe.db.get_single_value('Item Variant Settings', 'allow_rename_attribute_value')
|
allow_rename_attribute_value = frappe.db.get_single_value('Item Variant Settings', 'allow_rename_attribute_value')
|
||||||
if allow_rename_attribute_value:
|
if allow_rename_attribute_value:
|
||||||
pass
|
pass
|
||||||
elif attribute_value not in attributes_list:
|
elif attribute_value not in attributes_list:
|
||||||
frappe.throw(_("The value {0} is already assigned to an exisiting Item {2}.").format(
|
if from_variant:
|
||||||
attribute_value, attribute, item), InvalidItemAttributeValueError, title=_('Rename Not Allowed'))
|
frappe.throw(_("{0} is not a valid Value for Attribute {1} of Item {2}.").format(
|
||||||
|
frappe.bold(attribute_value), frappe.bold(attribute), frappe.bold(item)), InvalidItemAttributeValueError, title=_("Invalid Value"))
|
||||||
|
else:
|
||||||
|
msg = _("The value {0} is already assigned to an exisiting Item {1}.").format(
|
||||||
|
frappe.bold(attribute_value), frappe.bold(item))
|
||||||
|
msg += "<br>" + _("To still proceed with editing this Attribute Value, enable {0} in Item Variant Settings.").format(frappe.bold("Allow Rename Attribute Value"))
|
||||||
|
|
||||||
|
frappe.throw(msg, InvalidItemAttributeValueError, title=_('Edit Not Allowed'))
|
||||||
|
|
||||||
def get_attribute_values(item):
|
def get_attribute_values(item):
|
||||||
if not frappe.flags.attribute_values:
|
if not frappe.flags.attribute_values:
|
||||||
|
@ -34,7 +34,7 @@ class ItemAttribute(Document):
|
|||||||
if self.numeric_values:
|
if self.numeric_values:
|
||||||
validate_is_incremental(self, self.name, item.value, item.name)
|
validate_is_incremental(self, self.name, item.value, item.name)
|
||||||
else:
|
else:
|
||||||
validate_item_attribute_value(attributes_list, self.name, item.value, item.name)
|
validate_item_attribute_value(attributes_list, self.name, item.value, item.name, from_variant=False)
|
||||||
|
|
||||||
def validate_numeric(self):
|
def validate_numeric(self):
|
||||||
if self.numeric_values:
|
if self.numeric_values:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user