Enable Dark Mode!
how-to-add-dynamic-record-stages-in-odoo-17.jpg
By: Ayana KP

How to add Dynamic Record Stages in Odoo 17

Functional

In Odoo 17, managing record stages dynamically can great enhance the flexibility and scalability of your business processes. With the ability to add, modify, and remove stages as needed, you can adapt to changing requirements and streamline your workflow effectively. In this blog post, we'll explore how to implant dynamic record stages in Odoo 17, empowering you to optimize your business processes and improve productivity.

To enable the ability to add or remove stages dynamically in the state field, you can utilize a many2one field instead. Here's how you can achieve this:

1. Create a new model for your stages with the necessary fields. Here's an example:-

class DynamicStages (models.Model):

class DynamicStages(models.Model):
   _name = 'dynamic.stages'
   _rec_name = 'name'
   
   name = fields.Char(string='Name')
   sequence = fields.Integer(string='Sequence')
   fold = fields.Boolean(string='Folded in Kanban')

The code snippet defines a Python class called `DynamicStages`. This class facilitates the management of dynamic stages, with attributes representing their names, sequences, and where they are solded in a Kanban view.

2. Add the new stage_id field to your desired model:-

stage_id = fields.Many2one(
   'dynamic.stages', string='Stage', index=True, tracking=True,
    readonly=False, store=True, copy=False, group_expand='_read_group_stage_ids', ondelete='restrict')
@api.model
def _read_group_stage_ids(self, stages, domain, order):
   stage_ids = stages._search([], order=order,
                              access_rights_uid=SUPERUSER_ID)
   return stages.browse(stage_ids)

This code snippet defines a Many-to-One relationship field named `stage_id`, linking records of the current model to those of the `dynamic.stages` model. The `@api.model` decorator marks the subsequent method `_read_group_stage_ids` as a model method, distinct from instance methods. Within this method, a search operation is performed on all records of the `dynamic.stages` model, disregarding access rights. The retrieved records are then returned to expand groups when the `stage_id` field is utilized in a search or filtering context.

3. Include the stage_id field in the form view using a status bar widget:-

<form>
   <header>
       <field name="stage_id" widget="statusbar" options="{'clickable': '1', 'fold_field': 'fold'}"/>
   </header>
   <sheet>
       <group>
           <field name="name"/>
       </group>
   </sheet>
</form>

This XML snippet defines a form view with a header section containing a status bar for the stage_id field and a sheet section with a group containing the name field. This layout provides a structured and organized interface for viewing and interacting with data.

4. Finally, add the stage_id field in the Kanban view with the default_group_by attribute:-

<kanban class="o_kanban_mobile" sample="1" default_group_by="stage_id">
            	<field name="name"/>
            	<field name="stage_id"/>
            	<templates>
                	<t t-name="kanban-box">
                    	<div t-attf-class="oe_kanban_global_click">
                        	<div class="row">
                            	<div class="col-12">
                                	<strong>
                                    	<field name="name"/>
                                	</strong>
                            	</div>
                        	</div>
                    	</div>
                	</t>
            	</templates>
        	</kanban>

This XML snippet defines a Kanban view with the Odoo framework. It sets up cards to display the `name` and `stage_id` fields, and it specifications that cards should be grouped by default according to the `stage_id` field. Additionally, it customizes the attitude of Kanban cards using templates, enhancing the visual appeal and functionality of the interface for managing records.

These stages are interactive, enabling modification through clicking, which includes the option to fold them. Following these steps will enable you to customize the behavior of Kanban columns to suit your needs.

Dynamic record stages in Odoo 17 offer a powerful tool for managing and organizing your business processes effectively. By following the steps outlined in this blog post, you can easily add dynamic stage functionality to your Odoo instance, enabling you to adapt to changing requirements and optimize your workflow. With dynamic stages, you can streamline your processes, improve collaboration, and drive productivity across your organization. 


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message