Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
8363 Lượt xem

Hi,

      I been do some research on this site, but none works for me.

i am new to odoo 12. 

i am not that familiar with js as well.

Thank you for sharing you time to help.


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I find the solution to this problem! If you want to replace the create button if you use project.project model.

1) Create some js script (static/src/js/task_list.js) with click listener for the button :


openerp.project = function (instance){
    var QWeb = openerp.web.qweb;
    _t = instance.web._t;
    var self = this;
openerp.web.ListView.include({
    load_list: function(data) {
        this._super(data);
        if (this.$buttons) {
            this.$buttons.find('.oe_new_button').off().click(this.proxy('do_the_job')) ;
            console.log('Save & Close button method call...');
        }
    },
    do_the_job: function () {
        this.do_action({
            type: "ir.actions.act_window",
            name: "Создание нового проекта",
            res_model: "project.project",
            views: [[false,'form']],
            target: 'current',
            view_type : 'form',
            view_mode : 'form',
            flags: {'form': {'action_buttons': true, 'options': {'mode': 'edit'}}}
        });
        return {
                'type': 'ir.actions.client',
                'tag': 'reload',
        }
}
});
}


2) After that create static/src/xml/project_button.xml with the template, which replaces "Create" button if use project.project model



<?xml version="1.0" encoding="UTF-8"?>
<template id="template" xml:space="preserve">
    <t t-extend="ListView.buttons">
                <t t-jquery="button.oe_list_add" t-operation="replace">
                        <button t-if="widget.model == 'project.project'"  class="oe_button oe_new_button oe_highlight" type="button">Создать новый проект</button>
                        <button t-if="widget.model != 'project.project'" class="oe_button oe_list_add oe_highlight" type="button">Создать</button>
        </t>
    </t>
</template>


3) After that add my js script in web.asset_backend (Create file project/views/project.xml)


<?xml version="1.0" encoding="utf-8"?>
<!-- vim:fdn=3:
-->
<openerp>
    <data>
        <template id="assets_backend" name="project assets" inherit_id="web.assets_backend">
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/project/static/src/js/task_list.js"></script>
            </xpath>
        </template>
    </data>
</openerp>

4) And finally add in project/__openerp__.py section 'qweb' for static/src/xml/project_button.xml, 'js' for static/src/js/task_list.js and place file views/project.xml in 'data' section.


'data': [
        'security/project_security.xml',
         ...
        'views/project.xml',
    ],
    'qweb': ['static/src/xml/project_button.xml',],
    ...
    'js': 'static/src/js/task_list.js', 

And the button successful replace old button in project.project model.



Ảnh đại diện
Huỷ bỏ
Tác giả

It's seem the solution is in older odoo version.

Can you give me the solution in Odoo 12 up?

@pablo Escobar, You copied the answer from the reference link that I mentioned. What are you trying to prove here?

Câu trả lời hay nhất

I can give u a reference which described well, that how we can add a button in tree view header.

https://stackoverflow.com/questions/42694793/how-to-add-button-in-tree-view-header-near-create-and-import-buttons-odoo-8

Ảnh đại diện
Huỷ bỏ
Tác giả

HI Hilar,

Can you upgrade the solution to Odoo 12 up?

Am using the Odoo 12 and not familiar with openerp api in odoo 8

Thank you for you time.

I already mentioned this in answer, this is just a reference. You can follow the way they did.

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 10 19
3047
1
thg 4 24
12987
1
thg 10 19
6990
2
thg 6 22
2583
2
thg 9 20
5891