Skip to Content

How To Create Button Near Create Button in Odoo

March 1, 2025 by
Dương Nguyễn
| No comments yet

How to create button near create button on list view odoo 17

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

&lttemplates id="template" xml:space="preserve">

	&ltt t-name="d_button_near_create_button.ButtonNearCreateButtonView.Buttons" t-inherit="web.ListView.Buttons" t-inherit-mode="primary" owl="1">
		&ltxpath expr="//div[@t-if='props.showButtons']" position="after">
			&ltbutton type="button" t-on-click="onCreateProject" class="btn btn-primary">
				Create project here as well
			&lt/button>
		&lt/xpath>
	&lt/t>

&lt/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 daiduongnguyen2709@gmail.comng

Other Version

Odoo 16: https://apps.odoo.com/apps/modules/18.0/d_button_near_create_button

Odoo 17: https://apps.odoo.com/apps/modules/18.0/d_button_near_create_button

Sign in to leave a comment