Hi guys, im trying to add new record automatically in Doctype B before i save Doctype A but im getting allways the same error.
ERROR:
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 61, in application
response = frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 21, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 56, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1036, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/uni3/doctype/doctypeA/doctypeA.py”, line 28, in create_test
NameError: name ‘cur_frm’ is not defined
You pass functionario_empresa parameter to the frappe.call() but to not receive any parameters on the Python side. Add a parameter with the same name to the Python function. You will also need to frappe.parse_json() on the parameter, to extract the serialised data:
Try to frappe.msgprint() the contents of the passed variable on the Python side (the print function works exactly the same as on the JS side) to see how to handle it. I don’t remember right away how the API system handles serialized parameters. I think some of the data types get converted on the fly.
Im going to try to explain better how the doctypes are working so it may help in the resolution.
Doctype A (Licencas) has a link field to Doctype C (cliente) called “fetch_cliente”
Doctype B (Funcionarios) has a link field to Doctype C (Cliente) called “fetch_cliente”
And what i want is:
On save of doctype A create a new record in Doctype B “Funcionarios”
If i do "bench execute erpnext.uni3.doctype.licencas.licencas.create_funcionario --args “Teste” the record is created so i think the python is working.
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 66, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 56, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 21, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 56, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1036, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/uni3/doctype/licencas/licencas.py”, line 28, in create_funcionario
NameError: name ‘cur_frm’ is not defined
Try creating similar simple test api method and access it from the browser. Once you get a correct response, you can build on that, starting with using the JS to poke that method.
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 66, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 56, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 21, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 45, in execute_cmd
raise e
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 42, in execute_cmd
method = get_attr(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 135, in get_attr
method = frappe.get_attr(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1027, in get_attr
return getattr(get_module(modulename), methodname)
AttributeError: module ‘erpnext.uni3.doctype.licencas.licencas’ has no attribute ‘test_method’
then i tried to call it in the browser and gave me the same error as before
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 66, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 56, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 21, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 45, in execute_cmd
raise e
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 42, in execute_cmd
method = get_attr(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 135, in get_attr
method = frappe.get_attr(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1027, in get_attr
return getattr(get_module(modulename), methodname)
AttributeError: module ‘erpnext.crm.doctype.dc_doc_desdoc_meta.dc_doc_desdoc_meta’ has no attribute ‘test_method’