Odoo Help

4

What is the _track proprerty of mail.thread model used for ?

By
Nicolas Bessi
on 2/15/13, 6:48 AM 11,072 views

In the mail.thread model _trackpropety is defined. It as the following doc `

# Automatic logging system if mail installed
# _track = {
#   'field': {
#       'module.subtype_xml': lambda self, cr, uid, obj, context=None: obj[state] == done,
#       'module.subtype_xml2': lambda self, cr, uid, obj, context=None: obj[state] != done,
#   },
#   'field2': {
#       ...
#   },
# }

`

But his puprose and usage is not really clear.

This question has been included in the official documentation.
10
Andreas Brueckl
On 2/15/13, 7:53 AM

_track on the object is used to track events related to a document (an invoice has been paid, an opportunity is won, a task is blocked, ...). Users can follow events, represented by a mail.message.subtype, on any object.

It's different from the track_visibility attribute that you can define on a field which is used to track changes on this field. (e.g. Stage : Proposition -> Negociation)

Both _track and track_visibility produces messages on the document. Your object need to inherit from mail.thread.

If an object is inherited from 'mail.thread' then _track is used to send notifications. Therefore 'module.subtype_xml' is the related "Message Subtype". These subtypes have to be declared in XML. Here is an example:

<record id="subtype_xml" model="mail.message.subtype">
    <field name="name">Relevant Fields</field>
    <field name="res_model">project.issue</field>
    <field name="default" eval="True"/>
    <field name="description">The issue has been closed.</field>
</record>

Then whenever the field "field" is updated, all subtypes ("subtype_xml", "subtype_xml2") of this field are processed.

This means that the related method (in this example: lambda ...) is called and if the result is True, then for all users which follow this object and have checked the subtype a notification is created.

In the user preferences every user can choose whether he/she wants to be updated by email in case of new notifications.

You can also set a mail.message.subtype that depends on an other to act through a relation field. Here is an exemple from crm for Sales Teams crm.case.section using the section_id m2o in crm.lead:

    <record id="mt_lead_won" model="mail.message.subtype">
        <field name="name">Opportunity Won</field>
        <field name="res_model">crm.lead</field>
        <field name="default" eval="False"/>
        <field name="description">Opportunity won</field>
    </record>

    <record id="mt_salesteam_lead_won" model="mail.message.subtype">
        <field name="name">Opportunity Won</field>
        <field name="res_model">crm.case.section</field>
        <field name="parent_id" eval="ref('mt_lead_won')"/>
        <field name="relation_field">section_id</field>
    </record>

This allows a user to follow all "Opportunities Won" that are in a specific sales team. The user follow the event "Opportunity Won" on a sales team and he will become automatically follower of all leads/oppotunities of this sales team and _track event.

I merged several answers into this one (thanks Yannick Vaucher)

Fabien Pinckaers (fp)
on 3/22/13, 7:00 AM

Hi Fabien can you tell me how to track the amount change

Soohoo
on 1/10/14, 3:41 AM
This question has been included in the official documentation.
8
Sudhir Arya (SA)
On 2/15/13, 8:21 AM

As per my knowledge it keeps track on state. When state is changed you can see message at bottom of your page.


Let's take Sale Order as example.

When you confirm Sale Quotation, you can see message Quotation confirmed in message list.

You can see _track in sale.py

_track = {
    'state': {
        'sale.mt_order_confirmed': lambda self, cr, uid, obj, ctx=None: obj['state'] in ['manual', 'progress'],
        'sale.mt_order_sent': lambda self, cr, uid, obj, ctx=None: obj['state'] in ['sent']
    },

Here, mt_order_confirmed & mt_order_sent is an ID of record of object mail.message.subtype in sale_data.xml

Correct me if I am wrong.

Thank you.

This question has been included in the official documentation.
0

To complete the answer from Andreas

You can also set a mail.message.subtype that depends on an other to act through a relation field. Here is an exemple from crm for Sales Teams crm.case.section using the section_id m2o in crm.lead:

    <record id="mt_lead_won" model="mail.message.subtype">
        <field name="name">Opportunity Won</field>
        <field name="res_model">crm.lead</field>
        <field name="default" eval="False"/>
        <field name="description">Opportunity won</field>
    </record>

    <record id="mt_salesteam_lead_won" model="mail.message.subtype">
        <field name="name">Opportunity Won</field>
        <field name="res_model">crm.case.section</field>
        <field name="parent_id" eval="ref('mt_lead_won')"/>
        <field name="relation_field">section_id</field>
    </record>

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 2/15/13, 6:48 AM
Seen: 11072 times
Last updated: 7/30/15, 5:55 PM