* feat: provision to disable item attribute (#44358)
(cherry picked from commit 123e3ef263)
# Conflicts:
# erpnext/stock/doctype/item_attribute/item_attribute.json
# erpnext/stock/doctype/item_variant_attribute/item_variant_attribute.json
* chore: fix conflicts
* chore: fix conflicts
---------
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -663,39 +663,41 @@ $.extend(erpnext.item, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
frm.doc.attributes.forEach(function (d) {
|
frm.doc.attributes.forEach(function (d) {
|
||||||
let p = new Promise((resolve) => {
|
if (!d.disabled) {
|
||||||
if (!d.numeric_values) {
|
let p = new Promise((resolve) => {
|
||||||
frappe
|
if (!d.numeric_values) {
|
||||||
.call({
|
frappe
|
||||||
method: "frappe.client.get_list",
|
.call({
|
||||||
args: {
|
method: "frappe.client.get_list",
|
||||||
doctype: "Item Attribute Value",
|
args: {
|
||||||
filters: [["parent", "=", d.attribute]],
|
doctype: "Item Attribute Value",
|
||||||
fields: ["attribute_value"],
|
filters: [["parent", "=", d.attribute]],
|
||||||
limit_page_length: 0,
|
fields: ["attribute_value"],
|
||||||
parent: "Item Attribute",
|
limit_page_length: 0,
|
||||||
order_by: "idx",
|
parent: "Item Attribute",
|
||||||
},
|
order_by: "idx",
|
||||||
})
|
},
|
||||||
.then((r) => {
|
})
|
||||||
if (r.message) {
|
.then((r) => {
|
||||||
attr_val_fields[d.attribute] = r.message.map(function (d) {
|
if (r.message) {
|
||||||
return d.attribute_value;
|
attr_val_fields[d.attribute] = r.message.map(function (d) {
|
||||||
});
|
return d.attribute_value;
|
||||||
resolve();
|
});
|
||||||
}
|
resolve();
|
||||||
});
|
}
|
||||||
} else {
|
});
|
||||||
let values = [];
|
} else {
|
||||||
for (var i = d.from_range; i <= d.to_range; i = flt(i + d.increment, 6)) {
|
let values = [];
|
||||||
values.push(i);
|
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);
|
}, this);
|
||||||
|
|
||||||
Promise.all(promises).then(() => {
|
Promise.all(promises).then(() => {
|
||||||
@@ -710,26 +712,29 @@ $.extend(erpnext.item, {
|
|||||||
for (var i = 0; i < frm.doc.attributes.length; i++) {
|
for (var i = 0; i < frm.doc.attributes.length; i++) {
|
||||||
var fieldtype, desc;
|
var fieldtype, desc;
|
||||||
var row = frm.doc.attributes[i];
|
var row = frm.doc.attributes[i];
|
||||||
if (row.numeric_values) {
|
|
||||||
fieldtype = "Float";
|
if (!row.disabled) {
|
||||||
desc =
|
if (row.numeric_values) {
|
||||||
"Min Value: " +
|
fieldtype = "Float";
|
||||||
row.from_range +
|
desc =
|
||||||
" , Max Value: " +
|
"Min Value: " +
|
||||||
row.to_range +
|
row.from_range +
|
||||||
", in Increments of: " +
|
" , Max Value: " +
|
||||||
row.increment;
|
row.to_range +
|
||||||
} else {
|
", in Increments of: " +
|
||||||
fieldtype = "Data";
|
row.increment;
|
||||||
desc = "";
|
} 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) {
|
if (frm.doc.image) {
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
"field_order": [
|
"field_order": [
|
||||||
"attribute_name",
|
"attribute_name",
|
||||||
"numeric_values",
|
"numeric_values",
|
||||||
|
"column_break_vbik",
|
||||||
|
"disabled",
|
||||||
"section_break_4",
|
"section_break_4",
|
||||||
"from_range",
|
"from_range",
|
||||||
"increment",
|
"increment",
|
||||||
@@ -70,15 +72,26 @@
|
|||||||
"fieldtype": "Table",
|
"fieldtype": "Table",
|
||||||
"label": "Item Attribute Values",
|
"label": "Item Attribute Values",
|
||||||
"options": "Item Attribute Value"
|
"options": "Item Attribute Value"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_vbik",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "disabled",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Disabled"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"icon": "fa fa-edit",
|
"icon": "fa fa-edit",
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-10-02 12:03:02.359202",
|
"modified": "2024-11-26 20:05:29.421714",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Item Attribute",
|
"name": "Item Attribute",
|
||||||
|
"naming_rule": "By fieldname",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
@@ -94,4 +107,4 @@
|
|||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"track_changes": 1
|
"track_changes": 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class ItemAttribute(Document):
|
|||||||
from erpnext.stock.doctype.item_attribute_value.item_attribute_value import ItemAttributeValue
|
from erpnext.stock.doctype.item_attribute_value.item_attribute_value import ItemAttributeValue
|
||||||
|
|
||||||
attribute_name: DF.Data
|
attribute_name: DF.Data
|
||||||
|
disabled: DF.Check
|
||||||
from_range: DF.Float
|
from_range: DF.Float
|
||||||
increment: DF.Float
|
increment: DF.Float
|
||||||
item_attribute_values: DF.Table[ItemAttributeValue]
|
item_attribute_values: DF.Table[ItemAttributeValue]
|
||||||
@@ -47,6 +48,19 @@ class ItemAttribute(Document):
|
|||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
self.validate_exising_items()
|
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):
|
def validate_exising_items(self):
|
||||||
"""Validate that if there are existing items with attributes, they are valid"""
|
"""Validate that if there are existing items with attributes, they are valid"""
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"column_break_2",
|
"column_break_2",
|
||||||
"attribute_value",
|
"attribute_value",
|
||||||
"numeric_values",
|
"numeric_values",
|
||||||
|
"disabled",
|
||||||
"section_break_4",
|
"section_break_4",
|
||||||
"from_range",
|
"from_range",
|
||||||
"increment",
|
"increment",
|
||||||
@@ -74,11 +75,18 @@
|
|||||||
"fieldname": "to_range",
|
"fieldname": "to_range",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"label": "To Range"
|
"label": "To Range"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fetch_from": "attribute.disabled",
|
||||||
|
"fieldname": "disabled",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Disabled"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-07-14 17:15:19.112119",
|
"modified": "2024-11-26 20:10:49.873339",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Item Variant Attribute",
|
"name": "Item Variant Attribute",
|
||||||
@@ -87,4 +95,4 @@
|
|||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"states": []
|
"states": []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class ItemVariantAttribute(Document):
|
|||||||
|
|
||||||
attribute: DF.Link
|
attribute: DF.Link
|
||||||
attribute_value: DF.Data | None
|
attribute_value: DF.Data | None
|
||||||
|
disabled: DF.Check
|
||||||
from_range: DF.Float
|
from_range: DF.Float
|
||||||
increment: DF.Float
|
increment: DF.Float
|
||||||
numeric_values: DF.Check
|
numeric_values: DF.Check
|
||||||
|
|||||||
Reference in New Issue
Block a user