From bf703fd9a3951f9bd9bce1c6c62dc21ac2a4ac23 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 5 Mar 2015 09:42:38 +0100 Subject: [PATCH] [FIX] models: reorder the base classes of models following an equivalent class hierarchy Sometimes, the expected mro of the model is not the same as the one built with a binary class hierarchy. So we reorder the base classes in order to match the equivalent binary class hierarchy. This also fixes the cases where duplicates appear in base classes. --- openerp/models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openerp/models.py b/openerp/models.py index eb45259c6ba..76ad1e042bf 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -603,11 +603,17 @@ class BaseModel(object): # determine all the classes the model should inherit from bases = [cls] + hierarchy = cls for parent in parents: if parent not in pool: raise TypeError('The model "%s" specifies an unexisting parent class "%s"\n' 'You may need to add a dependency on the parent class\' module.' % (name, parent)) - bases += type(pool[parent]).__bases__ + parent_class = type(pool[parent]) + bases += parent_class.__bases__ + hierarchy = type(name, (hierarchy, parent_class), {'_register': False}) + + # order bases following the mro of class hierarchy + bases = [base for base in hierarchy.mro() if base in bases] # determine the attributes of the model's class inherits = {}