Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


audittrail on write res_parent loops endless when there is a many2many relation to other res_partner(s)

Joeri Belis
on 10/10/14, 4:29 AM 773 views

multiple res_partner records for departements.

multiple res_partner records for helpdesk agents.

So there is a many2many relation between departements and helpdesk users

An Dep. can has many helpdesk agents and a helpdesk agent can support many Departements.

In a custom view, when you select a departement you see all the helpdesk users, in the user you see its dept.

many2many in model:

'organisation_relation_ids': fields.many2many('res.organisation.relation', 'res_organisation_type_relation_rel', 'organisation_type_id', 'relation_type_id', 'organisation relations''),

We get into trouble when we activate audittrail on res_partner. When you look at the code in audittrail.py, in method get_data


     (1)       field_obj = resource_pool._all_columns.get(field).column
                if field_obj._type in ('one2many','many2many'):
                    # check if an audittrail rule apply in super admin mode
                    if self.check_rules(cr, SUPERUSER_ID, field_obj._obj, method):
                        # check if the model associated to a *2m field exists, in super admin mode
                        x2m_model_ids = pool.get('ir.model').search(cr, SUPERUSER_ID, [('model', '=', field_obj._obj)])
                        x2m_model_id = x2m_model_ids and x2m_model_ids[0] or False
                        assert x2m_model_id, _("'%s' Model does not exist..." %(field_obj._obj))
                        x2m_model = pool.get('ir.model').browse(cr, SUPERUSER_ID, x2m_model_id)
                        field_resource_ids = list(set(resource[field]))
                        if model.model == x2m_model.model:
                            # we need to remove current resource_id from the many2many to prevent an infinit loop
                            if resource_id in field_resource_ids:
                   (2)    data.update(self.get_data(cr, SUPERUSER_ID, pool, field_resource_ids, x2m_model, method))


Looping (1) through the fields when it hits 'organisation_relation_ids', the code (2) will call get_data again 

So you change departement > recurse get_data for every helpdesk user in organisation_relation_ids > recurse get_data from every dept.  > ... endlessly

Is this a bug in audittrail when many2many for the same model? How can we start fixing this? i am happy to start hacking a fix but community feedback is crucial.





I think that is a bug... try to change the logic, I mean restrict the audit trail if the child object is same as Parent object... or skip that column from logging the actions...

on 10/10/14, 5:25 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

3 follower(s)


Asked: 10/10/14, 4:29 AM
Seen: 773 times
Last updated: 3/16/15, 8:10 AM