-
For creating a status bar we have to create a selection field in python file. Here, a selection field
status
is created inappointment.py
file.status = fields.Selection([ ('draft', 'Draft'), ('confirmed', 'Confirmed'), ('done', 'Done'), ('cancel', 'Canceled') ], default='draft', required=True)
-
In the
appointment_view.xml
, we have to add aheader
with a field namedstatus
to show and change the status inside the form view and before thesheet
tag.<header> <field name="status" widget="statusbar" statusbar_visible="draft,confirm,done" options="{'clickable':'1'}"/> </header>
-
We can also control states by using button. For this purpose we have create buttons for changing the states. Here are some examples that we have to add inside the
header
tag:<button id="button_confirm" name="action_status_confirm" string="Confirm" class="btn-warning" type="object"/> <button id="button_done" name="action_status_done" string="Done" class="btn-success" type="object"/> <button id="button_cancel" name="action_status_cancel" string="Cancel" class="btn-danger" type="object"/>
-
Then we have to create functions for changing the states corresponding to its
name
in thexml
file. One function is created in theappointment.py
file. Try to create other functions fordone
andcancel
.def action_status_confirm(self): self.status = 'confirmed'
-
Check this code examples:
-
To show the confirmation message after button press we have to add below code inside the
button
.confirm="Are you sure you want to confirm?"