Calling py function from js!

Hello ,
I am trying in my doctype to call function and do some python code then call back the result
I try every thing but I still have strange problem !!
Here is my code, so when employee feild change the method will run but here it didnt !

 employee: function(frm) {
      return frappe.call({
        method: "erpnext.hr.doctype.end_of_service_award.end_of_service_award.get_it",
        args: {
          salary: frm.doc.salary,
        },
        callback: function(r) {
          if (r.message) {
              alert("done");
          }
        }
      });
  },

And here is my python code

@frappe.whitelist()
def get_it(self,salary):
    ss = salary
    return ss

I wonder what is my problem !
I also try to call the function by using doc: cur_frm.doc, but it didnt work with me !
Thanks all

where did u put this code?

In the same doctype’s python file

please copy and past the path

when I try to make new function and call it it say:
AttributeError: ‘module’ object has no attribute ‘get_it’
here is my code

frappe.ui.form.on(‘End of Service Award’, {
refresh: function(frm) {
employment(frm);
},

});

function employment(frm) {
return frappe.call({
method: “erpnext.hr.doctype.end_of_service_award.end_of_service_award.get_it”,
// args: {
// salary: frm.doc.salary,
// },
callback: function(r) {
if (r.message) {
alert(“done”);
// frm.set_value(‘salary’, r.message);
}
}
});
};

and here is my python code

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

class EndofServiceAward(Document):
def get_it(self):
return “done”

what’s the path of the python file?

the doctype file path

the path seems to be correct, try:

@frappe.whitelist()
def get_it(salary):
    ss = salary
    return ss

It didnt work

what’s the error?

Can you past all the py file?

It stop working , js problem

can you past the py file?

Here is my code

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

class EndofServiceAward(Document):
pass

@frappe.whitelist()
def get_it(salary):
ss = salary
return ss

its indented like this?

class EndofServiceAward(Document):
      pass

@frappe.whitelist()
def get_it(salary):
     ss = salary
     return ss

Yes ,exactly

can’t find the error, sorry. I think it’s an error on method call, but can’t actually find it … try to move end_of_service_award.py in the path …

1 Like

Ok, I am trying with it
thanks any way :slight_smile:

Hi,
Check the js function trigger or not when change employee filed’s value,If not trigger error in js side so check and clear [quote=“OmarJaber, post:1, topic:20375”]
end_of_service_award
[/quote]than proceed next step.

1 Like

thanks for helping,
The code is correct, it was browser problem
thanks all :slight_smile: