Chapter 19 - Odoo 15 Development Book

Dynamic Record Stages

In the State field, we cannot remove or add new stages. In this case, if we use the many2one field, we can add/remove new stages at any time.

Let's see how we can do this.

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’)

Add the new stage_id field :

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_employee_id, readonly=True, required=True, help="Employee")
             

Add the new stage_id field in the form view:

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

These stages are clickable, and we can change the stages by clicking on them and can be folded.

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