Odoo Help

Welcome!

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.

0

How do I configure the subscription types for a follower from Python?

By
Yenthe
on 3/23/16, 9:57 AM 745 views

Hi guys,

I'm creating a webpage from which a project issue will be automatically created. After the project issue is created I will add the customer as a follower with this code:

add_user_as_follower = request.env['mail.followers'].sudo().create({ 'partner_id': partner_id, 'res_model': 'project.issue', 'res_id': new_ticket_id.id })

This works fine and will add the customer as a follower on the issue (by writing in the model mail.followers). However, when I now look at the details of this follower and when he should get notified I can see none of the options are configured:

How can I set the field 'Discussions' checked on by default when I add the customer as a follower? The person that is added as a follower, with the above code, should also recieve e-mails when something is posted on the issue by anybody.
So, on which table should I write what to automatically check on Discussions for this follower?

Yenthe

0
Shawn Varghese
On 3/23/16, 3:34 PM

Hi Yenthe,

Are you referring to the message subtypes? You can normally configure that in the following way:

Example taken from sale.py:

@api.multi

def _track_subtype(self, init_values):

self.ensure_one()

if 'state' in init_values and self.state == 'sale':

return 'sale.mt_order_confirmed'

elif 'state' in init_values and self.state == 'sent':

return 'sale.mt_order_sent'

return super(SaleOrder, self)._track_subtype(init_values)


We use the _track_subtype method to track the state variable. Therefore, whenever the state is changed and moves to 'sale' state, the message subtype sale.mt_order_confirmed is used for the automatic e-mail to followers. This subtype will be defined in XML as :

<record id="mt_order_confirmed" model="mail.message.subtype">

<field name="name">Sales Order Confirmed</field>

<field name="res_model">sale.order</field>

<field name="default" eval="False"/>

<field name="description">Quotation confirmed</field>

</record>

Here, if you change the default field value to true, followers of the document will automatically get subscribed to this message type. I imagine something similar will have been done for the Issues module in the screenshot you shared.

Also, the automatic e-mail that gets sent will include details of the changes. You can choose which details to include by using the track_visibility parameter:

_columns={

     state = fields.Selection([

('draft', 'Quotation'),

('sent', 'Quotation Sent'),

('sale', 'Sale Order'),

('done', 'Done'),

('cancel', 'Cancelled'),

], string='Status', readonly=True, copy=False, index=True, track_visibility='onchange', default='draft')

}

Hope this is what you were referring to.

Also, isn't the Discussions default to True? I just tried adding a customer as a follower, but I found that they were automatically subscribed to Discussions... Also, if you navigate to Settings > Technical > Subtypes, you can configure which ones should be subscribed by default.

Shawn Varghese
on 3/23/16, 3:42 PM

@Shawn thank you for the answer but I'm not talking about the states at the top of a record (the progressbar), I'm talking about the followers on a record and how to automatically give them specific settings. The Discussions its followers are not by default configured by my case because I add them through Python, which I'm doing besides the default behaviour.

Yenthe
on 3/29/16, 3:04 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

1 follower(s)

Stats

Asked: 3/23/16, 9:57 AM
Seen: 745 times
Last updated: 3/31/16, 11:05 AM