Merge pull request #32730 from rohitwaghchaure/duplicate-custom-fields-inventory-dimension
fix: duplicate custom fields for inventory dimension
This commit is contained in:
commit
1033d34964
@ -121,18 +121,24 @@ class InventoryDimension(Document):
|
|||||||
|
|
||||||
if self.apply_to_all_doctypes:
|
if self.apply_to_all_doctypes:
|
||||||
for doctype in get_inventory_documents():
|
for doctype in get_inventory_documents():
|
||||||
custom_fields.setdefault(doctype[0], dimension_fields)
|
if not field_exists(doctype[0], self.source_fieldname):
|
||||||
else:
|
custom_fields.setdefault(doctype[0], dimension_fields)
|
||||||
|
elif not field_exists(self.document_type, self.source_fieldname):
|
||||||
custom_fields.setdefault(self.document_type, dimension_fields)
|
custom_fields.setdefault(self.document_type, dimension_fields)
|
||||||
|
|
||||||
if not frappe.db.get_value(
|
if not frappe.db.get_value(
|
||||||
"Custom Field", {"dt": "Stock Ledger Entry", "fieldname": self.target_fieldname}
|
"Custom Field", {"dt": "Stock Ledger Entry", "fieldname": self.target_fieldname}
|
||||||
):
|
) and not field_exists("Stock Ledger Entry", self.target_fieldname):
|
||||||
dimension_field = dimension_fields[1]
|
dimension_field = dimension_fields[1]
|
||||||
dimension_field["fieldname"] = self.target_fieldname
|
dimension_field["fieldname"] = self.target_fieldname
|
||||||
custom_fields["Stock Ledger Entry"] = dimension_field
|
custom_fields["Stock Ledger Entry"] = dimension_field
|
||||||
|
|
||||||
create_custom_fields(custom_fields)
|
if custom_fields:
|
||||||
|
create_custom_fields(custom_fields)
|
||||||
|
|
||||||
|
|
||||||
|
def field_exists(doctype, fieldname) -> str or None:
|
||||||
|
return frappe.db.get_value("DocField", {"parent": doctype, "fieldname": fieldname}, "name")
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
@ -191,6 +191,21 @@ class TestInventoryDimension(FrappeTestCase):
|
|||||||
|
|
||||||
self.assertEqual(sle_rack, "Rack 1")
|
self.assertEqual(sle_rack, "Rack 1")
|
||||||
|
|
||||||
|
def test_check_standard_dimensions(self):
|
||||||
|
create_inventory_dimension(
|
||||||
|
reference_document="Project",
|
||||||
|
type_of_transaction="Outward",
|
||||||
|
dimension_name="Project",
|
||||||
|
apply_to_all_doctypes=0,
|
||||||
|
document_type="Stock Ledger Entry",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertFalse(
|
||||||
|
frappe.db.get_value(
|
||||||
|
"Custom Field", {"fieldname": "project", "dt": "Stock Ledger Entry"}, "name"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def prepare_test_data():
|
def prepare_test_data():
|
||||||
if not frappe.db.exists("DocType", "Shelf"):
|
if not frappe.db.exists("DocType", "Shelf"):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user