Community mailing list archives

community@mail.odoo.com

Re: Dynamic / conditional module dependencies

by
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 <nhomar@vauxoo.com> wrote:

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

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe