Community mailing list archives

community@mail.odoo.com

Re: Dynamic / conditional module dependencies

by
Vauxoo S.A. de C.V., Nhomar Hernandez
- 06/29/2016 18:16:30

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

Dears,


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 ?


Regards,


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.

regards.

--
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