In this article, you will learn how to add or enable field tracking in custom form views in Odoo15. To enable tracking of fields in Odoo we have to inherit some models and dependencies.
Why do we need to enable field tracking in Odoo
Fields tracking or track_visibility is used to record every action or update of the particular field. For example, when a field value changed, its log will be recorded with from and to values.
Read More: WhatsApp Integration with Odoo (Python)
How to Enable Field Tracking or track_visibility in Odoo
To enable tracking of fields you have to inherit the following models in your custom class or model.
Read More: Inheritance in Models and Views in Odoo
class gym_body_parts_config(models.Model):
_name = 'gym.body.parts.config'
_inherit = ['mail.thread', 'mail.activity.mixin']
After inheriting the above models in your class, now just add this (tracking=True) attribute to the fields in which you want to track the record.
name = fields.Char(string="Name", required=True, tracking=True)
Now that we have implemented the tracking code in our model, now it's time to add some fields to views. Just add the below code in your XML after sheet tag.
Read More: How to Create Views (Form, Tree and Search) in Odoo
<sheet>
<!--your form view fields goes here-->
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" groups="base.group_user"/>
<field name="activity_ids"/>
<field name="message_ids"/>
</div>
TypeError: Model 'your.model.name' inherits from non-existing model 'mail.thread'
If you are facing the above error then don't forget to add the "mail" module in the dependency (in the __manifest__.py file).
Read More: Why we do use __manifest__.py file
# any module necessary for this one to work correctly
'depends': ['base','mail'],
2 Comments
And how to add tracking for Many2many fields?
ReplyDeleteI am just working on it, coming soon.......
Delete