Odoo 16 Development Book

Dynamic record stages

Stages are used in Odoo to specify the record's current state. In many cases, these fields are static and cannot be changed. Thus it is possible to use many2one fields to give access to update and create new states in accordance with. Let’s understand how it works, along with an example.

In order to manage the stages individually, let’s create a new 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')
   name = fields.Char(string='Sequence')

This model needs to be added in the required parent model in a many2one relation.

def _get_stage_id(self):
   dynamic_stages = self.env['dynamic.stages'].search([], limit=1)
   return dynamic_stages.id
stage_id = fields.Many2one('dynamic.stages', string="Dynamic State", default='_get_stage_id', readonly=True,
                          required=True, help="Employee")

Now this field can be added to the view as the following;

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

Once the fields are declared as such, we can then change and fold the stages. In this way, the stage definitions can be manipulated.

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