Unable to Add functionality

Hi there,
I am trying to add a button in offer letter.
The function it’ll do is that if the employee is created the button will change to view employee.
But it still remains to be make employee.
I am not able to retrieve data of the employee whose offer letter is open.
Please provided me with your valuable feedback.

I am pasting my python script since its not able to retrieve data.

Python Script is as follows:

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

class OfferLetter(Document):
def onload(self):
employee = frappe.get_all(“Employee”, filters={“employee”: self.applicant_nam})
if employee:
self.get(“__onload”).employee = employee[0].employee

I will also show you my javascript for the same…

The button script specifically

refresh: function(frm){

    if(!frm.doc.__islocal)
        {
        if(cur_frm.doc.__onload && cur_frm.doc.__onload.employee){
            if(cur_frm.doc.status=='Accepted' && frm.doc.docstatus===1)
            {
                cur_frm.add_custom_button(__("View Employee"), function() {
                frappe.set_route("Form", "Employee", cur_frm.doc.__onload.employee);
            },
        __());
        }
    }
            else
                    {
                        frm.add_custom_button(__('Make Employee'),function() {
                                if(frm.doc.status=='Accepted' && frm.doc.docstatus===1){
                                        erpnext.offer_letter.make_employee(frm)
                                }
                            },
                        __());
                    }
        }
    }

Can you add console.log("Conditions are true") after condition and check console log if it is even getting inside the block.

No mam its not heading inside if block

may be if block conditions are not met.
Can u provide help for the same.

The thing i want to perform is that after making employee by changing the status of the offer letter to accepted and then creating the employee whenever i go to the offer letter tab of the employee it still has that make employee button which i want to change to view employee.

And other thing I need is that whenever I click on make employee then the offer date in employee module must be same as the date in offer letter how can i do that?

Is this is python method under offer_letter.py ?

If yes, then you can not call the Python/Server Script methods directly from the Javascript / Client Script
You will need ajax call for such purpose. Frappe framework has built in ajax method for this. please use frappe.call method to call the server script method from client side.

below is the basic syntax for frappe.call also, you will find the number of example of frappe.call in all the *.js files available in erpnext & frappe

frappe.call({
	method: "path.to.your.method",
	args: {
		// pass arguments to method
	},
	callback: function(r){
		// callback, you will get the return value in r.message
	}
})

hope this would help!!

Hi there,

Sir , I didnt understand you properly. What i want to achieve is that i just want that whenever a employee is created the make employee button to change to view employee or even if the make employee button could vanish will do the work.
the method which you described is already given by default. the calls made by the system is default I havent made changes to it.
I just want to execute my If Condition.
Any Way?

check if above conditions are true or false

Hi there,
The problem is its not gng under the super if blck where it checks whether the employee is created.
Can u suggest me how i can check whether the employee is created in offer letter.
So that i can keep a condition.