Creating activity views in Odoo
Beginner
The activity view is used to show an overview of all activities on a model. The activities will be shown in a table like view where every row is a record and column is the activity type of the activity. From this view you can directly edit and confirm tasks. In this tutorial you will learn how to create an activity view. We will create a new model, menuitem and view to show you how the activity view works.
Before you can start creating activity views you will need to create a new module and configure the manifest.py correctly. Open up your manifest.py and add 'mail' as a dependency. The activity view inherits from the model 'mail.activity.mixin' which is defined in the 'mail' module so we'll need it:
'depends': ['mail'],
# -*- coding: utf-8 -*-from odoo import models, fields, apiclass StudyRoadmap(models.Model): _name = 'study.roadmap' # This inherit allows us to add activities on records (and thus to fill our activity views) # It is because of this inherits that we'll need the mail module as a dependency. _inherit = ['mail.thread', 'mail.activity.mixin'] _description = 'Study roadmap items' name = fields.Char(string='Title', required=True)
The activity view is one of the easiest views to create in XML. It just needs an activity string with a template inside it:
The field that is added inside the div 'activity-box' will be shown to the left of the activity view (as the title). You can even add multiple fields in the div and show them under eachother.
Lets add a tree and form view so we can access and edit the records made on this model too. Start with a tree view:
Lets also add a form view so we can edit the records:
Do you notice something interesting in the form view? In the form view definition I've added the 'message_ids' and 'activity_ids' fields. These fields exist in the mail module and contain all the data to be loaded in the chatter. 'message_ids' will hold and show all messages, both the internal and normal messages. The field 'activity_ids' will hold all activities related to the record. When you add these fields to the view you'll see them in the chatter just like you see on most existing views in Odoo.
Now that we have the views we'll need a security rule in the 'ir.model.access.csv' file to be able to access the view and create records in it. Let's create a simple security rule that gives all users full rights on this model:
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlinkaccess_study_roadmap,study.roadmap,model_study_roadmap,,1,1,1,1
Alright, we're almost done! Now that we have the model, the views and the security rule we just need a menuitem with an action in order to open the view(s). In this tutorial I'll create a new app on the homescreen with a configuration menuitem and an action as I do not know where you'd want to build these settings. You can just change this example.
First we'll need a main menu item, which will show up as an app on the Odoo home screen. Just create a new menuitem with a name and an icon:
The last step is to create an action. The action will make sure that if you click on the menuitem that it will open up our activity view:
That's it! If you now install this module you'll have a fully working activity view:
Activity views are a great way to get a quick overview for all activities related to a model. Thanks to the powerfull framework of Odoo it just takes a few lines of code to add activities to your own model and view while opening up a huge range of possibilities. Activities are a must have if you have to plan a lot of things or want to keep track off multiple activities.