v 17.0 Third Party 70
Download for v 17.0 Deploy on Odoo.sh
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
LicenseOPL-1
Websitehttp://daiduongnguyen2709@gmail.com
Versions 17.0 16.0
You bought this module and need support? Click here!
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
LicenseOPL-1
Websitehttp://daiduongnguyen2709@gmail.com
Versions 17.0 16.0

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

Overview

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/*/*',
        ],
    },
		
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

  • The author can leave a single reply to each comment.
  • This section is meant to ask simple questions or leave a rating. Every report of a problem experienced while using the module should be addressed to the author directly (refer to the following point).
  • If you want to start a discussion with the author, please use the developer contact information. They can usually be found in the description.
Please choose a rating from 1 to 5 for this module.
Hi iam an odoo developer in Viindoo JSC, feel free to email me if you need some help
by
Dương Nguyễn
on 3/11/24, 6:25 AM Author



There are no comments yet!