@netchampfaris here is my code
from JS
// Copyright (c) 2016, Helio de Jesus and contributors
// For license information, please see license.txt
cx_open =cur_frm.call({method:“check_caixa_aberto”,args:{“start”:“none”}})
caixaaber =cur_frm.call({method:“caixa_aberto”,args:{“start”:“none”}})
frappe.ui.form.on(‘BAR_RESTAURANTE’, {
onload: function(frm) {
frappe.call({
method:“frappe.client.get_list”,
args:{
doctype:“CAIXA_Registadora”,
filters: {
status_caixa:[‘in’, ‘Aberto, Em Curso’]
},
fields: [“status_caixa”]
},
callback: function(r) {
if (r.message) {
$.each(r.message, function(i,d) {
console.log(i.toString() + ": " + d.status_caixa);
caixaopen = d.status_caixa;
});
}
}
});
});
frappe.ui.form.on(‘BAR_RESTAURANTE’, {
refresh: function(frm) {
alert(“Abrir o Caixa”)
});
by adding an Alert on the Refresh I can get the Result of the cur_frm.call I have made for both and the call on the Load…
ON PY
@frappe.whitelist()
def caixa_aberto():
return frappe.get_list(“CAIXA_Registadora”,filters={‘status_caixa’:[‘in’, ‘Aberto, Em Curso’]},fields=[‘name’,‘status_caixa’])
@frappe.whitelist()
def check_caixa_aberto():
if (frappe.db.sql("""select name from `tabCAIXA_Registadora` WHERE status_caixa ='Aberto' """, as_dict=False)) != ():
return frappe.db.sql("""select name from `tabCAIXA_Registadora` WHERE status_caixa ='Aberto' """, as_dict=False)
elif (frappe.db.sql("""select name from `tabCAIXA_Registadora` WHERE status_caixa ='Em Curso' """, as_dict=False)) != ():
return frappe.db.sql("""select name from `tabCAIXA_Registadora` WHERE status_caixa ='Em Curso' """, as_dict=False)
If I don’t alert the variables take time to get values …unless I unload I go back to the grid and open again the form/doctype …
I have tried Fetch and does not load the values I need …
Wonder why cannot call frappe.get_list from JS as this allows filters!!!