Try to use onload instead of setup function.
Please put some logs to see if the function is being called.
Try to use onload instead of setup function.
Please put some logs to see if the function is being called.
What is the advantage / difference in putting the js script in a file vs the custom script area?
If you put the script inside the file (under erpnext app), then it can give conflict when update.
I tried to use onload function in both JS file and Custom Script and it still does not work.
It’s “funny” that, although I’m not using any filter and I do not see a filter in JS / PY files, the production_item field to select the item to be manufactured is being filtered by an item group by default, an item group that I created.
@schilgod, exactly, where can I view the logs that refer to the loading of that function?
try to put console.log(); in the function
I putted console.log()
in the function and nothing happens.
please show your code…
print something in console, console.log(‘testing’);
@nabinhait code should work as it is,
Reload and try?
I put console.log(‘testing’);
and only this is returned when I click on New button to create a Production Order:
SyntaxError: Invalid or unexpected token
at Class.setup (http://192.168.1.54:8080/assets/js/form.min.js?ver=1532940019.0:2693:18)
at _f.Frm.setup (http://192.168.1.54:8080/assets/js/form.min.js?ver=1532940019.0:172:22)
at _f.Frm.refresh (http://192.168.1.54:8080/assets/js/form.min.js?ver=1532940019.0:446:9)
at Class.load (http://192.168.1.54:8080/assets/js/form.min.js?ver=1532940019.0:87:33)
at http://192.168.1.54:8080/assets/js/form.min.js?ver=1532940019.0:82:7
at Object.with_doc (http://192.168.1.54:8080/assets/js/desk.min.js?ver=1532940019.0:5505:4)
at Class.show_doc (http://192.168.1.54:8080/assets/js/form.min.js?ver=1532940019.0:65:16)
at http://192.168.1.54:8080/assets/js/form.min.js?ver=1532940019.0:24:8
at Object.with_doctype (http://192.168.1.54:8080/assets/js/desk.min.js?ver=1532940019.0:5444:17)
at Class.make (http://192.168.1.54:8080/assets/js/form.min.js?ver=1532940019.0:20:17)
very strange, the code should work as it is, unless you made some change to it.
Error seems something related to quotes
The only changes I made to the code were to change Type 1, Type 2, Group 1 and Group 2 by their real names, and I am sure there are no errors with types and groups.
in that case check quotes…
The code is the following:
frappe.ui.form.on("production_order", {
setup: function (frm) {
console.log('testing');
var item_group = "";
if (frm.doc.item_type == "Compund") {
item_group = "Compounds";
} else
if (frm.doc.item_type == "Raw material") {
item_group = "Raw material";
}
frm.set_value({
"wip_warehouse": "WIP Warehouse",
"fg_warehouse": item_group
});
frm.set_query("production_item", function () {
return {
query: "erpnext.controllers.queries.item_query",
filters: {
'is_stock_item': 1,
'item_group': item_group
}
};
});
}
});
And report by JSHint is the following:
Metrics
There are 2 functions in this file.
Function with the largest signature take 1 arguments, while the median is 0.5.
Largest function has 7 statements in it, while the median is 4.
The most complex function has a cyclomatic complexity value of 3 while the median is 2.
One undefined variable
12 frappe
warehouse should be with company abbr eg: “Work In Progress - ABBR”
I just tried on my development setup, it works.
share your ui screenshot
I modified the code so that the abbreviation of the company was not inserted in the name of the warehouse to try to make it clearer. At the request of my boss.
Is it meaningful not to include the company’s abbreviation?
Exactly, what part of the UI do you want me to share?
Do you mean you modified Warehouse doctype, to save without abbr?
Without abbr warehouse name is invalid. it wont allow you to save anyways.
Share your page, where you r customization like item_type field, warehouse field etc are visible, with console
frappe.ui.form.on("Production Order", {
setup: function(frm) {
var item_group = "";
if (frm.doc.item_type == "Compund") {
item_group = "Compounds";
} else
if (frm.doc.item_type == "Raw material") {
item_group = "Raw material";
}
frm.set_value({
"wip_warehouse": "Work In Progress",
"fg_warehouse": item_group
});
frm.set_query("production_item", function () {
return {
query: "erpnext.controllers.queries.item_query",
filters: {
'is_stock_item': 1,
'item_group': item_group
}
}
});
}
})
The above code works on my local machine. I added a field item_type
Thank you very much for your patience and your help @schilgod.
I am having many problems with my ERPNext and I need to do many things that until now are impossible for me to do because I only get errors.
And now, when a I click over the production_item field, I get this error:
Traceback (most recent call last):
File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 62, in application
response = frappe.handler.handle()
File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 22, in handle
data = execute_cmd(cmd)
File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 53, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 939, in call
return fn(*args, **newargs)
File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/search.py", line 14, in search_link
search_widget(doctype, txt, query, searchfield=searchfield, page_length=page_length, filters=filters)
File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/search.py", line 35, in search_widget
searchfield, start, page_length, filters, as_dict=as_dict)
File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 939, in call
return fn(*args, **newargs)
File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/queries.py", line 178, in item_query
fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'),
File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/reportview.py", line 357, in get_filters_cond
if isinstance(f[1], string_types) and f[1][0] == '!':
IndexError: string index out of range