Hi
Goal: to auto populate the “taxes and charges” table (Sales Order), based on the “tax category” of
the customer.
My script seem to fetch the “Sales Taxes and Charges” template name correctly, but the child table
does not update.
Please help
frappe.ui.form.on('Sales Order', {
customer: function(frm) {
if (frm.doc.customer) {
frappe.call({
method: 'frappe.client.get_value',
args: {
doctype: 'Customer',
filters: {
customer_name: frm.doc.customer
},
fieldname: ['tax_category']
},
callback: function(response) {
if (response.message) {
var tax_category = response.message.tax_category;
frappe.show_alert(tax_category, 5);
getTaxTemplateByCategory(tax_category);
}
}
});
}
}
});
function getTaxTemplateByCategory(tax_category) {
frappe.call({
method: 'frappe.client.get_list',
args: {
doctype: 'Sales Taxes and Charges Template',
filters: { tax_category: tax_category },
fields: ['name'],
limit: 1
},
callback: function(response) {
if (response.message && response.message.length > 0) {
frappe.show_alert(response.message[0].name, 5);
cur_frm.doc.taxes_and_charges = response.message[0].name;
frm.refresh_field('taxes_and_charges');
frm.refresh_children('taxes');
frm.trigger('taxes_and_charges');
}
}
});
}