Skip to content

Commit ab8723a

Browse files
committed
feat: implement UOM specific dimensions for Item
1 parent 93eee70 commit ab8723a

7 files changed

Lines changed: 293 additions & 209 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ repos:
4545
additional_dependencies: ['flake8-bugbear']
4646

4747
- repo: https://github.com/agritheory/test_utils
48-
rev: v1.23.0
48+
rev: v1.25.1
4949
hooks:
5050
- id: update_pre_commit_config
5151
- id: validate_frappe_project

inventory_tools/inventory_tools/doctype/physical_dimension/physical_dimension.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ frappe.ui.form.on('Physical Dimension', {
99
},
1010
}))
1111
},
12+
reference_doctype(frm) {
13+
if (frm.doc.reference_doctype !== 'Item') {
14+
frm.set_value('item_uom', '')
15+
}
16+
set_item_uom_read_only_for_item_reference(frm)
17+
set_item_uom_from_item_stock_uom(frm)
18+
},
19+
reference_document(frm) {
20+
set_item_uom_read_only_for_item_reference(frm)
21+
set_item_uom_from_item_stock_uom(frm)
22+
},
1223
item_height(frm) {
1324
frm.trigger('calculate_item_volume')
1425
},
@@ -22,3 +33,20 @@ frappe.ui.form.on('Physical Dimension', {
2233
frm.set_value('item_volume', frm.doc.item_length * frm.doc.item_width * frm.doc.item_height)
2334
},
2435
})
36+
37+
function set_item_uom_read_only_for_item_reference(frm) {
38+
const locked = frm.doc.reference_doctype === 'Item'
39+
frm.set_df_property('item_uom', 'read_only', locked ? 1 : 0)
40+
}
41+
42+
function set_item_uom_from_item_stock_uom(frm) {
43+
if (frm.doc.reference_doctype !== 'Item' || !frm.doc.reference_document || frm.doc.item_uom) {
44+
return
45+
}
46+
return frappe.db.get_value('Item', frm.doc.reference_document, 'stock_uom').then(r => {
47+
const stock_uom = r?.message?.stock_uom
48+
if (stock_uom) {
49+
return frm.set_value('item_uom', stock_uom)
50+
}
51+
})
52+
}

0 commit comments

Comments
 (0)