In this recipe, we choose to extend the default implementation of the methods. In the make_boorrow() and make_available() methods, we modified the returned result before the super() call. Note that, when you call super(), it will execute the default implementation. It is also possible to perform some actions after the super() call. Of course, we can also do both at the same time.
However, it is more difficult to change the behavior of the middle of a method. To do this, we will need to refactor the code so that we can extract an extension point to a separate method and override this new method in the extension module.
What can you do before and after calling the original implementation of the method? There are lots of things, including (but not limited to) the following:
- Modifying the arguments that are passed to the original implementation (before)
- Modifying the context that is passed to the original implementation (before)
- Modifying the result that is returned by the original implementation (after)
- Calling another method (before and after)
- Creating records (before and after)
- Raising a UserError to cancel the execution in forbidden cases (before and after)
- Splitting self in smaller recordsets, and calling the original implementation on each of the subsets in a different way (before)