I am trying to make a similar table as Tax and Other Charges in Sales Invoice
I have written 2 functions , one in sales_invoice.js and corresponding function
in sales_invoice.py file
I have created a button which when clicked calls the .js code but I am getting the following error:
Traceback (innermost last):
File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 51, in application
response = frappe.handler.handle()
File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 66, in handle
execute_cmd(cmd)
File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 77, in execute_cmd
method = get_attr(cmd)
File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 98, in get_attr
method = frappe.get_attr(cmd)
File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 520, in get_attr
return getattr(get_module(modulename), methodname)
AttributeError: 'module' object has no attribute 'get_tax_and_other_charges'
Below is the .js code and .py code.
//My function to get all other charges
frappe.ui.form.on("Sales Invoice", "get_other_charges", function(frm) {
frm.set_value("sales_taxes_and_charges", []);
alert("The value entered was \n" + frm.doc.sales_taxes_and_charges_master_title);
return frappe.call({
method: 'erpnext.accounts.doctype.sales_invoice.sales_invoice.get_tax_and_other_charges',
args: {
args: {
"sales_taxes_and_charges_master_title": frm.doc.sales_taxes_and_charges_master_title,
}
},
callback: function(r, rt) {
if(r.message) {
frm.fields_dict.get_other_charges.$input.addClass("btn-primary");
alert("The value entered was 1 \n" + frm.doc.sales_taxes_and_charges_master_title);
frappe.model.clear_table(frm.doc, "sales_taxes_and_charges");
alert("The value entered was 2 \n" + frm.doc.sales_taxes_and_charges_master_title);
$.each(r.message, function(i, d) {
var tax_detail = frappe.model.add_child(frm.doc, "Sales Taxes and Charges", "sales_taxes_and_charges");
tax_detail.charge_type = d.charge_type;
tax_detail.description = d.description;
tax_detail.rate = d.rate;
tax_detail.tax_amount = d.tax_amount;
});
}
refresh_field("sales_taxes_and_charges");
}
})
})
@frappe.whitelist()
def get_tax_and_other_chargs(sales_taxes_and_charges_master_title):
flat_other_charges=[]
other_charges_list=frappe.db.sql("""
select
SC.charge_type,SC.description,SC.rate,SC.tax_amount
from
`tabSales Taxes and Charges` SC join `tabSales Taxes and Charges Master` SCM on SC.parent=SCM.name where SCM.name=%s""")
for d in other_charges_list:
flat_other_charges({
'charge_ype':d.charge_type,
'description':d.description,
'rate':d.rate,
'tax_amount':d.tax_amount
})
return flat_other_charges