Skip to Content
Menu
This question has been flagged
1 Reply
2569 Views

Hi, 

I have to assign schedule activity to multiple users. Do anyone have a better solution by adding a new field inside the schedule activity screen and so the rest work as like the default functioning of odoo. 

Thank you.

Avatar
Discard
Best Answer

Hi, 

We can add a many2many field inside mail.activity 

class MailActivity(models.Model):
_inherit = 'mail.activity'
 
multiple_users = fields.Many2many('res.users', store=True)
 
#Add this function inside 
@api.model
def create(self, vals):
assigned_user_id = vals['user_id']
assigned_user_name = self.env['res.users'].browse(vals['user_id']).name
vals['display_names'] = assigned_user_name
res = super(MailActivity, self).create(vals)
if 'multiple_users' in vals and vals['multiple_users']:
related_user_ids = self.env['res.users'].search([('id', 'in', vals['multiple_users'][0][2])], order='id')
for each in related_user_ids:
if each.name != assigned_user_name:
vals['user_id'] = each.id
vals['display_names'] = each.name
res = super(MailActivity, self).create(vals)
return res

And add that to the view.

<record id="mail_activity_view_form_popup_inherit" model="ir.ui.view">


    <field name="name">mail.activity.form.inherit.calendar</field>


        <field name="model">mail.activity</field>


        <field name="inherit_id" ref="mail.mail_activity_view_form_popup"/>


        <field name="arch" type="xml">


    <xpath expr="//field[@name='user_id']" position="after">


                <field name="multiple_users" widget="many2many_tags" string="Additional Assignees"/>


        </xpath>


        </field>


</record>


So here we can add separate activity for each users we select in the multiple_users field.

Regards

Avatar
Discard
Related Posts Replies Views Activity
0
Jan 21
1474
2
Mar 24
5888
0
Jul 21
1538
3
Oct 20
4398
3
Aug 20
3842