Creating a Generic Controller in Odoo18 Website

FARHA
May 21, 2025
how-to-create-a-generic-controller-in-odoo18-website

In the modern day business world, websites play a crucial role in engaging customers, eventually enhancing the customer relationship and driving the business to a profitable outcome. Managing and customizing the website features using a customized ERP can definitely serve this purpose and Odoo18 is one such platform to achieve this.

Odoo 18 is super customizable for managing UAE business needs and data. and/or creating custom workflows. Apart from this, Odoo Website offers a user-friendly platform to create, manage and customize your websites. It includes various features and tools which will help you to design, publish and maintain web pages without the need of some advanced technical skills. We can easily customize layouts, add different contents and also integrate with other Odoo apps to enhance and expand the website’s functionality.

In Odoo, controllers can considered as the backbone of web-based developments as they are responsible for connecting the front-end and the back-end of the web modules. The controllers enable the developers to define custom URLs, fetch the required data from Odoo models and dynamically render it using Qweb templates.

Enhanced Web Experiences with Controllers

By growing Odoo’s core ERP functionalities, web controllers empower businesses to create seamless, interactive, and responsive experiences for customers, suppliers, and partners.

In this blog, we can look into the various steps involved in building a generic controller in Odoo18 website that will enable users to submit a website form to create records in any specified model.

The first step is adding a menu item that links to the website form. The below code for the menuitem can added in the .xml file.

how-to-create-a-generic-controller-in-odoo-18-website

Next step is to define the required controller function. This can added under the controllers folder as a .py file as shown in the below image.

generic-controller-in-odoo18-website

Designing the Website Form Template

The next step is to design the website form template. This template includes various input fields and also a button which will return an action to create a new record in the crm.lead model.

The below code can used to create the template. This can added in the .xml file.

odoo-18-web-routes
generic-controller-in-odoo18-website
odoo-website-development
generic-controller-in-odoo18-website
odoo-18-http-controller

Use a hidden input field for the model name in the website form. As shown in the example above, –

<input type="hidden" name="model" value="crm.lead"/>

The value attribute contains the target model’s name. Also please make sure the field names in the template correspond directly to the actual field names in the model. See below for the website form generated by the above code.

odoo18-generic-controller

After the form is customized, the next step is to configure the generic controller in Odoo18 website which will handle the actions after the website form is submitted.

create-controller-in-odoo-18
odoo18-website-controller

Configuring the Generic Controller for Data Handling

The above controller function processes the submitted website form data by creating a new record in the target model, i.e.,” crm.lead” specified in the form. It will dynamically detect the model’s fields and then map their corresponding values received from the website form submission to back-end. The fields and button actions given in the above example can be modified and customized as per the requirement, thereby giving a much more flexibility and utility.

Odoo website controllers are versatile tools used for building custom web experiences which allows you to customize web interactions by defining routes, implementing various business logics and workflows and controlling responses, making it a powerful tool for building data-driven web pages, portals, and reports.

Odoo18 Website development is key to building dynamic, interactive web experiences. It seamlessly connects user actions on the front end to Odoo’s back end, allowing you to easily define custom URLs, fetch data, and create records from web forms. This flexibility lets you tailor your website to specific business needs, from capturing leads to managing customer feedback. By extending your ERP online, you can boost engagement, workflows, and drive success. Reach out today for a personalized Odoo consultation today

"Automate Your Business with our Customized Odoo ERP Solutions"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

Your email address will not be published. Required fields are marked *