fix: inventory dimension patch (backport #54147) (#54148)

This commit is contained in:
mergify[bot]
2026-04-09 02:40:40 +00:00
committed by GitHub
parent deb67db4a0
commit a56d6984d1

View File

@@ -16,7 +16,7 @@ def get_inventory_dimensions():
) )
def get_display_depends_on(doctype): def get_display_depends_on(doctype, fieldname):
if doctype not in [ if doctype not in [
"Stock Entry Detail", "Stock Entry Detail",
"Sales Invoice Item", "Sales Invoice Item",
@@ -24,18 +24,20 @@ def get_display_depends_on(doctype):
"Purchase Invoice Item", "Purchase Invoice Item",
"Purchase Receipt Item", "Purchase Receipt Item",
]: ]:
return return None, None
fieldname_start_with = "to"
display_depends_on = "" display_depends_on = ""
if doctype in ["Purchase Invoice Item", "Purchase Receipt Item"]: if doctype in ["Purchase Invoice Item", "Purchase Receipt Item"]:
display_depends_on = "eval:parent.is_internal_supplier == 1" display_depends_on = "eval:parent.is_internal_supplier == 1"
fieldname_start_with = "from"
elif doctype != "Stock Entry Detail": elif doctype != "Stock Entry Detail":
display_depends_on = "eval:parent.is_internal_customer == 1" display_depends_on = "eval:parent.is_internal_customer == 1"
elif doctype == "Stock Entry Detail": elif doctype == "Stock Entry Detail":
display_depends_on = "eval:doc.t_warehouse" display_depends_on = "eval:doc.t_warehouse"
return display_depends_on return f"{fieldname_start_with}_{fieldname}", display_depends_on
def execute(): def execute():
@@ -75,13 +77,13 @@ def execute():
"depends_on", "depends_on",
"eval:doc.t_warehouse", "eval:doc.t_warehouse",
) )
if (display_depends_on := get_display_depends_on(dimension.doctype)) and frappe.db.exists( fieldname, display_depends_on = get_display_depends_on(dimension.doctype, dimension.fieldname)
"Custom Field", if display_depends_on and frappe.db.exists(
{"fieldname": dimension.fieldname, "dt": dimension.doctype}, "Custom Field", {"fieldname": fieldname, "dt": dimension.doctype}
): ):
frappe.set_value( frappe.set_value(
"Custom Field", "Custom Field",
{"fieldname": dimension.fieldname, "dt": dimension.doctype}, {"fieldname": fieldname, "dt": dimension.doctype},
"mandatory_depends_on", "mandatory_depends_on",
display_depends_on if dimension.reqd else dimension.mandatory_depends_on, display_depends_on if dimension.reqd else dimension.mandatory_depends_on,
) )