diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index 1862258d295673834b2d319cb56d8070f1e8afd8..3cc1140ac197c9caf0fa2c4130de8862ecff5b98 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -688,39 +688,42 @@ $.extend(erpnext.item, { return selected_attributes; } - frm.doc.attributes.forEach(function(d) { - let p = new Promise(resolve => { - if(!d.numeric_values) { - frappe.call({ - method: "frappe.client.get_list", - args: { - doctype: "Item Attribute Value", - filters: [ - ["parent","=", d.attribute] - ], - fields: ["attribute_value"], - limit_page_length: 0, - parent: "Item Attribute", - order_by: "idx" - } - }).then((r) => { - if(r.message) { - attr_val_fields[d.attribute] = r.message.map(function(d) { return d.attribute_value; }); - resolve(); + frm.doc.attributes.forEach(function (d) { + if (!d.disabled) { + let p = new Promise((resolve) => { + if (!d.numeric_values) { + frappe + .call({ + method: "frappe.client.get_list", + args: { + doctype: "Item Attribute Value", + filters: [["parent", "=", d.attribute]], + fields: ["attribute_value"], + limit_page_length: 0, + parent: "Item Attribute", + order_by: "idx", + }, + }) + .then((r) => { + if (r.message) { + attr_val_fields[d.attribute] = r.message.map(function (d) { + return d.attribute_value; + }); + resolve(); + } + }); + } else { + let values = []; + for (var i = d.from_range; i <= d.to_range; i = flt(i + d.increment, 6)) { + values.push(i); } - }); - } else { - let values = []; - for(var i = d.from_range; i <= d.to_range; i = flt(i + d.increment, 6)) { - values.push(i); + attr_val_fields[d.attribute] = values; + resolve(); } - attr_val_fields[d.attribute] = values; - resolve(); - } - }); - - promises.push(p); + }); + promises.push(p); + } }, this); Promise.all(promises).then(() => { @@ -736,21 +739,29 @@ $.extend(erpnext.item, { for(var i=0;i< frm.doc.attributes.length;i++){ var fieldtype, desc; var row = frm.doc.attributes[i]; - if (row.numeric_values){ - fieldtype = "Float"; - desc = "Min Value: "+ row.from_range +" , Max Value: "+ row.to_range +", in Increments of: "+ row.increment - } - else { - fieldtype = "Data"; - desc = "" + + if (!row.disabled) { + if (row.numeric_values) { + fieldtype = "Float"; + desc = + "Min Value: " + + row.from_range + + " , Max Value: " + + row.to_range + + ", in Increments of: " + + row.increment; + } else { + fieldtype = "Data"; + desc = ""; + } + fields = fields.concat({ + label: row.attribute, + fieldname: row.attribute, + fieldtype: fieldtype, + reqd: 0, + description: desc, + }); } - fields = fields.concat({ - "label": row.attribute, - "fieldname": row.attribute, - "fieldtype": fieldtype, - "reqd": 0, - "description": desc - }) } if (frm.doc.image) { diff --git a/erpnext/stock/doctype/item_attribute/item_attribute.json b/erpnext/stock/doctype/item_attribute/item_attribute.json index acb346c2e63ddf8b0bf18b3b96bcf741560ca90d..eaa14efbfd4fbdac8a078870f0ad6ac91171e656 100644 --- a/erpnext/stock/doctype/item_attribute/item_attribute.json +++ b/erpnext/stock/doctype/item_attribute/item_attribute.json @@ -1,97 +1,111 @@ { - "actions": [], - "allow_import": 1, - "allow_rename": 1, - "autoname": "field:attribute_name", - "creation": "2014-09-26 03:49:54.899170", - "doctype": "DocType", - "document_type": "Setup", - "engine": "InnoDB", - "field_order": [ - "attribute_name", - "numeric_values", - "section_break_4", - "from_range", - "increment", - "column_break_8", - "to_range", - "section_break_5", - "item_attribute_values" - ], - "fields": [ - { - "fieldname": "attribute_name", - "fieldtype": "Data", - "in_list_view": 1, - "label": "Attribute Name", - "reqd": 1, - "unique": 1 - }, - { - "default": "0", - "fieldname": "numeric_values", - "fieldtype": "Check", - "label": "Numeric Values" - }, - { - "depends_on": "numeric_values", - "fieldname": "section_break_4", - "fieldtype": "Section Break" - }, - { - "default": "0", - "fieldname": "from_range", - "fieldtype": "Float", - "label": "From Range" - }, - { - "default": "0", - "fieldname": "increment", - "fieldtype": "Float", - "label": "Increment" - }, - { - "fieldname": "column_break_8", - "fieldtype": "Column Break" - }, - { - "default": "0", - "fieldname": "to_range", - "fieldtype": "Float", - "label": "To Range" - }, - { - "depends_on": "eval: !doc.numeric_values", - "fieldname": "section_break_5", - "fieldtype": "Section Break" - }, - { - "fieldname": "item_attribute_values", - "fieldtype": "Table", - "label": "Item Attribute Values", - "options": "Item Attribute Value" - } - ], - "icon": "fa fa-edit", - "index_web_pages_for_search": 1, - "links": [], - "modified": "2020-10-02 12:03:02.359202", - "modified_by": "Administrator", - "module": "Stock", - "name": "Item Attribute", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "read": 1, - "report": 1, - "role": "Item Manager", - "share": 1, - "write": 1 - } - ], - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1 - } \ No newline at end of file + "actions": [], + "allow_import": 1, + "allow_rename": 1, + "autoname": "field:attribute_name", + "creation": "2014-09-26 03:49:54.899170", + "doctype": "DocType", + "document_type": "Setup", + "engine": "InnoDB", + "field_order": [ + "attribute_name", + "numeric_values", + "column_break_vbik", + "disabled", + "section_break_4", + "from_range", + "increment", + "column_break_8", + "to_range", + "section_break_5", + "item_attribute_values" + ], + "fields": [ + { + "fieldname": "attribute_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Attribute Name", + "reqd": 1, + "unique": 1 + }, + { + "default": "0", + "fieldname": "numeric_values", + "fieldtype": "Check", + "label": "Numeric Values" + }, + { + "depends_on": "numeric_values", + "fieldname": "section_break_4", + "fieldtype": "Section Break" + }, + { + "default": "0", + "fieldname": "from_range", + "fieldtype": "Float", + "label": "From Range" + }, + { + "default": "0", + "fieldname": "increment", + "fieldtype": "Float", + "label": "Increment" + }, + { + "fieldname": "column_break_8", + "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "to_range", + "fieldtype": "Float", + "label": "To Range" + }, + { + "depends_on": "eval: !doc.numeric_values", + "fieldname": "section_break_5", + "fieldtype": "Section Break" + }, + { + "fieldname": "item_attribute_values", + "fieldtype": "Table", + "label": "Item Attribute Values", + "options": "Item Attribute Value" + }, + { + "fieldname": "column_break_vbik", + "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "disabled", + "fieldtype": "Check", + "label": "Disabled" + } + ], + "icon": "fa fa-edit", + "index_web_pages_for_search": 1, + "links": [], + "modified": "2024-11-26 20:05:29.421714", + "modified_by": "Administrator", + "module": "Stock", + "name": "Item Attribute", + "naming_rule": "By fieldname", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "read": 1, + "report": 1, + "role": "Item Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "creation", + "sort_order": "DESC", + "states": [], + "track_changes": 1 +} diff --git a/erpnext/stock/doctype/item_attribute/item_attribute.py b/erpnext/stock/doctype/item_attribute/item_attribute.py index ac4c313e28a89e63ad166de3a3e3e3ce4f3d9a36..ba4ce1398b4e55bbccec070926c151f89f1ed73f 100644 --- a/erpnext/stock/doctype/item_attribute/item_attribute.py +++ b/erpnext/stock/doctype/item_attribute/item_attribute.py @@ -19,8 +19,24 @@ class ItemAttributeIncrementError(frappe.ValidationError): class ItemAttribute(Document): - def __setup__(self): - self.flags.ignore_these_exceptions_in_test = [InvalidItemAttributeValueError] + # begin: auto-generated types + # This code is auto-generated. Do not modify anything in this block. + + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from frappe.types import DF + + from erpnext.stock.doctype.item_attribute_value.item_attribute_value import ItemAttributeValue + + attribute_name: DF.Data + disabled: DF.Check + from_range: DF.Float + increment: DF.Float + item_attribute_values: DF.Table[ItemAttributeValue] + numeric_values: DF.Check + to_range: DF.Float + # end: auto-generated types def validate(self): frappe.flags.attribute_values = None @@ -29,6 +45,19 @@ class ItemAttribute(Document): def on_update(self): self.validate_exising_items() + self.set_enabled_disabled_in_items() + + def set_enabled_disabled_in_items(self): + db_value = self.get_doc_before_save() + if not db_value or db_value.disabled != self.disabled: + item_variant_table = frappe.qb.DocType("Item Variant Attribute") + query = ( + frappe.qb.update(item_variant_table) + .set(item_variant_table.disabled, self.disabled) + .where(item_variant_table.attribute == self.name) + ) + + query.run() def validate_exising_items(self): """Validate that if there are existing items with attributes, they are valid""" diff --git a/erpnext/stock/doctype/item_variant_attribute/item_variant_attribute.json b/erpnext/stock/doctype/item_variant_attribute/item_variant_attribute.json index 9699ecbb3db2c3f040d17e660be21f6022207844..ee3e57d919e72b4877d8d633f2b9e4232885f8a4 100644 --- a/erpnext/stock/doctype/item_variant_attribute/item_variant_attribute.json +++ b/erpnext/stock/doctype/item_variant_attribute/item_variant_attribute.json @@ -11,6 +11,7 @@ "column_break_2", "attribute_value", "numeric_values", + "disabled", "section_break_4", "from_range", "increment", @@ -74,11 +75,18 @@ "fieldname": "to_range", "fieldtype": "Float", "label": "To Range" + }, + { + "default": "0", + "fetch_from": "attribute.disabled", + "fieldname": "disabled", + "fieldtype": "Check", + "label": "Disabled" } ], "istable": 1, "links": [], - "modified": "2023-07-14 17:15:19.112119", + "modified": "2024-11-26 20:10:49.873339", "modified_by": "Administrator", "module": "Stock", "name": "Item Variant Attribute", diff --git a/erpnext/stock/doctype/item_variant_attribute/item_variant_attribute.py b/erpnext/stock/doctype/item_variant_attribute/item_variant_attribute.py index d90af32726ca948484e0dba502b2d548fea2b613..9c1fece9f7d292ae61dad908a2c43d5019343840 100644 --- a/erpnext/stock/doctype/item_variant_attribute/item_variant_attribute.py +++ b/erpnext/stock/doctype/item_variant_attribute/item_variant_attribute.py @@ -7,4 +7,25 @@ from frappe.model.document import Document class ItemVariantAttribute(Document): + # begin: auto-generated types + # This code is auto-generated. Do not modify anything in this block. + + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from frappe.types import DF + + attribute: DF.Link + attribute_value: DF.Data | None + disabled: DF.Check + from_range: DF.Float + increment: DF.Float + numeric_values: DF.Check + parent: DF.Data + parentfield: DF.Data + parenttype: DF.Data + to_range: DF.Float + variant_of: DF.Link | None + # end: auto-generated types + pass