Wednesday 12 October 2022

Get Many2Many data in query

 Collect data of many2many in SQL query.

Sometimes in query needed to get all customer/partner data including tags. Here example to get all customer tags data in query.

Example:

select 

res_partner.name as "Partner Name",

res_partner.phone as "Phone",

(select STRING_AGG(ctg.name,',') from res_partner_category ctg  left join res_partner_res_partner_category_rel ct ON ct.partner_id=res_partner.id where ctg.id=ct.category_id) as "Tags"

from res_partner;


Tuesday 15 March 2022

Odoo 15: Send email to all followers with email template

Send Email to all followers

Here simple solution to send email to all followers or you custom the followers (exclude).

In your code file define the function to send email.

    @api.multi
    def action_lead_mail_send(self):
        group_id_list = []
        ir_model_data = self.env['ir.model.data']
        
        group_id_list.append(ir_model_data.get_object_reference('sales_team', 'group_sale_manager')[1])
        users_email = ",".join([user.email for user in self.env['res.groups'].browse(group_id_list).users if user.email])
        
        # read email template
        template_id = ir_model_data.get_object_reference('crm_notification', 'email_template_meeting')[1]
        template = self.env['mail.template'].browse(template_id)
        template.write({
            'email_to': users_email or '',
        })
        template.send_mail(self.id)
        return True

So, here you can customise the email receivers. You can also add the followers of the record.You can also exclude the followers and send email.

..Enjoy..