Hello,
I’m trying to calculate sales invoice line item amount with tax. I have a custom field to show tax percentage as well.
When I try to console log in item details, the amount is shows in the list. but when I try to fetch it from the list it’s 0. then I select another item in the same row it’s showing me a previous items value.
So, I set time out to check it and still output is same.
and I try field name as event as mentioned here but it’s not running at all->Form Scripts
but when I change the item the correct amount is display in the readonly field.
and I tried to make the field writable which is not success. I have added my code here.
Could you please help me for this ? Also, Please note this is not print purpose. and there will be another couple of fields for line item tax and amount incl tax.I just want to read the amount to calculate value for above fields.
TIA
frappe.ui.form.on('Sales Invoice Item', {
refresh: function(frm){
frm.set_df_property("amount", "read_only", 0);
},
item_code: function(frm,cdt,cdn){
var doc = locals[cdt][cdn];
//frm.set_df_property("doc.amount", "read_only", 0);
console.log(doc); // the amount is showing in this list
console.log(doc.amount); // but this is 0
frappe.db.get_doc('Item', doc.item_code).then(item=>{
console.log("item");
console.log(item);
console.log("item rate");
console.log(item.custom_tax_rate);
frappe.model.set_value(cdt, cdn, "custom_tax_rate", item.custom_tax_rate);
});
setTimeout(() => {
console.log("doc");
console.log(doc.amount);
}, 100);
},
amount: function(frm,cdt,cdn){
var doc = locals[cdt][cdn];
console.log("amount");
console.log(doc);
console.log(doc.amount);
}
});