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”);
cur_frm.call({
“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

@frappe.whitelist()
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

Both.

I created new app and inside app created a doctype and one method in doctype.py file and calling from Doctype Page but still i am getting same error
Traceback (innermost last):
File “/home/d/frappe-bench/apps/frappe/frappe/app.py”, line 51, in application
response = frappe.handler.handle()
File “/home/d/frappe-bench/apps/frappe/frappe/handler.py”, line 66, in handle
execute_cmd(cmd)
File “/home/d/frappe-bench/apps/frappe/frappe/handler.py”, line 77, in execute_cmd
method = get_attr(cmd)
File “/home/d/frappe-bench/apps/frappe/frappe/handler.py”, line 98, in get_attr
method = frappe.get_attr(cmd)
File “/home/d/frappe-bench/apps/frappe/frappe/init.py”, 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?