How to write custom server side method

I have written client side java script code in custom script (for Sales Invoice DocType). Now I need to make custom method (server side method in python) where should i write and how ?

Following JS code i have written inside the Custom Script

cur_frm.cscript.get_tax_and_other_charges = function(doc) {
alert(“From JS”);{
“method”: ‘erpnext.accounts.doctype.sales_invoice.sales_invoice.get_tax_and_other_charges’,
callback: function(r) {

But where should i write my PY code. which is as follows

def get_tget_tax_and_other_charges():
msgprint(“From Py”)

Server side methods should go in your own app.

Is it applicable for V4 or V5… I am working on V4


I created new app and inside app created a doctype and one method in file and calling from Doctype Page but still i am getting same error
Traceback (innermost last):
File “/home/d/frappe-bench/apps/frappe/frappe/”, line 51, in application
response = frappe.handler.handle()
File “/home/d/frappe-bench/apps/frappe/frappe/”, line 66, in handle
File “/home/d/frappe-bench/apps/frappe/frappe/”, line 77, in execute_cmd
method = get_attr(cmd)
File “/home/d/frappe-bench/apps/frappe/frappe/”, line 98, in get_attr
method = frappe.get_attr(cmd)
File “/home/d/frappe-bench/apps/frappe/frappe/”, line 520, in get_attr
return getattr(get_module(modulename), methodname)
AttributeError: ‘module’ object has no attribute ‘call_me’

I am also getting the same error AttributeError: ‘module’ object has no attribute ‘export_data’ while calling custom method from custom js.
Can anyone please help me in solving this?