Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
4 Antworten
10481 Ansichten

Hi all, 

I'm new to odoo. Somebody, please tell me. How to add a button near create button in odoo 16. 

Avatar
Verwerfen
Beste Antwort

Hello Keyaan,

a button cannot be created with the Studio and has to be created with writing a new view or editing an existing one and then adding the code for a button.


Here below are the steps for creating a button:

1) First create a server action by going to the Settings=> Technicals => Server actions.


 Code in the above screenshot: records.action_confirm()   

Once the server action is saved, look at the url and note the number that is after id. In my case, it was 540.


2) Then go to the Technical => views => create new view. 


By Following the above steps, you will be able to create a button before the confirm button in the Sales module. 


Avatar
Verwerfen
Beste Antwort

Hi, you can follow this: https://youtu.be/MCEKCBA7zGk

Hope it helps,

Thanks

Avatar
Verwerfen
Beste Antwort

Hi I have this tutorial module which will help you
https://apps.odoo.com/apps/modules/16.0/d_button_near_create_button/

Avatar
Verwerfen
Beste Antwort

Hello,

In Odoo we can add buttons near the 'Create' button by extending the view.

For example, if we need to add an 'Upload' button near the 'Create' Button in the Kanban view then extend 'KanbanView.buttons'.

Example

<templates>


    <t t-extend="KanbanView.buttons" t-name="BillsKanbanView.buttons">


        <t t-jquery="button" t-operation="after">


            <button type="button" class="btn btn-secondary  on_upload"  


         name="upload_button">


                Upload


            </button>


        </t>


    </t>


</templates>


if you want to replace the Create button then set the 't-operation' value to 'replace'

<t t-jquery="button" t-operation="replace">

we can also specify the model by adding conditions like

<button t-if="widget.modelName == '<model_name>'">Upload</button>

After adding the button we can create a function in js,
by extending 'web.KanbanController' you can add an action for the newly created button

Example

odoo.define('example.uploadButton', function(require) {
var KanbanController = require('web.KanbanController');
var KanbanButton = KanbanController.extend({
buttons_template: '',
events: _.extend({}, KanbanController.prototype.events, {
'click .on_upload': '_onUpload',
},
_onUpload: function(){
// this function will execute the Button click
}
}

Regards

Avatar
Verwerfen

In order to add button in tree view, try the following:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-inherit="web.ListView.Buttons" t-inherit-mode="extension">
<xpath expr="//*[@class='btn btn-secondary fa fa-download o_list_export_xlsx']"
position="after">
<button type="button" class="btn btn-secondary o_list_new_button"
t-on-click="actionDef">New Button</button>
</xpath>
</t>
</templates>

hello,
I am stuck in opening a record from list view when target is new in js action. Can you explain this using example?