Adding a custom whitelist method to sales invoice doctype

I am trying to figure out the best approach to add a custom whitelist method to the sales invoice doctype which will get called on before ‘Before Submit’.

Should I add my custom whitelist method to /erpnext/accounts/doctype/sales_invoice/ ?


Should I be creating a custom app that holds this method?

My understanding is that you should avoid modifying the core .py files. How should I approach this?

neither . create a server script using the app itself .

The issue is that I need to do a POST to an external website. I do not think that is possible in the server script on the app. Is it?

the same method you are gonna use after sumbit and as api at the same time ?

This is basically what I am trying to accomplish:

The user is going to click submit. My custom method will get invoked which will post to an external URL. That URL will return a response. My custom method will analyze the response and either raise an error or allow the submit to continue.

if you are consuming the other url you can put it on server script , and it will works .
if you are trying to make a api method , create a new python file inside frappe ,
to call it use /api/method/frappe.file_name.function_name
also you can put the function inside the file on the after submit section

So in the server script, how do I actually make a call to an external URL? I don’t think will work for that. Will it?

it’s just python code . but erpnext may block it when you import the module requests .
If so ,try the second method . create the python file inside frappe and create your function .
Then ,inside the file at the doc_events dict put it like this :

doc_events = {
“Doctype_name”: {
“before_validate”: “frappe.file.method” },

(you can change before_validate with any other event.

Yes, erpnext does block the import of requests. Therefore, doing it the second way means modifying core code of erpnext (for example, Is this ok to do for my case? Or is there a way to accomplish this without having to modify core erpnext files?

it’s totally fine . however , the code will disappear when updating the server

Thanks for all your help!!

Last question, is there any way to accomplish what I’m doing without having to modify erpnext files, or is that the best way?

the only way is to find a ways to make server script accept your code .
As I said it’s okay , I got a lot of live server for clients and I always change the code .

Ok sounds good…:+1: