Registries in Odoo18
Odoo version 18 offers exciting new features and additions, and among those is a useful well-built registry: a structured and efficient system for reuse components and services across the whole application. Registries in Odoo act as central collections for all key/value pairs to be used and enable developers to expand and master the Odoo web client rather than writing the same code multiple times. Each Odoo18 registries dependent on its individual functions, thus leading to better maintenance. This blog is going to cover all these registries, their tasks, as well as practical-use scenarios showcasing how to use them.
What Are Registries Categories
Categories of Registry are logical business units under the framework web of Odoo. Each category deals with some specific property, benefit, or function. The distribution ensures that a developer while doing such registration would require very specific insight into hosting and managing custom extensions in a non-cumbersome way.
Categories of Registries in Odoo18
Effects Registry
Usage : The establishment of effects registry is as important an aspect as it allows to manage reusable UI effects like animation or transitions all through the application which facilitates the consistent application of visual feedback throughout the application.
- To exemplify, putting in a fade-out effect for notifications would be an example.
/** @odoo-module **/
import { registry } from "@web/core/registry";
// Define a custom effect
const myCustomEffect = {
apply(element) {
element.style.transition = "opacity 0.5s";
element.style.opacity = 0;
},
};
// Register the effect registry.category(“effects”).add(“fade_out”, myCustomEffect);
Formatters Registry
Purpose: This registry contains utility functions for formatting values, particularly field data. It’s useful when you need consistent formatting across the application.
Example: Formatting a number as currency.
/** @odoo-module **/
import { registry } from "@web/core/registry";
// Define a custom formatter
const currencyFormatter = {
format(value) {
return `$${value.toFixed(2)}`;
},
};
// Register the formatter
registry.category(“formatters”).add(“currency_formatter”, currencyFormatter);
Main Components Registry
Purpose: This category manages top-level UI components such as modals,
- widgets, and other reusable interface elements.
- Example: Adding a custom modal component
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { Component } from "@odoo/owl";
// Define a custom modal component
class CustomModal extends Component {
static template = "<div class='custom-modal'>Hello, Modal!</div>";
}
// Register the component
registry.category(“main_components”).add(“custom_modal”, CustomModal)
Parsers Registry
- Purpose: The parsers registry provides utility functions to parse raw data,
such as strings, into specific data types. - Example: Parsing a date string into a JavaScript Date object.
/** @odoo-module **/
import { registry } from "@web/core/registry";
// Define a custom parser
const dateParser = {
parse(value) {
return new Date(value);
},
};
// Register the parser
registry category(“parsers”).add(“date_parser”, dateParser);
Services Registry
- Purpose: Services are centralized functionalities or APIs that can be accessed
throughout the application. The services registry manages these reusable
pieces of logic. - Example: Creating a notification service
/** @odoo-module **/
import { registry } from "@web/core/registry";
const notificationService = {
name: "notification_service",
start() {
return {
notify(message) {
console.log("Notification: ", message);
},
};
},
};
// Register the service
registry.category(“services”).add(“notification_service”, notificationService);
Systray Registry
- Purpose: The systray registry manages components displayed in the systray
zone, located at the top-right corner of the navbar. This is ideal for adding
quick-access icons or widgets. - Example: Adding a custom systray component.
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { Component } from "@odoo/owl";
class CustomSystray extends Component {
static template = "<div class='custom-systray'>My Icon</div>";
}
// Register the systray component
registry.category(“systray”).add(“custom_systray”, CustomSystray);
User Menu Items Registry
- Purpose: This registry allows you to add custom menu items to the user menu
(accessible in the top-right corner). - Example: Adding a help link to the user menu.
/** @odoo-module **/
import { registry } from "@web/core/registry";
const helpMenuItem = {
name: "help",
action() {
window.open("https://help.example.com", "_blank");
},
};
// Register the menu item
registry.category(“user_menuitems”).add(“help_item”, helpMenuItem);
Views Registry
- Purpose: The views registry handles view types, such as kanban, list, and
form views, along with their respective renderers. - Example: Adding a custom renderer for a new view type
** @odoo-module **/
import { registry } from "@web/core/registry";
const customViewRenderer = {
render(params) {
console.log("Rendering custom view with params: ", params);
},
};
// Register the custom view
registry.category(“views”).add(“custom_view”, customViewRenderer);
Why Registry Categories Matter
- Modularity: By grouping related functionality, Odoo ensures that extensions are easy to find and manage
- Reusability: Registries promote the reuse of components, services, and utilities throughout the application.
- Customizability: Developers can seamlessly add new functionality or override existing ones without altering core code
- Scalability: As the application grows, registries make it easier to maintain organized code.
Odoo’s registry categories provide a robust framework for managing and extending functionality in a modular and maintainable way. Whether you’re adding custom UI components, formatting values, or creating new services, the registries system ensures that your work integrates seamlessly into the web client. By leveraging these categories effectively, developers can build scalable and reusable features that enhance the overall user experience. So, the next time you’re building a feature in Odoo18 take advantage of registries to keep your code clean and organized!
Odoo18 registries can get your business’s full potential and transform how you operate. With modularity, reusability, and customizability, Odoo18’s registry framework empowers businesses to simplify workflows, and user interfaces, and optimize services seamlessly. Let Bassam Infotech help you leverage these powerful tools with expert Odoo integration services to your needs. Contact us today and discover how Odoo18 can revolutionize your business processes.
"Unlock the Full Potential of Your Business with Odoo ERP!"
"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"
Get a Free Quote