fix: UX for inventory dimension

(cherry picked from commit 0a69523940)
This commit is contained in:
Rohit Waghchaure
2022-11-15 15:48:44 +05:30
committed by Mergify
parent 084d81025c
commit f1dd4d0449
4 changed files with 47 additions and 29 deletions

View File

@@ -71,6 +71,8 @@ frappe.ui.form.on('Inventory Dimension', {
if (r.message && r.message.length) { if (r.message && r.message.length) {
frm.set_df_property("fetch_from_parent", "options", frm.set_df_property("fetch_from_parent", "options",
[""].concat(r.message)); [""].concat(r.message));
} else {
frm.set_df_property("fetch_from_parent", "hidden", 1);
} }
} }
}); });

View File

@@ -11,20 +11,20 @@
"reference_document", "reference_document",
"column_break_4", "column_break_4",
"disabled", "disabled",
"section_break_7",
"field_mapping_section", "field_mapping_section",
"source_fieldname", "source_fieldname",
"column_break_9", "column_break_9",
"target_fieldname", "target_fieldname",
"applicable_for_documents_tab", "applicable_for_documents_tab",
"apply_to_all_doctypes", "apply_to_all_doctypes",
"column_break_13",
"document_type", "document_type",
"istable",
"type_of_transaction", "type_of_transaction",
"fetch_from_parent", "fetch_from_parent",
"column_break_16", "istable",
"condition",
"applicable_condition_example_section", "applicable_condition_example_section",
"condition",
"conditional_rule_examples_section",
"html_19" "html_19"
], ],
"fields": [ "fields": [
@@ -52,13 +52,13 @@
{ {
"fieldname": "applicable_for_documents_tab", "fieldname": "applicable_for_documents_tab",
"fieldtype": "Tab Break", "fieldtype": "Tab Break",
"label": "Applicable For Documents" "label": "Applicable For"
}, },
{ {
"depends_on": "eval:!doc.apply_to_all_doctypes", "depends_on": "eval:!doc.apply_to_all_doctypes",
"fieldname": "document_type", "fieldname": "document_type",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Applicable to Document", "label": "Apply to Document",
"mandatory_depends_on": "eval:!doc.apply_to_all_doctypes", "mandatory_depends_on": "eval:!doc.apply_to_all_doctypes",
"options": "DocType" "options": "DocType"
}, },
@@ -72,6 +72,7 @@
"fetch_from": "document_type.istable", "fetch_from": "document_type.istable",
"fieldname": "istable", "fieldname": "istable",
"fieldtype": "Check", "fieldtype": "Check",
"hidden": 1,
"label": " Is Child Table", "label": " Is Child Table",
"read_only": 1 "read_only": 1
}, },
@@ -79,13 +80,13 @@
"depends_on": "eval:!doc.apply_to_all_doctypes", "depends_on": "eval:!doc.apply_to_all_doctypes",
"fieldname": "condition", "fieldname": "condition",
"fieldtype": "Code", "fieldtype": "Code",
"label": "Applicable Condition" "label": "Conditional Rule"
}, },
{ {
"default": "0", "default": "1",
"fieldname": "apply_to_all_doctypes", "fieldname": "apply_to_all_doctypes",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Apply to All Inventory Document Types" "label": "Apply to All Inventory Documents"
}, },
{ {
"default": "0", "default": "0",
@@ -93,10 +94,6 @@
"fieldtype": "Check", "fieldtype": "Check",
"label": "Disabled" "label": "Disabled"
}, },
{
"fieldname": "section_break_7",
"fieldtype": "Section Break"
},
{ {
"fieldname": "target_fieldname", "fieldname": "target_fieldname",
"fieldtype": "Data", "fieldtype": "Data",
@@ -115,13 +112,11 @@
"collapsible": 1, "collapsible": 1,
"fieldname": "field_mapping_section", "fieldname": "field_mapping_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 1,
"label": "Field Mapping" "label": "Field Mapping"
}, },
{ {
"fieldname": "column_break_16", "depends_on": "eval:!doc.apply_to_all_doctypes",
"fieldtype": "Column Break"
},
{
"fieldname": "type_of_transaction", "fieldname": "type_of_transaction",
"fieldtype": "Select", "fieldtype": "Select",
"label": "Type of Transaction", "label": "Type of Transaction",
@@ -136,23 +131,33 @@
"collapsible": 1, "collapsible": 1,
"depends_on": "eval:!doc.apply_to_all_doctypes", "depends_on": "eval:!doc.apply_to_all_doctypes",
"fieldname": "applicable_condition_example_section", "fieldname": "applicable_condition_example_section",
"fieldtype": "Section Break", "fieldtype": "Column Break"
"label": "Applicable Condition Examples"
}, },
{ {
"fieldname": "column_break_4", "fieldname": "column_break_4",
"fieldtype": "Column Break" "fieldtype": "Column Break"
}, },
{ {
"description": "Set fieldname or DocType name like Supplier, Customer etc.", "depends_on": "eval:!doc.apply_to_all_doctypes",
"description": "Set fieldname from which you want to fetch the data from the parent form.",
"fieldname": "fetch_from_parent", "fieldname": "fetch_from_parent",
"fieldtype": "Select", "fieldtype": "Select",
"label": "Fetch Value From Parent Form" "label": "Fetch Value From"
},
{
"fieldname": "column_break_13",
"fieldtype": "Section Break"
},
{
"depends_on": "eval:!doc.apply_to_all_doctypes",
"fieldname": "conditional_rule_examples_section",
"fieldtype": "Section Break",
"label": "Conditional Rule Examples"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2022-09-02 13:29:04.098469", "modified": "2022-11-15 15:50:16.767105",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Inventory Dimension", "name": "Inventory Dimension",

View File

@@ -33,10 +33,22 @@ class InventoryDimension(Document):
) )
def validate(self): def validate(self):
self.validate_reference_document()
def before_save(self):
self.do_not_update_document() self.do_not_update_document()
self.reset_value() self.reset_value()
self.validate_reference_document()
self.set_source_and_target_fieldname() self.set_source_and_target_fieldname()
self.set_type_of_transaction()
self.set_fetch_value_from()
def set_type_of_transaction(self):
if self.apply_to_all_doctypes:
self.type_of_transaction = "Both"
def set_fetch_value_from(self):
if self.apply_to_all_doctypes:
self.fetch_from_parent = self.reference_document
def do_not_update_document(self): def do_not_update_document(self):
if self.is_new() or not self.has_stock_ledger(): if self.is_new() or not self.has_stock_ledger():

View File

@@ -140,14 +140,13 @@ class TestInventoryDimension(FrappeTestCase):
self.assertRaises(DoNotChangeError, inv_dim1.save) self.assertRaises(DoNotChangeError, inv_dim1.save)
def test_inventory_dimension_for_purchase_receipt_and_delivery_note(self): def test_inventory_dimension_for_purchase_receipt_and_delivery_note(self):
create_inventory_dimension( inv_dimension = create_inventory_dimension(
reference_document="Rack", reference_document="Rack", dimension_name="Rack", apply_to_all_doctypes=1
type_of_transaction="Both",
dimension_name="Rack",
apply_to_all_doctypes=1,
fetch_from_parent="Rack",
) )
self.assertEqual(inv_dimension.type_of_transaction, "Both")
self.assertEqual(inv_dimension.fetch_from_parent, "Rack")
create_custom_field( create_custom_field(
"Purchase Receipt", dict(fieldname="rack", label="Rack", fieldtype="Link", options="Rack") "Purchase Receipt", dict(fieldname="rack", label="Rack", fieldtype="Link", options="Rack")
) )