Are you looking to revolutionize your project management and task scheduling within Odoo 18? Do you need a dynamic, visual tool to track progress, allocate resources, and manage timelines effectively? Then you’ve landed in the right place! This comprehensive tutorial will guide you step-by-step on how to Create Odoo Gantt View, transforming your data into insightful, interactive Gantt charts.
Gantt views are an indispensable feature, offering a horizontal bar chart visualization that allows you to forecast, examine, and manage the overall progress of records over time. While incredibly powerful, this view is exclusively available in the Odoo Enterprise edition. If you’re ready to unlock this capability and enhance your Odoo experience, let’s dive in!
For a deeper dive and visual walkthrough, you can follow along with the original source video here: How to Create Gantt View in Odoo Complete Weblearns Odoo Tutorial.
Prerequisites for Building Your Odoo Gantt View
Before we begin to create Odoo Gantt View, ensure you have the following in place:
- Odoo 18 Enterprise Edition: As mentioned, Gantt views are an Enterprise-exclusive feature.
- A Custom Odoo Module: You’ll need an existing or a new custom module where you want to implement and customize your Gantt view.
- Basic Odoo Development Knowledge: Familiarity with Odoo models, views (XML), and Python is beneficial.
- A Model with Date Fields: Your target model must have at least two
DateorDatetimefields to represent the start and end of a task or record.
What is a Gantt View in Odoo?
At its core, an Odoo Gantt view is a specialized data visualization that presents tasks or records as horizontal bars plotted against a timeline. Each bar’s length corresponds to the duration of the task, and its position on the timeline indicates its scheduled start and end dates. This makes it an incredibly intuitive tool for project managers, team leads, and even individual users to:
- Visualize Project Timelines: Get an instant overview of all ongoing and upcoming activities.
- Track Progress: Easily see how tasks are progressing relative to their planned schedules.
- Identify Bottlenecks: Spot potential delays or overloaded resources at a glance.
- Manage Dependencies: Understand which tasks rely on others for completion, crucial for complex projects.
- Allocate Resources: Plan and adjust resource assignments across different tasks and projects.
In Odoo, the Gantt view integrates seamlessly with your existing data models, allowing you to represent anything from project tasks and manufacturing orders to employee schedules and student course durations.
Why You Should Powerfully Create Odoo Gantt View for Your Business
Implementing a Gantt view in Odoo isn’t just about adding another visual element; it’s about fundamentally enhancing your operational efficiency and decision-making capabilities. Here’s why you should powerfully create Odoo Gantt View for your Odoo instance:
- Crystal-Clear Project Overview: No more sifting through lists. A Gantt chart provides a single, unified visual representation of your entire project, making it easy to grasp the scope, timeline, and status of every task. This clarity is invaluable for stakeholders and team members alike.
- Enhanced Scheduling and Planning: The drag-and-drop functionality (if enabled) allows for dynamic rescheduling. You can quickly adjust task durations, shift timelines, and reallocate resources directly within the view, ensuring your plans remain agile and responsive to changes. This is a powerful way to manage complex schedules.
- Improved Resource Management: By grouping tasks by assigned personnel or specific resources, you can quickly identify who is working on what and if any team member is over-allocated. This helps in balancing workloads and preventing burnout, leading to a more productive workforce.
- Proactive Problem Identification: Gantt charts highlight potential conflicts or delays early on. If a critical task is falling behind, its extended bar or color-coded status immediately draws attention, allowing for proactive intervention before it impacts the entire project.
- Effective Stakeholder Communication: The visual nature of Gantt charts makes it easier to communicate project plans and progress to clients, management, and team members who may not be familiar with the intricate details of Odoo. It fosters transparency and alignment.
- Dependency Management: For projects with sequential tasks, identifying and managing dependencies is crucial. The ability to visually link tasks within the Gantt view ensures that prerequisite tasks are completed before dependent ones begin, streamlining workflows and preventing errors.
By leveraging the Odoo Gantt view, you’re not just organizing data; you’re gaining a strategic advantage in planning and execution. Now, let’s proceed with the technical steps to create Odoo Gantt View within your custom module.
Step-by-Step Tutorial: How to Create Odoo Gantt View
This section will walk you through each essential step to successfully create Odoo Gantt View in your Odoo 18 Enterprise environment.
1. Defining Essential Date Fields
Every Gantt view needs a starting and an ending point. These are typically represented by date or datetime fields in your Odoo model. If your model doesn’t already have them, you’ll need to add them.
Action: Open your Python model file (e.g., your_module/models/your_model.py) and define the Date or Datetime fields.
Example Python Code:
from odoo import fields, models
class YourModel(models.Model):
_name = 'your.model'
_description = 'Description of Your Model'
name = fields.Char(string="Record Name", required=True)
start_date = fields.Date(string="Start Date", required=True)
end_date = fields.Date(string="End Date", required=True)
status_id = fields.Many2one('your.status.model', string="Status")
user_id = fields.Many2one('res.users', string="Assigned To", default=lambda self: self.env.user)
amount = fields.Float(string="Amount")
# Fields for dependencies (assuming 'your.school.model' for context reference)
child_school_ids = fields.Many2many('your.school.model', 'gantt_school_child_rel', 'parent_id', 'child_id', string="Child Schools")
parent_school_id = fields.Many2many('your.school.model', 'gantt_school_parent_rel', 'child_id', 'parent_id', string="Parent Schools")
# Ensure to add this model to your __init__.py and __manifest__.py
Practical Tip: Decide whether fields.Date or fields.Datetime is more appropriate for your use case. Date is sufficient for day-level planning, while Datetime offers hour-level precision.
2. Crafting the Core Gantt View XML Structure
The heart of your Odoo Gantt view lies in its XML definition. You’ll create a new XML file within your module’s views directory (e.g., your_module/views/gantt_views.xml).
Action: Create the XML file and add the basic Gantt view structure.
Example XML Code:
<odoo>
<data>
<record id="view_your_model_gantt" model="ir.ui.view">
<field name="name">Your Model Gantt View</field>
<field name="model">your.model</field>
<field name="arch" type="xml">
<gantt string="My Awesome Project Timeline"
date_start="start_date"
date_stop="end_date"
default_group_by="status_id"
scales="day,week,month,year">
</gantt>
</field>
</record>
</data>
</odoo>
Key Attributes Explained:
id: A unique identifier for your view record (e.g.,view_your_model_gantt).name: A descriptive name for the view, visible in Odoo’s technical settings.model: The technical name of the model this Gantt view applies to (e.g.,your.model).arch: Contains the actual XML definition of the Gantt chart.<gantt>tag: The root element for your Gantt view.string: The title displayed at the top of the Gantt chart.date_start: Crucial! The technical name of your model’s field that indicates the start date/time.date_stop: Crucial! The technical name of your model’s field that indicates the end date/time. Note: It’sdate_stop, notdate_end.
Important: Make sure this XML file is included in your module’s __manifest__.py under the data key.
3. Registering Your Gantt View in Odoo Actions
For users to actually access your new Gantt view, you need to register it within an existing window action (ir.actions.act_window) or create a new one. This tells Odoo which view types are available for a given model.
Action: Locate your model’s window action XML (e.g., in your_module/views/actions.xml or within gantt_views.xml if creating a new action).
Example XML Code:
<odoo>
<data>
<!-- Existing or New Window Action -->
<record id="action_your_model" model="ir.actions.act_window">
<field name="name">Your Model Records</field>
<field name="res_model">your.model</field>
<field name="view_mode">tree,form,gantt</field> <!-- Add 'gantt' here -->
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create a new record to manage its timeline!
</p>
</field>
</record>
<!-- Optional: Menu Item to access the action -->
<menuitem id="menu_your_model"
name="My Projects"
parent="base.menu_root"
action="action_your_model"
sequence="10"/>
</data>
</odoo>
Explanation: By adding gantt to the view_mode field, an icon for the Gantt view will appear alongside other view types (like List/Tree, Form, Kanban) when users navigate to your model’s records.
4. Enhancing Visualization with Grouping Options
Grouping is essential for organizing your Gantt chart. You can group tasks by various fields, like status, assigned user, or project phase.
Action: Add the group_by attribute to your <gantt> tag.
Example XML Code (within the <gantt> tag):
<gantt string="My Awesome Project Timeline"
date_start="start_date"
date_stop="end_date"
default_group_by="status_id"> <!-- Groups records by their status -->
</gantt>
default_group_by: This attribute makes the grouping permanent upon loading the view. If you just use group_by, users can manually group, but it won’t persist after refreshing the page. Here, status_id is a Many2one field referring to a separate your.status.model.
Internal Link: To learn more about other view types and actions, you can explore Odoo’s official documentation on Odoo Views.
5. Dynamic Styling with Decorations for Your Gantt View
Decorations allow you to visually highlight Gantt bars based on specific conditions, using Bootstrap classes. This is a powerful way to convey status or urgency at a glance.
Action: Add decoration- attributes within your <gantt> tag.
Example XML Code (within the <gantt> tag):
<gantt string="My Awesome Project Timeline"
date_start="start_date"
date_stop="end_date"
default_group_by="status_id">
<field name="status_id"/> <!-- Required if using status_id in conditions -->
<decoration-danger="status_id[0] == 1"/> <!-- If status ID is 1 (e.g., 'Draft'), make it red -->
<decoration-warning="status_id[0] == 2"/> <!-- If status ID is 2 (e.g., 'In Progress'), make it orange -->
<decoration-info="user_id == uid"/> <!-- If the current record is assigned to the current user, make it blue -->
<decoration-success="status_id[0] == 5"/> <!-- If status ID is 5 (e.g., 'Done'), make it green -->
</gantt>
Explanation:
decoration-danger,decoration-warning,decoration-info,decoration-success, etc.: These apply standard Bootstrap colors.- Conditions: The value of these attributes are Python expressions that evaluate to
TrueorFalse. - Relational Fields (Many2one): When checking conditions on
Many2onefields (likestatus_id), remember that Odoo returns a tuple(ID, Name). So, to check the ID, you must usestatus_id[0]. uid: A special variable representing the ID of the currently logged-in user.<field name="status_id"/>: It’s good practice to declare any fields you use in conditions or popovers directly under the<gantt>tag, even if they aren’t directlydate_startordate_stop.
6. Implementing Color-Coding for Clarity
Beyond decorations, you can also apply custom colors to the Gantt bars based on a field’s value, providing another layer of visual distinction. This is often used for categorizing tasks.
Action: Use the color attribute within your <gantt> tag.
Example XML Code (within the <gantt> tag):
<gantt string="My Awesome Project Timeline"
date_start="start_date"
date_stop="end_date"
default_group_by="status_id"
color="status_id"> <!-- Assigns different colors based on status_id -->
</gantt>
Explanation: Odoo’s frontend automatically maps the ID of the status_id (or any integer-based field) to a predefined set of colors, ensuring consistency without needing to define explicit color codes. This is a quick and easy way to create Odoo Gantt View with visually distinct categories.
7. Customizing Time Scales for Better Overview
Users often need to view the Gantt chart at different levels of granularity (day, week, month, year). You can control which scales are available in the view.
Action: Add the scales attribute to your <gantt> tag.
Example XML Code (within the <gantt> tag):
<gantt string="My Awesome Project Timeline"
date_start="start_date"
date_stop="end_date"
default_group_by="status_id"
scales="day,week,month,year" /> <!-- Available scales -->
scales: A comma-separated string of the desired scales (day, week, month, year). You can limit these to provide a more focused view if needed (e.g., scales="week,month").
8. Controlling User Interaction: Disabling Drag and Drop
Sometimes, you want to prevent users from accidentally (or intentionally) moving tasks around directly on the Gantt chart.
Action: Use the disable_dragdrop attribute.
Example XML Code (within the <gantt> tag):
<gantt string="My Awesome Project Timeline"
date_start="start_date"
date_stop="end_date"
disable_dragdrop="1" /> <!-- Disables drag and drop for task bars -->
disable_dragdrop="1": Setting this to 1 (or true) will prevent users from dragging the Gantt bars to change their start and end dates. A small “lock” icon will appear on the bars.
9. Richer Information: Mastering Popover Templates
When a user clicks on a Gantt bar, a small popover typically appears, showing basic information. You can customize this popover to display more relevant details using QWeb templates.
Action: Add a <templates> section with a t-name="gantt-popover" template.
Example XML Code (within the <gantt> tag, after date_stop or other attributes):
<gantt string="My Awesome Project Timeline"
date_start="start_date"
date_stop="end_date"
default_group_by="status_id">
<field name="name"/>
<field name="amount"/>
<field name="status_id"/>
<field name="start_date"/>
<field name="end_date"/>
<templates>
<t t-name="gantt-popover">
<div class="o_gantt_popover_content">
<strong>Task:</strong> <t t-out="name"/><br/>
<strong>Amount:</strong> <t t-out="amount"/><br/>
<strong>Status:</strong> <t t-out="status_id[1]"/><br/>
<strong>Start:</strong> <t t-out="start_date" t-options='{"widget": "date"}'/><br/>
<strong>End:</strong> <t t-out="end_date" t-options='{"widget": "date"}'/><br/>
<!-- Add more fields as needed -->
</div>
</t>
</templates>
</gantt>
Explanation:
<templates>: This tag encloses all QWeb templates for the view.<t t-name="gantt-popover">: This specific template name is recognized by Odoo for the Gantt popover.<field name="..."/>: Crucially, any fields you want to display in the popover must be declared as<field name="field_name"/>directly under the<gantt>tag. Odoo loads these fields’ data when the Gantt view is rendered.<t t-out="field_name"/>: This QWeb directive outputs the value of the specified field.field_name[1]for Many2one: To display the name (not the ID) of a Many2one field, usefield_name[1].t-options='{"widget": "date"}'ort-options='{"widget": "datetime"}': Essential for properly formattingDateandDatetimefields within the QWeb template.<br/>: Used for line breaks to format the popover content.
10. Granular Control: Managing User Creation, Editing, and Deletion
You might want to restrict certain user actions directly from the Gantt view interface.
Action: Add create, edit, and delete attributes to your <gantt> tag.
Example XML Code (within the <gantt> tag):
<gantt string="My Awesome Project Timeline"
date_start="start_date"
date_stop="end_date"
create="false" <!-- Disables the 'Create' button -->
edit="false" <!-- Prevents users from editing record details via popover -->
delete="false" /> <!-- Removes the 'Delete' option from the popover -->
create="false": Removes the “New” button in the Gantt view, preventing users from creating records directly there.edit="false": Disables the “Edit” button in the popover, forcing users to navigate to the form view to make changes.delete="false": Removes the “Delete” button from the popover.
11. Boosting Insights with a Total Row
For grouped Gantt views, a total row can provide a quick summary, such as the number of records within each group or for the entire visible timeline.
Action: Add the total_row attribute.
Example XML Code (within the <gantt> tag):
<gantt string="My Awesome Project Timeline"
date_start="start_date"
date_stop="end_date"
default_group_by="status_id"
total_row="true" /> <!-- Displays a total row for each group -->
total_row="true": When set to true, Odoo will display a row at the top of each group (if default_group_by is active) showing a summary, such as the total number of records within that group. This helps in quickly assessing the workload or count of items in a category.
12. Visualizing Interdependencies in Your Odoo Gantt View
One of the most powerful features of a Gantt chart is visualizing dependencies between tasks. This allows you to see which tasks must be completed before others can begin. To achieve this in Odoo, you need two Many2many fields on your model: one for the ‘children’ (tasks that depend on the current task) and one for the ‘parents’ (tasks that the current task depends on).
Action: Add dependency_field and dependency_inverted_field attributes to your <gantt> tag.
Example XML Code (within the <gantt> tag):
<gantt string="My Awesome Project Timeline"
date_start="start_date"
date_stop="end_date"
dependency_field="child_school_ids" <!-- Field holding tasks that depend on THIS task -->
dependency_inverted_field="parent_school_id"/> <!-- Field holding tasks that THIS task depends on -->
Explanation:
dependency_field: This attribute specifies the Many2many field on your model that links to records which depend on the current record (i.e., its children). In the context example,child_school_idsrepresents other schools that depend on the current school.dependency_inverted_field: This attribute specifies the Many2many field on your model that links to records which the current record depends on (i.e., its parents). In the context example,parent_school_idrepresents schools that the current school depends on.- Crucial for Functionality: Both attributes must be present and correctly configured with Many2many fields. If you only provide one, Odoo will raise an error upon module upgrade.
- How it looks: Once configured, you’ll see small arrow lines connecting dependent tasks, visually indicating the flow and sequence of work. This is an incredible tool to create Odoo Gantt View that truly aids in complex project management.
13. Finalizing Your Changes: Updating the Module
After making any changes to your Python models or XML view definitions, you need to update your Odoo module for the changes to take effect.
Action: Update your custom module in Odoo.
Steps to Update:
- Navigate to Apps in your Odoo instance.
- Remove the “Apps” filter.
- Search for your custom module.
- Click the “Update” button for your module.
Alternatively, for developers, you can restart your Odoo server with the -u flag followed by your module name (e.g., sudo /path/to/odoo-bin -u your_module -c /etc/odoo/odoo.conf).
Practical Tips and Best Practices for Your Odoo Gantt View
- Keep it Simple Initially: When you first create Odoo Gantt View, start with the basic
date_startanddate_stopfields. Gradually addgroup_by,decorations, and other features. - Test Thoroughly: After each significant change, update your module and test the Gantt view. This helps pinpoint issues early.
- Understand Field Types: Be mindful of
Datevs.Datetimeand how they affect yourdate_start/date_stopfields and popover formatting. - Clear Labels: Use meaningful
stringattributes for your fields and the Gantt view itself. - Performance Considerations: For models with thousands of records, complex decorations or dependencies might impact performance. Optimize your data and conditions where possible.
- User Training: If your team isn’t familiar with Gantt charts, provide a brief explanation of how to interpret and interact with the view.
Troubleshooting Common Issues
Even with a step-by-step guide, you might encounter bumps along the way. Here are some common issues and their solutions when you create Odoo Gantt View:
- Gantt View Not Showing in View Mode:
- Check
view_mode: Ensureganttis explicitly included in theview_modefield of your window action (ir.actions.act_window). - Module Update: Always remember to update your module after any XML changes.
- Odoo Enterprise: Confirm your Odoo instance is the Enterprise Edition.
- Check
- Error Message During Module Update (e.g.,
AttributeError: 'gantt' object has no attribute 'date_end'):- Typo in
date_stop: The most common error is usingdate_endinstead ofdate_stop. Double-check this attribute name. - Missing Field: Ensure the fields specified in
date_startanddate_stopactually exist in your Python model.
- Typo in
- Popover Not Displaying or Showing Incorrect Data:
<field name="..."/>Declaration: All fields used within yourgantt-popovertemplate (t-out="field_name") must be explicitly declared as<field name="field_name"/>directly under the<gantt>tag.- Relational Field Index: For Many2one fields, use
field_name[0]for the ID andfield_name[1]for the display name in conditions ort-outdirectives respectively. - Date/Datetime Formatting: Ensure you use
t-options='{"widget": "date"}'ort-options='{"widget": "datetime"}'for proper display of date fields.
- Dependency Arrows Not Showing or Causing Errors:
- Both Fields Required: You must define both
dependency_fieldanddependency_inverted_fieldattributes. Providing only one will result in an error. - Many2many Fields: Confirm that both fields specified are indeed Many2many fields pointing to the same model.
- Data Integrity: Ensure your data actually has dependencies. If no records are linked, no arrows will appear.
- Both Fields Required: You must define both
- Decorations Not Applying Colors:
- Field Declaration: Ensure the field used in the
decoration-condition (e.g.,status_id) is declared with<field name="status_id"/>under the<gantt>tag. - Relational Field Index: For Many2one fields, remember to use
field_name[0]to access the ID in your condition (e.g.,decoration-danger="status_id[0] == 1"). - Condition Logic: Double-check your Python expression for the condition.
- Field Declaration: Ensure the field used in the
Conclusion
Congratulations! You’ve successfully learned how to Create Odoo Gantt View in Odoo 18 Enterprise. By following these detailed steps, you can now build powerful, interactive Gantt charts that bring clarity and efficiency to your project management, resource allocation, and overall operational planning.
The Odoo Gantt view is more than just a visualization; it’s a strategic tool that empowers you to make informed decisions, anticipate challenges, and ensure your projects stay on track. Experiment with the various attributes – grouping, decorations, popover templates, and dependencies – to tailor the view precisely to your business needs. Embrace the visual power of Gantt charts and transform the way you manage tasks and timelines in Odoo!
If you still have any doubts or run into specific issues while implementing your Odoo Gantt view, feel free to comment below or consult the vibrant Odoo developer community. Happy developing!
Discover more from teguhteja.id
Subscribe to get the latest posts sent to your email.

