Process Payroll customization

Hi all,

I am trying to pass the object but is not working … so what am i not doing well to have it running?
Thanks in advance for the support.

	cur_frm.call({
                    "docs":cur_frm.doc,			
		"method": "angola_erp.angola_erpnext.validations.process_payroll.submit_salary_slips1",
		"args": {
                       "docs":cur_frm.doc
                    },							
		callback: function(r,rt) {
			if (r.message){
				frappe.model.set_value(cdt,cdn,'processa_inss',1);  
			}
		}

	});	

my PY

@frappe.whitelist()
def submit_salary_slips1(self):
print “SUBMETER SALARIOSSSSSSSSS”
print self
print self.start_date
ss = {}
ss = self
print ss[“end_date”]
return

Try this out ?
Im not sure that by sending docs variable assigns self in python.
The following should work

cur_frm.call({              
	"method": "angola_erp.angola_erpnext.validations.process_payroll.submit_salary_slips1",
	"args": {
             "doc":cur_frm.doc
         },							
	callback: function(r,rt) {
			if (r.message){
				frappe.model.set_value(cdt,cdn,'processa_inss',1);  
			}
		}

	});
@frappe.whitelist()
def submit_salary_slips1(doc):
    print "SUBMETER SALARIOSSSSSSSSS"    
    print doc.start_date    
    return

Hope it helps

Thanks for the help but i had tried this and it did not work … the error it returns is
‘unicode’ object has no attribute ‘start_date’

and if i try to print doc[‘start_date’] the below error is returned

string indices must be integers

if i change
cur_frm.call({
“doc”:cur_frm.doc,
“method”: “angola_erp.angola_erpnext.validations.process_payroll.submit_salary_slips1”,
“args”: {
“docs”:cur_frm.doc
},
callback: function(r,rt) {
if (r.message){
frappe.model.set_value(cdt,cdn,‘processa_inss’,1);
}
}

});

the return error is
‘ProcessPayroll’ object has no attribute ‘angola_erp.angola_erpnext.validations.process_payroll.submit_salary_slips1’

@Helio_Jesus

What are you trying to achieve?
cur_frm.call is same as frappe.call which call method from .py file of the same form/doctype.

try this,

In .js

cur_frm.call({
	method: "submit_salary_slips1",
	doc:cur_frm.doc,
	callback: function(r) {
		if (r.message){
			cur_frm.set_value('processa_inss',1);  
		}
	}
}); 

In .py

def submit_salary_slips1(self):
	#do your operations here
	return "Success"

In regards to your post here … you chose a completely non-related subject line (which is never a good idea)

@Sangram thanks for the support … what i need is to submit the salary slip by running the submit_salary_slips that was created by ERPNEXT … but this one has some other code to process or data to add on the JE …
For example i need to add two rows with account 3450 as debit and 3221 as credit and only after the JE is generated or created.
The only way i have found to add those records was by orver writing the button with my own submit salary slip and add my code but when i try to call the method and when executing the PY the object properties like self.start_date and other fields are not valid it returns errors…

I need to execute all the code that the ERPNEXT Submit_salary_slip has but from my Validations.process_payroll.py

I hope i have managed to explain my point.
Once again thanks.

Hi,
Sorry but as i have been trying to have this working for almost 2 days i thought that by asking the community would be the quickest way to have it solved.

Write Custom Script to override submit_salary_slip button click.

Custom Script

e.g.

cur_frm.cscript.submit_salary_slip = function(doc, cdt, cdn) { 
	//Do your customization here. Copy paste default code along with your custom script. So, it will not break the flow.
}

Community member will guide you.

That was done already … now the issue is with the Py as i explained… to call the method and pass cur_frm.doc so i can execute the other steps.

cur_frm.call({
	method: "submit_salary_slips1",
	doc:cur_frm.doc,
        args: {"key": value},
	callback: function(r) {}
});

or simply use frappe.call

	frappe.call({
		method: "dotted.method.path",
		args: {key:value},
		callback: function(r){}
	})
	frappe.call({
		"method": "angola_erp.angola_erpnext.validations.process_payroll.submit_salary_slips1",
                    "args":{
			"doc":cur_frm.doc,
		},			
		callback: function(r,rt) {
			if (r.message){
				frappe.model.set_value(cdt,cdn,'processa_inss',1);  
			}
		}

	});	

and on PY should i use

class ProcessPayroll(Document):
def init(self):
pass

   @frappe.whitelist()
   def submit_salary_slips1(self):
   print "SUBMETER SALARIOSSSSSSSSS"
 	   print self.start_date
return

OR

@frappe.whitelist()
def submit_salary_slips1(self):
	print "SUBMETER SALARIOSSSSSSSSS"
	print self.start_date

	return

if like this it says submit_salary_slips1() takes exactly 1 argument (0 given)

if the cur_frm.doc object returns a Dict cant i create a DICT when submit_salary_slip1 is called so that the other functions will access the data or information the object has ?
I have managed to have it working before but the problem was that when i do doc.get(‘start_date’) it returned error.

try this

you passed argument doc and accessing self?

@frappe.whitelist()
def submit_salary_slips1(doc):
	print "SUBMETER SALARIOSSSSSSSSS"
	print self.start_date
	return

This is the result
global name ‘self’ is not defined

:frowning:

print doc.start_date

before starting with customization check basics of Python

when adding this the result as before ‘unicode’ object has no attribute ‘start_date’

I have done the reading and continue to search for solution …
But thanks for the support and solutions.

convert unicode data using json.loads()

 @frappe.whitelist()
    def submit_salary_slips1(doc):
        doc = json.loads(doc)
    	print "SUBMETER SALARIOSSSSSSSSS"
    	print doc.start_date
    	return

If the method is in doctype class, you can simply set

'method': 'submit_salary_slip'

You can access self variable then.
See the example

You dont even need to whitelist the method.
Hope it helps

Thanks for the support, but i for what i need to do i think i need the whitelist …
to run or execute all the code run on erpnext process_payroll.py i had to copy the file to my angola_erpnext.validation.process_payroll
And on the PY i have copied i will make the changes i need … reason why i need the whitelist and to pass the object or dict me.doc/cur_frm.doc in order to be able to doc.get(‘start_date’) which is executed on this

def check_mandatory(self):
for fieldname in [‘company’, ‘start_date’, ‘end_date’]:
if not self.get(fieldname):
frappe.throw(_(“Please set {0}”).format(self.meta.get_label(fieldname)))

Oh ok, so its not in the doctype py class.
Did you follow this code exactly ?

Edit: you cant access self variable in your case, you have to pass the doc as an argument
Edit: as @Sangram pointed out, you might have to do json.loads