How to do it...

We’ll add a JavaScript file that contains our widget’s logic, and a CSS file to do some styling. Then, we also choose one field on the partner form to use our new widget. Follow the given steps:

  1. Add a static/src/js/r1_widgets.js file. For the syntax used here, refer to the Extending CSS and JavaScript for the website recipe from Chapter 16, CMS Website Development:
odoo.define('r1_widgets', function(require) {     var registry = require('web.field_registry'),         AbstractField = require('web.AbstractField');
  1. Create your widget by subclassing AbstractField:
var FieldMany2OneButtons = AbstractField.extend({
  1. Set the CSS class for the widget’s root div element:
className: 'oe_form_field_many2one_buttons',
  1. Override init to do ...

Get Odoo 11 Development Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.