Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
10471 Zobrazení

I can't find any information about the order of dependencies when installing modules. I'm talking about the case where you don't specify any dependencies in __manifest__, just install the modules in some (random) order.

This is a big deal when it comes to overriding class methods and properties both in python and javascript.

Example: Lets say I have 2 modules that each override a method in res.partner, something like the code below.

Which one will run first? And what happens if you update the module that don't run first?

class ResPartner(models.Model):
    _inherit = 'res.partner'
    @api.model_cr
    def init(self):
        super(ResPartner, self).init()
        # some custom code


Avatar
Zrušit
Autor

Sorry about the formating, the editor kind of suck..

Nejlepší odpověď

The short answer is, without explicitly listing dependencies, there is no guarantee of order.

The process builds a tree and ensures that anything with explicit dependencies to be not processed until all its dependencies are done.  So, two "siblings" will have a similar ranking, and it will have more to do with order it comes back from sql in ir_module_module, which cannot be relied upon.

When you "update" it will only update that module, and anything that depends upon it, meaning that an unrelated module will not "update".

This is exactly why it is poor form to inherit a method and overwrite code without good super calls.

res_partner

    def xxx(self):

        return self.field1 == desired_val


res_partner in module X

     def xxx(self):

         if self.block_xxx:

              return False

          return super().xxx()

and res_partner in module Y

      def xxx(self):

          return True


If module X code is loaded before module Y, then the result will always be True

If module Y code is loaded before module X, then the result will be False if self.block_xxx, otherwise it will be True.

And there is no guarantee that the behaviour will be consistent from one install to the next.

  

Avatar
Zrušit

Your answer is on time Richard, I was just looking into this ;)

So this line illustrates that there is no defined order in which modules are loaded:

cr.execute("SELECT name from ir_module_module WHERE state IN %s" ,(tuple(states),))

https://github.com/odoo/odoo/blob/def7d7bb0231fef38e044803b245c9b990a90216/odoo/modules/loading.py#L340

Bummer... I have a case where I'd like to override res_partner.xxx() so all other known and unknown modules benefit from it. Odoo has implemented a "priority" field for views but it looks like they have not for models.

Ahh, this gets tricky. If they all call super correctly, then they may benefit, depending on what they do (or if they completely override)

Effectively, to be sure, you need to set a dependency(ies) or take your chances.

We have, at times, needed 3, 4, or more modules to achieve what would be nice to do in 1.

module res_partner_xxx depends on crm

res_partner_xxx_sale depends on res_partner_xxx and sale and auto installed, and only has a few lines of code

res_partner_xxx_purchase

res_partner_xxx_yyyy

etc.

And, even if the read from sql could guarantee an order (like alphabetically), the tree and dependency calcs push them around as lists, recordsets, joining and unioning - it would be foolish to trust any sequence would remain intact without any explicit code to ensure it.

Related Posts Odpovědi Zobrazení Aktivita
1
čvc 22
4602
3
čvc 25
1983
3
kvě 25
3463
2
čvc 24
1343
1
říj 23
2443