mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-19 06:45:11 +00:00
* fix: inventory dimensions should not be mandatory unnecesarily (#54064)
(cherry picked from commit 6e44b8913e)
# Conflicts:
# erpnext/patches.txt
# erpnext/stock/doctype/inventory_dimension/inventory_dimension.py
* chore: resolve conflicts
* chore: resolve conflicts
* chore: resolve conflicts
---------
Co-authored-by: Mihir Kandoi <kandoimihir@gmail.com>
This commit is contained in:
@@ -432,3 +432,4 @@ erpnext.patches.v16_0.set_ordered_qty_in_quotation_item
|
|||||||
erpnext.patches.v15_0.replace_http_with_https_in_sales_partner
|
erpnext.patches.v15_0.replace_http_with_https_in_sales_partner
|
||||||
erpnext.patches.v16_0.add_portal_redirects
|
erpnext.patches.v16_0.add_portal_redirects
|
||||||
erpnext.patches.v16_0.update_order_qty_and_requested_qty_based_on_mr_and_po
|
erpnext.patches.v16_0.update_order_qty_and_requested_qty_based_on_mr_and_po
|
||||||
|
erpnext.patches.v16_0.depends_on_inv_dimensions
|
||||||
|
|||||||
70
erpnext/patches/v16_0/depends_on_inv_dimensions.py
Normal file
70
erpnext/patches/v16_0/depends_on_inv_dimensions.py
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import frappe
|
||||||
|
|
||||||
|
|
||||||
|
def get_inventory_dimensions():
|
||||||
|
return frappe.get_all(
|
||||||
|
"Inventory Dimension",
|
||||||
|
fields=[
|
||||||
|
"target_fieldname as fieldname",
|
||||||
|
"source_fieldname",
|
||||||
|
"reference_document as doctype",
|
||||||
|
"reqd",
|
||||||
|
"mandatory_depends_on",
|
||||||
|
],
|
||||||
|
order_by="creation",
|
||||||
|
distinct=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_display_depends_on(doctype):
|
||||||
|
if doctype not in [
|
||||||
|
"Stock Entry Detail",
|
||||||
|
"Sales Invoice Item",
|
||||||
|
"Delivery Note Item",
|
||||||
|
"Purchase Invoice Item",
|
||||||
|
"Purchase Receipt Item",
|
||||||
|
]:
|
||||||
|
return
|
||||||
|
|
||||||
|
display_depends_on = ""
|
||||||
|
|
||||||
|
if doctype in ["Purchase Invoice Item", "Purchase Receipt Item"]:
|
||||||
|
display_depends_on = "eval:parent.is_internal_supplier == 1"
|
||||||
|
elif doctype != "Stock Entry Detail":
|
||||||
|
display_depends_on = "eval:parent.is_internal_customer == 1"
|
||||||
|
elif doctype == "Stock Entry Detail":
|
||||||
|
display_depends_on = "eval:doc.t_warehouse"
|
||||||
|
|
||||||
|
return display_depends_on
|
||||||
|
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
for dimension in get_inventory_dimensions():
|
||||||
|
frappe.set_value(
|
||||||
|
"Custom Field",
|
||||||
|
{"fieldname": dimension.source_fieldname, "dt": "Stock Entry Detail"},
|
||||||
|
"depends_on",
|
||||||
|
"eval:doc.s_warehouse",
|
||||||
|
)
|
||||||
|
frappe.set_value(
|
||||||
|
"Custom Field",
|
||||||
|
{"fieldname": dimension.source_fieldname, "dt": "Stock Entry Detail", "reqd": 1},
|
||||||
|
{"mandatory_depends_on": "eval:doc.s_warehouse", "reqd": 0},
|
||||||
|
)
|
||||||
|
frappe.set_value(
|
||||||
|
"Custom Field",
|
||||||
|
{
|
||||||
|
"fieldname": f"to_{dimension.fieldname}",
|
||||||
|
"dt": "Stock Entry Detail",
|
||||||
|
"depends_on": "eval:parent.purpose != 'Material Issue'",
|
||||||
|
},
|
||||||
|
"depends_on",
|
||||||
|
"eval:doc.t_warehouse",
|
||||||
|
)
|
||||||
|
if display_depends_on := get_display_depends_on(dimension.doctype):
|
||||||
|
frappe.set_value(
|
||||||
|
"Custom Field",
|
||||||
|
{"fieldname": dimension.fieldname, "dt": dimension.doctype},
|
||||||
|
"mandatory_depends_on",
|
||||||
|
display_depends_on if dimension.reqd else dimension.mandatory_depends_on,
|
||||||
|
)
|
||||||
@@ -8,9 +8,8 @@
|
|||||||
"field_order": [
|
"field_order": [
|
||||||
"dimension_details_tab",
|
"dimension_details_tab",
|
||||||
"dimension_name",
|
"dimension_name",
|
||||||
"reference_document",
|
|
||||||
"column_break_4",
|
"column_break_4",
|
||||||
"disabled",
|
"reference_document",
|
||||||
"field_mapping_section",
|
"field_mapping_section",
|
||||||
"source_fieldname",
|
"source_fieldname",
|
||||||
"column_break_9",
|
"column_break_9",
|
||||||
@@ -93,12 +92,6 @@
|
|||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Apply to All Inventory Documents"
|
"label": "Apply to All Inventory Documents"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"default": "0",
|
|
||||||
"fieldname": "disabled",
|
|
||||||
"fieldtype": "Check",
|
|
||||||
"label": "Disabled"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "target_fieldname",
|
"fieldname": "target_fieldname",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
@@ -159,6 +152,7 @@
|
|||||||
"label": "Conditional Rule Examples"
|
"label": "Conditional Rule Examples"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"depends_on": "eval:!doc.apply_to_all_doctypes",
|
||||||
"description": "To apply condition on parent field use parent.field_name and to apply condition on child table use doc.field_name. Here field_name could be based on the actual column name of the respective field.",
|
"description": "To apply condition on parent field use parent.field_name and to apply condition on child table use doc.field_name. Here field_name could be based on the actual column name of the respective field.",
|
||||||
"fieldname": "mandatory_depends_on",
|
"fieldname": "mandatory_depends_on",
|
||||||
"fieldtype": "Small Text",
|
"fieldtype": "Small Text",
|
||||||
@@ -188,7 +182,7 @@
|
|||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2025-07-07 15:51:29.329064",
|
"modified": "2026-04-08 10:10:16.884388",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Inventory Dimension",
|
"name": "Inventory Dimension",
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ class InventoryDimension(Document):
|
|||||||
apply_to_all_doctypes: DF.Check
|
apply_to_all_doctypes: DF.Check
|
||||||
condition: DF.Code | None
|
condition: DF.Code | None
|
||||||
dimension_name: DF.Data
|
dimension_name: DF.Data
|
||||||
disabled: DF.Check
|
|
||||||
document_type: DF.Link | None
|
document_type: DF.Link | None
|
||||||
fetch_from_parent: DF.Literal[None]
|
fetch_from_parent: DF.Literal[None]
|
||||||
istable: DF.Check
|
istable: DF.Check
|
||||||
@@ -75,7 +74,6 @@ class InventoryDimension(Document):
|
|||||||
|
|
||||||
old_doc = self._doc_before_save
|
old_doc = self._doc_before_save
|
||||||
allow_to_edit_fields = [
|
allow_to_edit_fields = [
|
||||||
"disabled",
|
|
||||||
"fetch_from_parent",
|
"fetch_from_parent",
|
||||||
"type_of_transaction",
|
"type_of_transaction",
|
||||||
"condition",
|
"condition",
|
||||||
@@ -119,6 +117,7 @@ class InventoryDimension(Document):
|
|||||||
def reset_value(self):
|
def reset_value(self):
|
||||||
if self.apply_to_all_doctypes:
|
if self.apply_to_all_doctypes:
|
||||||
self.type_of_transaction = ""
|
self.type_of_transaction = ""
|
||||||
|
self.mandatory_depends_on = ""
|
||||||
|
|
||||||
self.istable = 0
|
self.istable = 0
|
||||||
for field in ["document_type", "condition"]:
|
for field in ["document_type", "condition"]:
|
||||||
@@ -183,8 +182,12 @@ class InventoryDimension(Document):
|
|||||||
label=_(label),
|
label=_(label),
|
||||||
depends_on="eval:doc.s_warehouse" if doctype == "Stock Entry Detail" else "",
|
depends_on="eval:doc.s_warehouse" if doctype == "Stock Entry Detail" else "",
|
||||||
search_index=1,
|
search_index=1,
|
||||||
reqd=self.reqd,
|
reqd=1
|
||||||
mandatory_depends_on=self.mandatory_depends_on,
|
if self.reqd and not self.mandatory_depends_on and doctype != "Stock Entry Detail"
|
||||||
|
else 0,
|
||||||
|
mandatory_depends_on="eval:doc.s_warehouse"
|
||||||
|
if self.reqd and doctype == "Stock Entry Detail"
|
||||||
|
else self.mandatory_depends_on,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -296,12 +299,13 @@ class InventoryDimension(Document):
|
|||||||
options=self.reference_document,
|
options=self.reference_document,
|
||||||
label=label,
|
label=label,
|
||||||
depends_on=display_depends_on,
|
depends_on=display_depends_on,
|
||||||
|
mandatory_depends_on=display_depends_on if self.reqd else self.mandatory_depends_on,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def field_exists(doctype, fieldname) -> str or None:
|
def field_exists(doctype, fieldname) -> str | None:
|
||||||
return frappe.db.get_value("DocField", {"parent": doctype, "fieldname": fieldname}, "name")
|
return frappe.db.get_value("DocField", {"parent": doctype, "fieldname": fieldname}, "name")
|
||||||
|
|
||||||
|
|
||||||
@@ -374,7 +378,6 @@ def get_document_wise_inventory_dimensions(doctype) -> dict:
|
|||||||
"type_of_transaction",
|
"type_of_transaction",
|
||||||
"fetch_from_parent",
|
"fetch_from_parent",
|
||||||
],
|
],
|
||||||
filters={"disabled": 0},
|
|
||||||
or_filters={"document_type": doctype, "apply_to_all_doctypes": 1},
|
or_filters={"document_type": doctype, "apply_to_all_doctypes": 1},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -397,7 +400,6 @@ def get_inventory_dimensions():
|
|||||||
"reference_document as doctype",
|
"reference_document as doctype",
|
||||||
"validate_negative_stock",
|
"validate_negative_stock",
|
||||||
],
|
],
|
||||||
filters={"disabled": 0},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
frappe.local.inventory_dimensions = dimensions
|
frappe.local.inventory_dimensions = dimensions
|
||||||
|
|||||||
@@ -220,9 +220,9 @@ class TestInventoryDimension(FrappeTestCase):
|
|||||||
doc = create_inventory_dimension(
|
doc = create_inventory_dimension(
|
||||||
reference_document="Pallet",
|
reference_document="Pallet",
|
||||||
type_of_transaction="Outward",
|
type_of_transaction="Outward",
|
||||||
dimension_name="Pallet",
|
dimension_name="Pallet 75",
|
||||||
apply_to_all_doctypes=0,
|
apply_to_all_doctypes=0,
|
||||||
document_type="Stock Entry Detail",
|
document_type="Delivery Note Item",
|
||||||
)
|
)
|
||||||
|
|
||||||
doc.reqd = 1
|
doc.reqd = 1
|
||||||
@@ -230,7 +230,7 @@ class TestInventoryDimension(FrappeTestCase):
|
|||||||
|
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
frappe.db.get_value(
|
frappe.db.get_value(
|
||||||
"Custom Field", {"fieldname": "pallet", "dt": "Stock Entry Detail", "reqd": 1}, "name"
|
"Custom Field", {"fieldname": "pallet_75", "dt": "Delivery Note Item", "reqd": 1}, "name"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user