* Betr.: " Re: [tryton-dev] About glue modules" (Sat, 24 Dec 2011 07:45:18
  +0530):

> On Dec 24, 2011, at 3:09 AM, Cédric Krier wrote:
> 
> > I think I have found a solution.
> > 
> > First, we can have module extending Models define on other modules but
> > without depending on it. Like puting the code of
> > sale_shipment_cost_weight in carrier_weight but without making
> > carrier_weight depending on sale.
> 
> Which means no separate glue module :)
> 
> > Second, we just need to ensure the carrier_weight will be loaded after
> > sale_shipment_cost if it is installed. For this, let's introduce an
> > other keyword "extra_depends" that will behave like "depends" but it
> > will not be read when installing the module.
> 
> This will not prevent tryton module loader from loading classes which
> were meant to be inherited (but will be loaded as new). For example if
> you inherit `sale.sale` and change the behaviour of a method, and if
> sale module is not in `depends` tryton will create `sale.sale` as a new
> model ?
> 
> > 
> > I think this design will allow to put glue code inside the module
> > without crappy hack and it will be explicit via the extra_depends.
> 
> I dont know if this is really a dependency management problem ? (if I
> understood the problem right. Please correct me if I am wrong)
> 
> I dont think these glue modules introduce new fields in DB and they only
> overwrite existing methods or introduce new methods to change the
> functionality.

I think, glue modules could want to add new fields.

> Why not provide an efficient helper function which checks if a module is
> installed ?
> 
> ```
> from trytond.tools import is_module_installed
> 
> class Something(ModelSQL):
>     def create(self, values):
>         if is_module_installed(['sale', 'something_else']):
>             # do something
>         #anyway do this which is common
> 
> ```
> 
> Though this might make methods bulky, I think it makes it more findable (and 
> hence readable) rather than having a lot of glue modules distributing
> functionality across the place.

I like the direction of this idea most until now, because something like this
could also provide the flexibility needed to handle Or cases:

if is_module_installed(['sale_kit']):
    # do something
elif is_module_installed(['sale_production']):
    # do soemthing else


Perhaps sort of conditional loader in __init__.py or something similar could do
the trick?

from company import *
if_module_installed('company_extension'):
    from company_extension import *




-- 

    Mathias Behrle
    MBSolutions
    Gilgenmatten 10 A
    D-79114 Freiburg

    Tel: +49(761)471023
    Fax: +49(761)4770816
    http://m9s.biz
    UStIdNr: DE 142009020
    PGP/GnuPG key availabable from any keyserver, ID: 0x8405BBF6

Attachment: signature.asc
Description: PGP signature

Reply via email to