Try ERPNext Buy Support Partners Foundation

Cannot access attributes in custom doctype: AttributeError: module 'sntg.sonith_app.doctype.sonith_thing' has no attribute 'some_method'

Hi,

I’m quite new to erpNext and seem to be missing something essential.

I’m trying to access server-side attributes in a custom doctype via js but I keep getting this error:

#### Something went wrong
  
Server Error: Please check your server logs or contact tech support.

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 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 'sntg.sonith_app.doctype.sonith_thing' has no attribute 'some_method' </code>

my js looks like this:

frappe.ui.form.on('Sonith Thing', {
    onload: function(frm){do_something(frm)
});

function do_something(frm){
    frappe.call({
        method: 'sntg.sonith_app.doctype.sonith_thing.some_method', 
	callback: (r) => {
	    cur_frm.set_value('description', 'please!')
	}
    })
}

my py looks like this:

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document

class SonithThing(Document):
    #pass
    def __init__(self):
	 self.some_attribute="this is some attribute"

@frappe.whitelist()
def some_method(self):
    return "anything"

further infos

  • The files are located at /frappe-bench/apps/sntg/sntg/sonith_app/doctype/sonith_thing/sonith_thing.py (or .js respectively)
  • I can get neither the attribute nor the method, I always get the ‘module x has no attribute y error’
  • when I put some other method (e.g. ‘frappe.core.doctype.user.user.get_timezones’) I get some data

Any help will be greatly appreciated!

if the path u gave at the bottom is correct, then you should be calling your function with this,

 sntg.sonith_app.doctype.sonith_thing.sonith_thing.some_method

not this

sntg.sonith_app.doctype.sonith_thing.some_method

You are right!! I tried so many paths and I would have probably bet my life on having tried this one as well. Obviously I did not. Thank you so much!