ERPNext Conference 2019* ERPNext.com Blog

Calling py function from js!

customization

#1

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


Hide field using python
#2

where did u put this code?


#3

In the same doctype’s python file


#5

please copy and past the path


#6

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® {
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”


#7

what’s the path of the python file?


#8

the doctype file path


#9

the path seems to be correct, try:

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

#10

It didnt work


#11

what’s the error?

Can you past all the py file?


#12

It stop working , js problem


#13

can you past the py file?


#14

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


#15

its indented like this?

class EndofServiceAward(Document):
      pass

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

#16

Yes ,exactly


#17

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 …


#18

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


#19

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.


#20

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


#21