Hi, I am working with custom scripts in ERPNext to help enforce some rules. So far, Its going ok, but I am struggling to check connected forms from the script item… For example:
frappe.ui.form.on(‘Stock Entry’, {
validate(frm) {
if (stock_entry_type == ‘Material Receipt’)
{
for (var row in doc.items)
{
???
}
}
}
});
I have a Stock Entry Item. when this is validated, I would like to check that the item being added to stock does not have a connected BOM. Can anyone point me to the correct Jinja / JS code that would return a list of connected BOMs to the items on the stock entry? I do not want to use the “manufacturing” checkbox on the item as we do have nested BOMs.
The end result is to inhibit the Save / Submit button on a “Material Receipt” IF any item within the stock entry has a BOM. We should use the Work Order to create these items. They cannot simply be added.
Thanks!
Hi Phil,
Offhand, I do not know which JS function(s) might yield the data you need: Given a single Item,
does that Item
have any associated BOMs? (yes/no)
Is your ERPNext self-hosted, or are you using a service provider’s cloud?
A few options I can think of:
-
Try doing some wildcard searches in the JS code files related to Items and BOMs. You might get lucky.
-
If you can, write your own Python function that yields the answer:
@frappe.whitelist()
def does_item_have_boms(item_code):
# ....
# returns a True/False
Then call this function from your JS code, using 'frappe.call()'
- Don’t write any JS code at all. Instead, modify the Document controller functions (server-side Python) related to Save and Submit.
For these situations, I spend a little time searching for out-of-the-box code. But if I cannot find it? I just create my own. It’s not worth being stuck hours/days, trying to find something, when you could have already written your own solution.
Later, if you do stumble on the out-of-the-box equivalent? Great. Then you can always go back and replace your custom function, with that one.
we are self hosted, so I will investigate the python example. Thanks!