Pass values from .py to .js

Hi guys, I’m do this query in salary_slip.py:

frappe.db.sql(“”“select base from tabSalary Structure Employee
where employee=%s and (from_date <= %s or from_date <= %s)
and (to_date is null or to_date >= %s or to_date >= %s)
and parent in (select name from tabSalary Structure
where is_active = ‘Yes’%s)
“””% (‘%s’, ‘%s’, ‘%s’,‘%s’,‘%s’, cond),(self.employee, self.start_date, joining_date, self.end_date, relieving_date))

How I pass the result of query to the salary_slip. js?

Thanks!

Structure this as a callback from JS:

frappe.call({
	method: "rodolfos_python_method",
	   doc: frm.doc
	 }).done((r) => {
	     console.log(r.message);
     }).fail((r) => {
	     console.log(r);
     });

When do you want this sql query to trigger?

1 Like

Hi tmatteson, when I consult the Salary Slip because with the result this query I need to do a multiplication for a decimal and the result show it in front-end of salary slip… thanks.

I assume it’s going into a custom field in salary slip?
So this will need to go in as a Custom Script (search for “Custom Script List” in the awesome bar) and then point to the file where your python code resides. You can then set the field when it returns (r.message) with frm.set_value("name_of_custom_field", r.message)

You’ll need to decided what it should be triggered on: look at this list.

Hi tmatteson, yes, I have in the form of the Salary Slip several custom fields, here I show you:

The amount (10000) on the SENA title, that I put on manually from mysql with an Update sentence but that I need is to do a query from a SELECT from salary_slip.py, save in a variable and so to do a multiplication on the .py and then execute an UPDATE sentence on the tabSalary Structure Employee table with the new value, It inserted, the amount automatically shows on the Front-End…

This way that I understand, please you correct me…

¿Puedes explicar que esto son oraciones cortas en castellano? No quiero que haya una barrera idiomática para conseguir ayuda y hablo un poco de español.

English: Can you restate this in a few short sentences in Spanish? I speak some and I don’t want there to be a language barrier.

1 Like

si claro

Necesito hacer esto:

frappe.db.sql(“”“select base from tabSalary Structure Employee
where employee=%s and (from_date <= %s or from_date <= %s)
and (to_date is null or to_date >= %s or to_date >= %s)
and parent in (select name from tabSalary Structure
where is_active = ‘Yes’%s)
”“”% (’%s’, ‘%s’, ‘%s’,’%s’,’%s’, cond),(self.employee, self.start_date, joining_date, self.end_date, relieving_date))

desde salary_slip.py

luego el resultado guardarlo en una variable.

Esa variable multiplicarla por un decimal y guardarla en la variable.

Ese resultado enviarlo con un UPDATE a la tabla tabSalary Slip.

Eso es todo! Gracias.

Todavía no estoy seguro de cómo se desencadena la función en salary_slip.py, que es la parte de su pregunta que solicitó ayuda. Propongo este código en Custom Script ListSalary Slip-Client:

frappe.ui.form.on('Salary Slip', {
    SENA: function(frm) { // this will call the python method on change
frappe.call({
	method: "rodolfos_python_method_in_salary_slip.py",
	   doc: frm.doc // calls a method from salary_slip.py
	 }).done((r) => {
	     console.log(r.message); // if you are returning anything
     }).fail((r) => {
	     console.log(r);
     });
  }
})

Hay dos métodos para impulsar la salida de SENA:
En rodolfos_python_method_in_salary_slip.py:
self.SENA = # las matemáticas
En Salary Slip-Client:
frm.doc.set_value(r.message) // de return de rodolfos_python_method_in_salary_slip.py

Yo prefiero la segunda. Buena suerte!

Oi @Rodolfo_Pablo_Silva ! Como esta su codigo indo?
Let me know if you are past this problem or if you still need help.