Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 2.3 KB

6_statusBar.md

File metadata and controls

58 lines (40 loc) · 2.3 KB

Adding Status and Status Bar

  • For creating a status bar we have to create a selection field in python file. Here, a selection field status is created in appointment.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 a header with a field named status to show and change the status inside the form view and before the sheet tag.

    <header>
        <field name="status" widget="statusbar" statusbar_visible="draft,confirm,done" options="{'clickable':'1'}"/>
    </header>

    statusbar1

Control States and Status bar Using Buttons

  • 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 the xml file. One function is created in the appointment.py file. Try to create other functions for done and cancel.

    def action_status_confirm(self):
        self.status = 'confirmed'

    statusbar2

  • 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?"

    statusbar3

🚀 Happy Coding ! 🔥