But it always shows “Not Permitted” upon item code change. Error on console:
File "/home/vef/frappe-bench/apps/frappe/frappe/app.py", line 67, in application
response = frappe.handler.handle()
File "/home/vef/frappe-bench/apps/frappe/frappe/handler.py", line 75, in handle
execute_cmd(cmd)
File "/home/vef/frappe-bench/apps/frappe/frappe/handler.py", line 107, in execute_cmd
raise frappe.PermissionError('Not Allowed, {0}'.format(method))
PermissionError: Not Allowed, <function get_incoming_rate at 0x7fd9743e5398>
104, in get_incoming_rate
previous_sle = get_previous_sle(args)
File "/home/vef/frappe-bench/apps/erpnext/erpnext/stock/stock_ledger.py", line 359, in get_previous_sle
sle = get_stock_ledger_entries(args, "<=", "desc", "limit 1", for_update=for_update)
File "/home/vef/frappe-bench/apps/erpnext/erpnext/stock/stock_ledger.py", line 384, in get_stock_ledger_entries
}, previous_sle, as_dict=1, debug=debug)
File "/home/vef/frappe-bench/apps/frappe/frappe/database.py", line 135, in sql
self._cursor.execute(query, values)
File "/home/vef/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 185, in execute
for key, item in args.iteritems())
KeyError: 'warehouse'
I need to trigger the function after item (warehouse) is fetched. frappe.ui.form.on("Delivery Note Item", "refresh", function(frm, cdt, cdn) also doesn’t work…
Above code is not working because on item_code change event, item details like warehouse etc are not fetched yet. It’s fetched on 2nd field change.
I get this working by using another trigger from a custom field. I created custom field: imei_serial_no to pull item_code then trigger get_incoming_rate. But I believe there’s more simple way to do this. This is just the matter how we trigger events. I just want to fire the function after all item-details are fetched. Is there any example?
This is because of asynchronous behaviour of javascript. Actually, your function should be called on callback of get_item_details function. But while doing customization, you can’t do that.
Here, may be you should fetch incoming rate in validate function, in that case, rate will be fetched on saving of the document.