Hi,
I have doctype x which is submitted and i updated one field in x say due_amount via other doctype y
but when i take submitted doc x again the due_amount is not updated but it will update when i refresh the doc type
what have i tried is
what i have done to update due_amount is
in y.py i wrote following code
def on_submit(self):
ohb = frappe.get_doc("x",reference.reference_name)
ohb.update_due_amount(self.paid_amount,reference.reference_name)
update_due_amount in x.py has following code
def update_due_amount(self,name_of_doctype):
frappe.db.sql("""update `tabx` set due_amount = '{0}' where name ='{2}'""".format(due_amount,amount_paid,name_of_doctype))
but when i take the submitted doctype of x it is not updated unitll i refresh the page
so to refresh the page
i wrote this code in x.js
frappe.ui.form.on('Hotel Booking', {
refresh: function(frm) {
frm.events.check_difference(frm,frm.doc.due_amount);
},
check_difference: function(frm,due_amount){
frappe.call({
method: "ims.ims.doctype.x.x.get_due_amount",
args : {
"dt" : frm.doc.doctype,
"dn": frm.doc.name,
"due_amount":due_amount
},
callback:function(r)
{
if(!r.exec)
{
if(r.message != due_amount)
{
location.reload();
}
}
}
})
}
});
get_due_amount in x.py has this code
@frappe.whitelist()
def get_due_amount(dt,dn,due_amount):
hb = frappe.get_doc("x",dn)
due_amount = hb.due_amount
return due_amount
but i would like to know is there any better way to do this with out refreshing the form