Contributors mailing list archives


Re: Overwriting a method in OCA module.

by "Kitti U." <> - 13/09/2015 10:33:19
Dear Stefan,

Thank you for brought up an interesting topic. Still I do not quite understand it.

As I try to understand from the code, the MonkeyPatch class (i.e., account.voucher.monkeypatch), its duty is to redirect the original method to our own modified method. Right?

Though it will help not having to overwrite the method directly to the underlining Class (i..e, account.voucher), but the affect is the same as a plain method overwrite. Is it not?

For example, months later, the original method has been enhanced by Odoo S.A (core code). Those changes will be ignored, as it the monkeypatch class will still help redirect it to our modified method (which now become outdated).

So, this won't help, is it? What will be the benefit of using it when compare to overwriting it?

Thank you,

On Sun, Sep 13, 2015 at 10:53 AM, David Arnold <> wrote:


Stefan Rijnhart <> schrieb am Sa., 12. Sep. 2015 um 17:37:

Sure Arnold, see here:

On September 12, 2015 7:52:53 PM CEST, David Arnold <> wrote:

Hi Stefan, do you know of a code example where you can point me to? I'm interested in that kind of advanced tricks.. Best, David

Stefan Rijnhart <> schrieb am Sa., 12. Sep. 2015 um 09:52:
On 12-09-15 00:37, Nhomar Hernandez wrote:
> 1.- Overwrite the method in a module which split (refactoring it) the
> mega method in several mini methods and/or hooks. (this is module1 and
> propose to OCA explaining why for stable-version).

Good idea to overwrite the method in a module that introduces the hooks
but does not change anything functional!

To preserve any existing inheritance, you could in such a module replace
the original method with the refactored version by applying it as a
monkeypatch in _register_hook. While it will still affect all databases
on the instance once the module is installed, it will not be preloaded
if the module is only in the module path and not installed on any
database. That trick is courtesy of Holger Brunn, BTW.


Post to:

Post to:

Sent from my Android device with K-9 Mail. Please excuse my brevity.


Post to:

Mobile: +66-(0)8-1841-7480
Your ERP Partner =>