Community mailing list archives

Re: Dynamic / conditional module dependencies

Open For Small Business Ltd, Graeme Gellatly
- 06/29/2016 19:24:53
Perhaps slightly better explained as

def your_special_method_inherited_from_sales(self):
    ctx = dict(self._context)
    flag = ctx.get({'your_explicit_flag': True})
    if flag:
        do_something before calling super if needed
    res = super(YourClass, self).your_special_method_inherited_from_sales()
    if flag:
        do_something after super like appending to res if needed
    return res

On Thu, Jun 30, 2016 at 10:21 AM, Nhomar Hernandez <> wrote:

On Wed, Jun 29, 2016 at 2:42 PM, Mohamed M. Hagag <> wrote:


In many cases we want to build a module that affects for ex. sale, product and POS.

but we don't want the functions that affect POS to be executed in case that POS is not installed.

the way we can build a general module that doesn't depend on POS but affects it if only installed.

How can we achieve this behaviour in odoo 8 or 9 without building module for sale and another for POS ?


You can use an installed validator it is technically feasible, but, bad things happen, What I recommend is work with some kind of hooks or contextual validations.

def your_especial_method_inherited_from_sales(self):
    ctx = dict(self._context)
    flag = ctx.get({'your_explicit_flag': True})
    if flag:
        do_something and append to res
    return super(YourClass, self).your_especial_method_inherited_from_sales()

In that way your methods will be more object oriented.

In the 99% of cases when you need to do what you describe (do an If Module Installed) you are making a design crime functionally speaking.


Nhomar Hernandez
CEO Vauxoo.
Twitter: @nhomar
Odoo Gold Partner
Skype: nhomar00 (Envia mail previo no lo superviso siempre).
Móvil Venezuela:
+58 4144110269
Móvil México:
+52 1 4773933942

Post to: