In Odoo 8, the default radio widget displays radio buttons vertically by default. If you want to display them horizontally, you can customize the field widget to achieve this. Here's how you can do it:

  1. Create a Custom Radio Widget: First, you need to create a custom radio widget that displays the radio buttons horizontally. You can do this by extending the default radio widget.
javascript
odoo.define('your_module_name.horizontal_radio_widget', function (require) { 'use strict'; var core = require('web.core'); var FieldRadio = require('web.basic_fields').FieldRadio; var HorizontalRadioWidget = FieldRadio.extend({ _renderEdit: function () { this.$el.empty(); var self = this; _.each(this.nodeOptions, function (option) { var $radio = $('<input/>', { type: 'radio', id: _.uniqueId(), name: self.name, value: option.val, checked: self.value === option.val, }); var $label = $('<label/>', { for: $radio.prop('id'), text: option.name, }); $label.addClass('radio-inline'); // Bootstrap class to display horizontally $radio.appendTo(self.$el); $label.appendTo(self.$el); }); }, }); core.form_widget_registry.add('horizontal_radio', HorizontalRadioWidget); return HorizontalRadioWidget; });
  1. Register the Custom Widget: Now, you need to register your custom widget in the Odoo web client by adding it to the asset bundle. Create a new XML file (e.g., your_module_name/static/src/xml/horizontal_radio.xml) with the following content:
xml
<templates> <t t-name="FieldRadio"> <t t-if="widget.horizontal"> <div class="o_horizontal_radio"> <input t-attf-id="#{widget_id}" t-att-name="widget.name" t-att-value="option.val" type="radio" t-att-checked="widget.value === option.val" t-att-data-oe-field="widget.field"/> <label t-att-for="#{widget_id}" t-att-title="option.title"> <t t-esc="option.name"/> </label> </div> </t> <t t-else=""> ... </t> </t> </templates>
  1. Load the Custom Widget: To load the custom widget, you need to include it in your Odoo asset bundle. In your module's __openerp__.py file, add the following line:
python
{ 'name': 'Your Module Name', 'version': '1.0', 'depends': ['web'], 'data': [ 'static/src/xml/horizontal_radio.xml', ], 'qweb': [ 'static/src/xml/horizontal_radio.xml', ], }
  1. Use the Custom Widget: Finally, you can use the custom widget in your model definition by setting the widget attribute to 'horizontal_radio' for the desired radio field.
python
from openerp import models, fields class YourModel(models.Model): _name = 'your.model' _description = 'Your Model' your_radio_field = fields.Selection( selection=[('value1', 'Label 1'), ('value2', 'Label 2')], string='Your Radio Field', widget='horizontal_radio', # Use the custom widget here )

With these steps, you should have a custom radio widget that displays the radio buttons horizontally in Odoo 8. Remember to customize the widget further if needed to suit your specific requirements.

Have questions or queries?
Get in Touch