Reputation: 302
i'm writing a ticketing module and i need the assigned employee to a specific ticket to be automatically follow the ticket the thing as is it followers are added form res.partner model and i need to add them from hr.employee and res.partner
here is my work around
python:
class ticket(models.Model):
_name = 'itmangement.ticket'
_description = 'IT Ticket Management Process'
_inherit = ['mail.thread', 'ir.needaction_mixin']
#some other fields
assigned_to_id = fields.Many2many('hr.employee', string="Assigned To")
employee_message_follower_ids=fields.Many2many('hr.employee')
@api.one
def action_assign(self):
self.employee_message_follower_ids =[(6,0,self.assigned_to_id.ids)]
and the view:
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
<div class="oe_chatter">
<field name="employee_message_follower_ids" widget="mail_followers"/>
</div>
Upvotes: 0
Views: 4756
Reputation: 537
Since message_follower_ids contain the mail.follower objects' ids, and not the partner_ids themselves, you need a method to add the follower(s). Something like this:
def add_follower_id(self, res_id, partner_id, model):
followers_obj = self.env['mail.followers']
follower_id = False
reg = {
'res_id': res_id,
'res_model': model,
'partner_id': partner_id, }
try:
follower_id = followers_obj.create(reg)
except:
_logger.info(u'AddFollower: follower already exists')
return follower_id
where res_id is the id of your object model is the model of your object ('crm.lead' for example). and partner_id is the id of the partner who is going to be the follower (not de object, but the id instead). If you pass the object you will get a "can't adapt type" exception.
Perhaps there is a better solution, (a previous existing method to do this) but I did not find it, and this worked for me.
Upvotes: 0
Reputation: 740
For each Employee, Related User will be there. For each Related User, Partner shall be Created and Once you assign a Ticket to an Employee, immediately he will be added as Follower. if its not adding then, you can add like this,
self.write(cr, uid, ids, {'message_follower_ids':[(4, partner_id)]})
Upvotes: 1