SlideShare a Scribd company logo
3
Most read
6
Most read
15
Most read
Developing New Widgets for your Views in Owl
Assets Management
How to load templates?
How to write odoo-compatible code?
Owl QWeb
Renderer
Old QWeb Engine
Communication with events
Widget
In Widgets:
● events bubble up widget tree
● generated with trigger_up
● caught with custom_events
● use underscores: “something_happened”
In Components:
● events bubble up DOM tree
● generated with trigger
● caught with t-on- directive
● use dash: “something-happened”
across boundaries
Component
Widget
From imperative
to declarative
Widgets are instantiated/updated
manually
Components are instantiated/updated by
Owl
Lifecycle remapping
across boundaries
Widgets
on_attach_callback
on_detach_callback
Components
mounted
willUnmount
JS code style
● No static class fields
● No ultra modern ES features
● No inline template
class MyComponent extends Component {
static template = xml`<div>my template</div>`;
static components = { SubComponent };
...
}
class MyComponent extends Component {
...
}
MyComponent.template =
'myModule.MyComponent';
MyComponent.components = {
SubComponent
};
Owl templates
Add a special attribute: owl=”1” for owl components
<t t-name="AddToGoogleSpreadsheetMenu" owl="1">
<li class="o_menu_item o_add_to_spreadsheet" role="menuitem">
<a class="dropdown-item" href="#"
t-on-click.prevent="_onAddToSpreadsheet">
Add to Google Spreadsheet
</a>
</li>
</t>
View widgets in Owl
<field name="payments_widget" widget="payment"/>
Adding owl field widgets in
views
const AbstractField = require('web.AbstractFieldOwl);
class FieldBadge extends AbstractField {
_getClassFromDecoration(decoration) {
return `bg-${decoration.split('-')[1]}-light`;
}
}
FieldBadge.description = _lt("Badge");
FieldBadge.supportedFieldTypes = ['selection',
'many2one', 'char'];
FieldBadge.template = 'web.FieldBadge';
const registry = require('web.field_registry_owl');
registry
.add('badge', FieldBadge);
<field name="state" widget="badge"/>
It works for: form/list/kanban views
➔ Subclass AbstractFieldOwl (exported in
‘web.AbstractFieldOwl’)
➔ Register it in ‘web.field_registry_owl’
➔ Don’t forget to add widget=... in the arch
What you (might) need to know:
AbstractField API
(web.AbstractFieldOwl)
- field
- isEmpty
- ...
Odoo Env (web.env)
- services
- _t
- bus
- ...
Owl components in Odoo
● Component/Component
● Component/Widget
● Widget/Component
3 kinds of boundaries
1. Component/Component
<t t-name="myModule.AddMyComponent"
t-inherit="web.SomeTemplate"
t-inherit-mode="extension"
owl="1">
<xpath expr="//div[@class='abc']"
position="inside">
<MyComponent mode="’readonly’" />
</xpath>
</t>
class MyComponent extends Component {
...
}
// register the new component as a sub component for
the parent
ParentComponent.components.MyComponent = MyComponent
Standard owl development.
➔ XPath the parent template to add a tag
<MyComponent/> where needed (it
works!!!)
➔ Add MyComponent to parent static
components key
Owl Compatibility Helpers
Component inside Widget Widget inside Component
web.OwlCompatibility
Owl Component
ComponentAdapter
Some Widget
SomeWidget +
WidgetAdapterMixin
ComponentWrapper
Owl Component
2. Component inside Widget
➔ Client action (Hello world)
const AbstractAction =
require('web.AbstractAction');
const { actionRegistry } = require('web.core');
const { ComponentWrapper, WidgetAdapterMixin} =
require('web.OwlCompatibility');
const { Component, tags } = owl;
class HelloWorld extends Component {}
HelloWorld.template = tags.xml`<div>Hello
World!</div>`;
const ClientAction =
AbstractAction.extend(WidgetAdapterMixin, {
start() {
const component =
new ComponentWrapper(this, HelloWorld);
return component.mount(
this.el.querySelector('.o_content')
);
},
});
actionRegistry.add('client_action',
ClientAction);
3. Widget inside Component
with ComponentAdapter
const MyWidget = Widget.extend({
start: function () {
this.$el.text('Hello World!');
}
});
class Parent extends Component {
constructor() {
super(...arguments);
this.MyWidget = MyWidget;
}
}
Parent.template = xml`
<div>
<ComponentAdapter
Component="MyWidget"/>
</div>`;
Parent.components = { ComponentAdapter };
Thank You

More Related Content

What's hot (20)

PDF
React redux-tutoriel-1
Sem Koto
 
PDF
VueJS: The Simple Revolution
Rafael Casuso Romate
 
PPTX
Widgets in odoo
Celine George
 
PPTX
Set Default Values to Fields in Odoo 15
Celine George
 
PDF
Android Toast.pdf
John Benetic
 
PDF
Redux Toolkit - Quick Intro - 2022
Fabio Biondi
 
PDF
Angular & RXJS: examples and use cases
Fabio Biondi
 
PPT
JavaScript: Events Handling
Yuriy Bezgachnyuk
 
PDF
Railway Oriented Programming
Scott Wlaschin
 
PPT
Spring Batch 2.0
Guido Schmutz
 
PDF
Angular Directives
iFour Technolab Pvt. Ltd.
 
PPTX
Empower your App by Inheriting from Odoo Mixins
Odoo
 
PDF
Angular Advanced Routing
Laurent Duveau
 
PDF
Introduction à React
Thibault Martinez
 
PPT
Java Persistence API (JPA) Step By Step
Guo Albert
 
PDF
HTML5: features with examples
Alfredo Torre
 
ODP
An Introduction to Vuejs
Paddy Lock
 
PPTX
Introduction to spring boot
Santosh Kumar Kar
 
PDF
react redux.pdf
Knoldus Inc.
 
PPT
ASP.NET 10 - Data Controls
Randy Connolly
 
React redux-tutoriel-1
Sem Koto
 
VueJS: The Simple Revolution
Rafael Casuso Romate
 
Widgets in odoo
Celine George
 
Set Default Values to Fields in Odoo 15
Celine George
 
Android Toast.pdf
John Benetic
 
Redux Toolkit - Quick Intro - 2022
Fabio Biondi
 
Angular & RXJS: examples and use cases
Fabio Biondi
 
JavaScript: Events Handling
Yuriy Bezgachnyuk
 
Railway Oriented Programming
Scott Wlaschin
 
Spring Batch 2.0
Guido Schmutz
 
Angular Directives
iFour Technolab Pvt. Ltd.
 
Empower your App by Inheriting from Odoo Mixins
Odoo
 
Angular Advanced Routing
Laurent Duveau
 
Introduction à React
Thibault Martinez
 
Java Persistence API (JPA) Step By Step
Guo Albert
 
HTML5: features with examples
Alfredo Torre
 
An Introduction to Vuejs
Paddy Lock
 
Introduction to spring boot
Santosh Kumar Kar
 
react redux.pdf
Knoldus Inc.
 
ASP.NET 10 - Data Controls
Randy Connolly
 

More from Odoo (20)

PPTX
Timesheet Workshop: The Timesheet App People Love!
Odoo
 
PPTX
Odoo 3D Product View with Google Model-Viewer
Odoo
 
PPTX
Keynote - Vision & Strategy
Odoo
 
PPTX
Opening Keynote - Unveilling Odoo 14
Odoo
 
PDF
Extending Odoo with a Comprehensive Budgeting and Forecasting Capability
Odoo
 
PDF
Managing Multi-channel Selling with Odoo
Odoo
 
PPTX
Product Configurator: Advanced Use Case
Odoo
 
PDF
Accounting Automation: How Much Money We Saved and How?
Odoo
 
PPTX
Rock Your Logistics with Advanced Operations
Odoo
 
PPTX
Transition from a cost to a flow-centric organization
Odoo
 
PDF
Synchronization: The Supply Chain Response to Overcome the Crisis
Odoo
 
PPTX
Running a University with Odoo
Odoo
 
PPTX
Down Payments on Purchase Orders in Odoo
Odoo
 
PPTX
Odoo Implementation in Phases - Success Story of a Retail Chain 3Sach food
Odoo
 
PPTX
Migration from Salesforce to Odoo
Odoo
 
PPTX
Preventing User Mistakes by Using Machine Learning
Odoo
 
PPTX
Becoming an Odoo Expert: How to Prepare for the Certification
Odoo
 
PPTX
Instant Printing of any Odoo Report or Shipping Label
Odoo
 
PPTX
How Odoo helped an Organization Grow 3 Fold
Odoo
 
PPTX
From Shopify to Odoo
Odoo
 
Timesheet Workshop: The Timesheet App People Love!
Odoo
 
Odoo 3D Product View with Google Model-Viewer
Odoo
 
Keynote - Vision & Strategy
Odoo
 
Opening Keynote - Unveilling Odoo 14
Odoo
 
Extending Odoo with a Comprehensive Budgeting and Forecasting Capability
Odoo
 
Managing Multi-channel Selling with Odoo
Odoo
 
Product Configurator: Advanced Use Case
Odoo
 
Accounting Automation: How Much Money We Saved and How?
Odoo
 
Rock Your Logistics with Advanced Operations
Odoo
 
Transition from a cost to a flow-centric organization
Odoo
 
Synchronization: The Supply Chain Response to Overcome the Crisis
Odoo
 
Running a University with Odoo
Odoo
 
Down Payments on Purchase Orders in Odoo
Odoo
 
Odoo Implementation in Phases - Success Story of a Retail Chain 3Sach food
Odoo
 
Migration from Salesforce to Odoo
Odoo
 
Preventing User Mistakes by Using Machine Learning
Odoo
 
Becoming an Odoo Expert: How to Prepare for the Certification
Odoo
 
Instant Printing of any Odoo Report or Shipping Label
Odoo
 
How Odoo helped an Organization Grow 3 Fold
Odoo
 
From Shopify to Odoo
Odoo
 
Ad

Recently uploaded (20)

PDF
Top 10 Common Mistakes Entrepreneurs Make When Applying for Business Subsidie...
shailjapariharoffici
 
PPTX
QuickBooks Database Server Manager.pptx a
seoczaranshu
 
PDF
Perfume Market Size, Share, Trends and Future Outlook 2025-2034
Rupal Dekate
 
PPTX
How Essar Transforms the Planet while Investing in People Over Profit
essarcase
 
PDF
Agentic AI: The Autonomous Upgrade Your AI Stack Didn’t Know It Needed
Amnic
 
PDF
🌿 Mohit Bansal – Building a Greener Future from Chandigarh.pdf
Mohit Bansal Chandigarh
 
PDF
2025.07_ TJ Communications Credentials.pdf
tjcomstrang
 
PDF
Corporate Governance for South African Mining Companies (a practitioner's view).
James AH Campbell
 
PDF
Beyond HR: Human Experience, Business Psychology, and the Future of Work
Seta Wicaksana
 
PDF
2025 Trends- What to Expect from the Best Medical Billing Agencies in Canada
India Data Entry Help
 
PDF
BCG's Guide to Cost and Growth 24pages file
Wipro Unza Vietnam Company Limited
 
PDF
IoT Identity and Access Management: A Growing Market Opportunity
GauriKale30
 
PPTX
Green Energy in India How the Energy Transition Is Reshaping the Power Sector...
Essar Group
 
PDF
Ulas Utku Bozdogan: A Global Career Fueled by Innovation
Ulas Utku Bozdogan
 
PDF
Rise of the Build Division, Conquering the Curve.pdf
Brij Consulting, LLC
 
PDF
5 Game-Changing AI Agent Tools Transforming FinOps.pdf
Amnic
 
DOCX
Andrew C. Belton, MBA Resume - July 2025
Andrew C. Belton
 
PDF
Mohit Bansal Chandigarh_ The Man Powering Mohali’s Real Estate Transformation...
mohitbansalchandigar4
 
PDF
Seven Causes of SMS Delivery Issues and Solutions for 2025.pdf
nusrat889955
 
PDF
Transforming Tricity Real Estate_ The Leadership of Mohit Bansal.pdf
Mohit Bansal GMI
 
Top 10 Common Mistakes Entrepreneurs Make When Applying for Business Subsidie...
shailjapariharoffici
 
QuickBooks Database Server Manager.pptx a
seoczaranshu
 
Perfume Market Size, Share, Trends and Future Outlook 2025-2034
Rupal Dekate
 
How Essar Transforms the Planet while Investing in People Over Profit
essarcase
 
Agentic AI: The Autonomous Upgrade Your AI Stack Didn’t Know It Needed
Amnic
 
🌿 Mohit Bansal – Building a Greener Future from Chandigarh.pdf
Mohit Bansal Chandigarh
 
2025.07_ TJ Communications Credentials.pdf
tjcomstrang
 
Corporate Governance for South African Mining Companies (a practitioner's view).
James AH Campbell
 
Beyond HR: Human Experience, Business Psychology, and the Future of Work
Seta Wicaksana
 
2025 Trends- What to Expect from the Best Medical Billing Agencies in Canada
India Data Entry Help
 
BCG's Guide to Cost and Growth 24pages file
Wipro Unza Vietnam Company Limited
 
IoT Identity and Access Management: A Growing Market Opportunity
GauriKale30
 
Green Energy in India How the Energy Transition Is Reshaping the Power Sector...
Essar Group
 
Ulas Utku Bozdogan: A Global Career Fueled by Innovation
Ulas Utku Bozdogan
 
Rise of the Build Division, Conquering the Curve.pdf
Brij Consulting, LLC
 
5 Game-Changing AI Agent Tools Transforming FinOps.pdf
Amnic
 
Andrew C. Belton, MBA Resume - July 2025
Andrew C. Belton
 
Mohit Bansal Chandigarh_ The Man Powering Mohali’s Real Estate Transformation...
mohitbansalchandigar4
 
Seven Causes of SMS Delivery Issues and Solutions for 2025.pdf
nusrat889955
 
Transforming Tricity Real Estate_ The Leadership of Mohit Bansal.pdf
Mohit Bansal GMI
 
Ad

Developing New Widgets for your Views in Owl

  • 2. Assets Management How to load templates? How to write odoo-compatible code? Owl QWeb Renderer Old QWeb Engine
  • 3. Communication with events Widget In Widgets: ● events bubble up widget tree ● generated with trigger_up ● caught with custom_events ● use underscores: “something_happened” In Components: ● events bubble up DOM tree ● generated with trigger ● caught with t-on- directive ● use dash: “something-happened” across boundaries Component Widget
  • 4. From imperative to declarative Widgets are instantiated/updated manually Components are instantiated/updated by Owl
  • 6. JS code style ● No static class fields ● No ultra modern ES features ● No inline template class MyComponent extends Component { static template = xml`<div>my template</div>`; static components = { SubComponent }; ... } class MyComponent extends Component { ... } MyComponent.template = 'myModule.MyComponent'; MyComponent.components = { SubComponent };
  • 7. Owl templates Add a special attribute: owl=”1” for owl components <t t-name="AddToGoogleSpreadsheetMenu" owl="1"> <li class="o_menu_item o_add_to_spreadsheet" role="menuitem"> <a class="dropdown-item" href="#" t-on-click.prevent="_onAddToSpreadsheet"> Add to Google Spreadsheet </a> </li> </t>
  • 8. View widgets in Owl <field name="payments_widget" widget="payment"/>
  • 9. Adding owl field widgets in views const AbstractField = require('web.AbstractFieldOwl); class FieldBadge extends AbstractField { _getClassFromDecoration(decoration) { return `bg-${decoration.split('-')[1]}-light`; } } FieldBadge.description = _lt("Badge"); FieldBadge.supportedFieldTypes = ['selection', 'many2one', 'char']; FieldBadge.template = 'web.FieldBadge'; const registry = require('web.field_registry_owl'); registry .add('badge', FieldBadge); <field name="state" widget="badge"/> It works for: form/list/kanban views ➔ Subclass AbstractFieldOwl (exported in ‘web.AbstractFieldOwl’) ➔ Register it in ‘web.field_registry_owl’ ➔ Don’t forget to add widget=... in the arch
  • 10. What you (might) need to know: AbstractField API (web.AbstractFieldOwl) - field - isEmpty - ... Odoo Env (web.env) - services - _t - bus - ...
  • 11. Owl components in Odoo ● Component/Component ● Component/Widget ● Widget/Component 3 kinds of boundaries
  • 12. 1. Component/Component <t t-name="myModule.AddMyComponent" t-inherit="web.SomeTemplate" t-inherit-mode="extension" owl="1"> <xpath expr="//div[@class='abc']" position="inside"> <MyComponent mode="’readonly’" /> </xpath> </t> class MyComponent extends Component { ... } // register the new component as a sub component for the parent ParentComponent.components.MyComponent = MyComponent Standard owl development. ➔ XPath the parent template to add a tag <MyComponent/> where needed (it works!!!) ➔ Add MyComponent to parent static components key
  • 13. Owl Compatibility Helpers Component inside Widget Widget inside Component web.OwlCompatibility Owl Component ComponentAdapter Some Widget SomeWidget + WidgetAdapterMixin ComponentWrapper Owl Component
  • 14. 2. Component inside Widget ➔ Client action (Hello world) const AbstractAction = require('web.AbstractAction'); const { actionRegistry } = require('web.core'); const { ComponentWrapper, WidgetAdapterMixin} = require('web.OwlCompatibility'); const { Component, tags } = owl; class HelloWorld extends Component {} HelloWorld.template = tags.xml`<div>Hello World!</div>`; const ClientAction = AbstractAction.extend(WidgetAdapterMixin, { start() { const component = new ComponentWrapper(this, HelloWorld); return component.mount( this.el.querySelector('.o_content') ); }, }); actionRegistry.add('client_action', ClientAction);
  • 15. 3. Widget inside Component with ComponentAdapter const MyWidget = Widget.extend({ start: function () { this.$el.text('Hello World!'); } }); class Parent extends Component { constructor() { super(...arguments); this.MyWidget = MyWidget; } } Parent.template = xml` <div> <ComponentAdapter Component="MyWidget"/> </div>`; Parent.components = { ComponentAdapter };

Editor's Notes

  • #7: let’s talk about the odoo ecosystem in general