Skip to main content

How to Show Selection Field as Radio in Odoo

A selection field in Odoo is a drop-down list of options that users can choose from. When creating or editing a record, the selection field will be displayed as a list of dropdown buttons.

In some cases, if we need to render it as a radio widget, here is how to do it:

class TaxInvoiceExport(models.TransientModel):
    _name = 'wizard.tax.invoice'
    _description = 'Tax Invoice Export'

    invoice_type = fields.Selection(string='Type', selection=[('invoice', 'Invoice'), ('bill', 'Vendor Bill')], default="invoice")

In view, use widget=”radio”

<record model="ir.ui.view" id="tax_invoice_export_form_view">
    <field name="name">wizard.tax.invoice.form</field>
    <field name="model">wizard.tax.invoice</field>
    <field name="arch" type="xml">
        <form string="Invoices">
            <group>
                <field name="invoice_type" widget="radio"/>
            </group>
            <footer>
                <button name="any_method_here" type="object" string="Export" class="oe_highlight"/>
                or
                <button special="cancel" string="Cancel"/>
            </footer>
        </form>
    </field>
</record>

By continuing to use the site, you agree to the use of cookies.