Applying custom code across many doctypes

Hello everyone,

I have multiple custom doctypes and codes for each of those doctypes. Is there a way to apply a few lines of code across multiple doctypes? For example, let’s say I have a function to calculate net total and I want this code to be applied to all custom doctypes. Is there a way I can do this?

I am just thinking it would make things easier so that if you have a bug in your code, you would only need to change one line of code rather than go through all the custom codes and fix the bug.

Any help is appreciated.