mail_thread._message_get_auto_subscribe_fields needs a tracking_visibility to track a field

Bug #1188538 reported by Guewen Baconnier @ Camptocamp
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Won't Fix
Wishlist
Unassigned

Bug Description

Concerns the method openerp.addons.mail.mail_thread.mail_thread._message_get_auto_subscribe_fields:

    def _message_get_auto_subscribe_fields(self, cr, uid, updated_fields, auto_follow_fields=['user_id'], context=None):
        """ Returns the list of relational fields linking to res.users that should
            trigger an auto subscribe. The default list checks for the fields
            - called 'user_id'
            - linking to res.users
            - with track_visibility set
            In OpenERP V7, this is sufficent for all major addon such as opportunity,
            project, issue, recruitment, sale.
            Override this method if a custom behavior is needed about fields
            that automatically subscribe users.
        """
        user_field_lst = []
        for name, column_info in self._all_columns.items():
            if name in auto_follow_fields and name in updated_fields and getattr(column_info.column, 'track_visibility', False) and column_info.column._obj == 'res.users':
                user_field_lst.append(name)
        return user_field_lst

(BTW, unrelated to my issue but the auto_follow_fields arg should probably not be a mutable argument.)

Use case:

I create a model, I want to automatically subscribe a 'specialist_user_id' when defined so he will receive messages.
Note: the model does not automatically track and displays the changes.

    class my_model(orm.Model):
        _name = 'my.model'
        _inherit = ['mail.thread']

        _columns = {
            'name': fields.char('Name'),
            'user_id': fields.many2one('res.users', string='User'),
            'specialist_user_id': fields.many2one('res.users', string='Specialist'),
        }

        def _message_get_auto_subscribe_fields(self, cr, uid, updated_fields, auto_follow_fields=['user_id'], context=None):
            follow_fields = ['specialist_user_id']
            follow_fields += auto_follow_fields
            return super(my_model, self)._message_get_auto_subscribe_fields(cr, uid, updated_fields, auto_follow_fields=follow_fields, context=context)

Result:

user_id and specialist_user_id are not subscribed when changed

Expected:

user_id and specialist_user_id are subscribed when changed

Note:

If I put the _columns:

        _columns = {
            'name': fields.char('Name'),
            'user_id': fields.many2one('res.users', string='User', track_visibility='onchange'),
            'specialist_user_id': fields.many2one('res.users', string='Specialist', track_visibility='onchange'),
        }

It works, but I don't understand what is the relation between the track_visibility and the auto subscription.
I think that's 2 different things and that I shouldn't need to define a track_visibility to subscribe the users.

Workaround:

Define the columns with a dummy track_visibility as follows:

        _columns = {
            'name': fields.char('Name'),
            'user_id': fields.many2one('res.users', string='User', track_visibility='never'),
            'specialist_user_id': fields.many2one('res.users', string='Specialist', track_visibility='never'),
        }

Related branches

description: updated
description: updated
Revision history for this message
Martin Trigaux (OpenERP) (mat-openerp) wrote :

Hello,

Sorry but it's not something that we want to have currently. We don't want to autoscubscribe every user fields.
We consider autosubscribe fields are quite important (eg: responsible of a task) so it's good to track them (why was I added as follower ? can see in the chatter)

Regards

Changed in openobject-addons:
importance: Undecided → Wishlist
status: New → Won't Fix
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Thanks for your answer.

Can you point me to the correct solution to automatically subscribe a user when it is changed (i.e. in a 'specialist_user_id' field)?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.