Skip to content

Commit

Permalink
Merge pull request #33 from agritheory/uom_enforcement_fix
Browse files Browse the repository at this point in the history
fix: make uom enforcement respond better to toggle on/off
  • Loading branch information
HKuz authored Sep 12, 2023
2 parents 4264bdd + f82b590 commit 13ad883
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
6 changes: 3 additions & 3 deletions inventory_tools/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

# Boot
# ------------
extend_bootinfo = "inventory_tools.inventory_tools.boot.boot_session"
# extend_bootinfo = "inventory_tools.inventory_tools.boot.boot_session"


# Desk Notifications
Expand Down Expand Up @@ -133,9 +133,9 @@
"Item": {
"validate": ["inventory_tools.inventory_tools.overrides.uom.duplicate_weight_to_uom_conversion"],
},
"Warehouse": {
"Warehouse": {
"validate": ["inventory_tools.inventory_tools.overrides.warehouse.update_warehouse_path"]
},
},
}

# Scheduled Tasks
Expand Down
11 changes: 0 additions & 11 deletions inventory_tools/inventory_tools/boot.py

This file was deleted.

11 changes: 10 additions & 1 deletion inventory_tools/inventory_tools/overrides/uom.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ def uom_restricted_query(doctype, txt, searchfield, start, page_len, filters):
limit_page_length=page_len,
as_list=True,
)
return search_link(doctype, txt, searchfield, start, page_len, filters)
if "parent" in filters:
filters.pop("parent")
return execute(
"UOM",
filters=filters,
fields=[searchfield],
limit_start=start,
limit_page_length=page_len,
as_list=True,
)


@frappe.whitelist()
Expand Down
33 changes: 17 additions & 16 deletions inventory_tools/public/js/uom_enforcement.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright(c) 2023, AgriTheory and contributors
// For license information, please see license.txt

// if the route == "Form" check if it's in the uom_enforcement object
// then apply

frappe.provide('frappe.ui.form')

$(document).on('page-change', () => {
Expand All @@ -13,23 +10,27 @@ $(document).on('page-change', () => {
function page_changed() {
frappe.after_ajax(() => {
const route = frappe.get_route()
if (route[0] == 'Form' && Object.keys(frappe.boot.inventory_tools.uom_enforcement).includes(route[1])) {
frappe.ui.form.on(route[1], {
onload: frm => {
setup_uom_enforcement(frm)
},
})
frappe.ui.form.on(route[1], {
refresh: frm => {
setup_uom_enforcement(frm)
},
})
}
frappe.call('inventory_tools.inventory_tools.overrides.uom.get_uom_enforcement').then(r => {
frappe.uom_enforcement = r.message
if (route[0] == 'Form' && Object.keys(frappe.uom_enforcement).includes(route[1])) {
frappe.ui.form.on(route[1], {
onload_post_render: frm => {
// onload runs too soon
setup_uom_enforcement(frm)
},
})
frappe.ui.form.on(route[1], {
refresh: frm => {
setup_uom_enforcement(frm)
},
})
}
})
})
}

function setup_uom_enforcement(frm) {
for (const [form_doctype, config] of Object.entries(frappe.boot.inventory_tools.uom_enforcement[frm.doc.doctype])) {
for (const [form_doctype, config] of Object.entries(frappe.uom_enforcement[frm.doc.doctype])) {
// form setup
if (frm.doc.doctype == form_doctype) {
config.forEach(field => {
Expand Down

0 comments on commit 13ad883

Please sign in to comment.