Availability |
Odoo Online
Odoo.sh
On Premise
|
Odoo Apps Dependencies |
•
Project (project)
• Discuss (mail) |
Lines of code | 59 |
Technical Name |
d_button_near_create_button |
License | OPL-1 |
Website | https://duong-odoo-apps.odoo.com |
Versions | 16.0 17.0 18.0 |
Availability |
Odoo Online
Odoo.sh
On Premise
|
Odoo Apps Dependencies |
•
Project (project)
• Discuss (mail) |
Lines of code | 59 |
Technical Name |
d_button_near_create_button |
License | OPL-1 |
Website | https://duong-odoo-apps.odoo.com |
Versions | 16.0 17.0 18.0 |
How to create button near create button on list view odoo 16
Here is a module which is a quick tutorial to learn to create button near create button on list view

STEP 1
First we start with JS Code
/** @odoo-module */ import { useService } from "@web/core/utils/hooks"; import { ListController } from "@web/views/list/list_controller"; export class ButtonNearCreateButtonController extends ListController { setup() { super.setup(); this.orm = useService("orm"); } async onCreateProject() { let project_data = { name : 'Test'}; // Both way will create project await this.orm.call('project.project', 'action_create_project', [project_data], {}); // this one call a python method that we define in the project model await this.orm.create("project.project", [project_data], {}); // this one call the ORM create method that Odoo already define for us await this.model.root.load(); this.model.notify(); } }
Extend logic from the List Controller, note most business logic are implemented here, like the logic of the create button for example so in order to have our logic we extend its from here
The method onCreateProject() is going to assign to a button that we are going to create then when press that button, we call a method in the js code or the ORM 'create' method
STEP 2
View inheritance to add button near create button
Create a xml file , you can name whatever you like, and the xml need to be like this
<templates id="template" xml:space="preserve"> <t t-name="d_button_near_create_button.ButtonNearCreateButtonView.Buttons" t-inherit="web.ListView.Buttons" t-inherit-mode="primary" owl="1"> <xpath expr="//t[@t-if='props.showButtons']" position="after"> <button type="button" t-on-click="onCreateProject" class="btn btn-primary"> Create project here as well </button> </xpath> </t> </templates>
STEP 3
Register using registry in order to tell Odoo to recognize our code
/** @odoo-module */ import { listView } from "@web/views/list/list_view"; import { registry } from "@web/core/registry"; import { ButtonNearCreateButtonController as Controller } from './button_near_create_button_controller'; export const ButtonNearCreateButtonView = { ...listView, Controller, buttonTemplate: 'd_button_near_create_button.ButtonNearCreateButtonView.Buttons', }; registry.category("views").add("button_near_create_button", ButtonNearCreateButtonView);
STEP 4
And most importantly is to remember to define js code in manifest. And you good to go
'assets': { 'web.assets_backend': [ '/d_button_near_create_button/static/src/views/*/*', ], },
SUPPORT EMAIL
contact me for support duongodooapps@gmail.com
Odoo Proprietary License v1.0 This software and associated files (the "Software") may only be used (executed, modified, executed after modifications) if you have purchased a valid license from the authors, typically via Odoo Apps, or if you have received a written agreement from the authors of the Software (see the COPYRIGHT file). You may develop Odoo modules that use the Software as a library (typically by depending on it, importing it and using its resources), but without copying any source code or material from the Software. You may distribute those modules under the license of your choice, provided that this license is compatible with the terms of the Odoo Proprietary License (For example: LGPL, MIT, or proprietary licenses similar to this one). It is forbidden to publish, distribute, sublicense, or sell copies of the Software or modified copies of the Software. The above copyright notice and this permission notice must be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Please log in to comment on this module