Custom controller / event for standard documents

I’d like to build the following and want to make sure I follow the path of least resistance while doing so…the purpose of the question is to make sure that I don’t spend a lot of time on something and then realize it’s been the wrong way to do it!

I am creating an extended customer portal. I have a db outside of ERPNext that essentially functions as a slave for tables shared with ERPNext. The reason it’s built outside of ERPNext is some other data/analytics for which I won’t go into - but that’s the reason for a foreign db.

When we change a document, like sales order, item, etc, I’d like to either send it to the correct customer’s db right away, or store it for up to ~5min or so and have a scheduler event in the other application fetch it.

Is the best place to do this in hooks for a custom app in the document events section? Or should I write add’l code in the controllers of doctypes I wish to send? I don’t want to change anything in the controllers because I’ll have to deal with merges on 10+ doctypes for every update, but if that’s the best way to do it, so be it…

If I can do it through hooks, am I able to access documents outside of that app’s documents? (e.g. could I access Sales Order in a doc event hook from a custom app?) I understand the doc gets passed in the doc_events so this will be what I start with. Is this the best place to start?

EDIT: seems to be working with hooks, storing a tuple with the event type, doc/doctype/customer.

@alec_ruizramon1, hooks is the right place to start!

If do you have a common action for various doctypes, do you can use a single hook to all!

The most important information here is:

  • Your hook need be specific in the event! (A bad event choice, can generate mistakes between the information in one, and other db)
  • You can get the doc, and inspect all information that do you need inside on this, like, the doctype, and docname name

With the hooks, updates dont will be a headache for you!