Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
7568 Tampilan
                    

Hello,


Currently we’re having issues with Odoo v15 (previous versions 14, 13 and 12 are unaffected) in a plugin we have developed inhouse. Here’s how the button appears on odoo 14 (labeled INS):

We are aware that there’s changes in Odoo 15 compared to previous versions and we followed the official documentation and some examples from the Odoo 15 source code. Sadly, neither of them function properly, the button does not render at all in the view and we can’t even get access to the functions.


Here’s the view code as we implemented it in odoo 15:

XML:


JavaScript:

odoo.define('hr.ExportReportListView', function (require) {
    "use strict";
    var ListView = require('web.ListView');
    var ListController = require('web.ListController');
    var viewRegistry = require('web.view_registry');
    var core = require('web.core');
    var qweb = core.qweb;
    var HrExportReportListController = ListController.extend({
        buttons_template: 'HrExportReport.Buttons',
           renderButtons: function ($node) {
            this._super.apply(this, arguments);
            this.$buttons = $(qweb.render('HrExportReport.Buttons'));
            this.$buttons.on('click', '.oe_export_ins', this._onExportTxt.bind(this));
        },
        _onExportTxt: function () {
            var self = this;
            return rpc.query({
                model: 'export_ins',
                method: 'odoo_button_click'
            }, {
                shadow: true
            }).then(function (res) {
                return self.do_action(res)
            });
        }
    });
    var HrExportReportListView = ListView.extend({
        config: _.extend({}, ListView.prototype.config, {
            Controller: HrExportReportListController,
        }),
    });
    viewRegistry.add('hr_export_report_list', HrExportReportListView);
    return HrExportReportListView;
});

__manifest__.py:

"assets": {
        "web.assets_backend": [
            "/hr_employee_report_ins_rt_cr/static/src/js/hr_export_ins.js",
        ],
        "web.assets_qweb": [
            "/hr_employee_report_ins_rt_cr/views/hr_views.xml",
        ]
    },
Is there something we’re missing in the implementation of this code?
Avatar
Buang
Jawaban Terbai

Hello Marco Duran,

I understand your question and yes the code is changed in V15.

I tried adding a button on sale order list view and I could achive it using below code.

Js file code:

function ccButton() {
if (this.$buttons) {
var self = this;
this.$buttons.on('click', '.o_button_custom', function () {
self.do_action({
name: 'Generate Leads',
type: 'ir.actions.act_window',
res_model: 'sale.order',
target: 'new',
views: [[false, 'form']],
});
});
}
}


var cListController = ListController.extend({
willStart: function() {
var self = this;
// var ready = self.buttons_template = 'CustListView.buttons';
var ready = this.getSession().user_has_group('sales_team.group_sale_manager')
.then(function (is_sale_manager) {
if (is_sale_manager) {
self.buttons_template = 'CustListView.buttons';
}
});
return Promise.all([this._super.apply(this, arguments), ready]);
},
renderButtons: function () {
this._super.apply(this, arguments);
ccButton.apply(this, arguments);
}
});


var CustListView = ListView.extend({
config: _.extend({}, ListView.prototype.config, {
Controller: cListController,
}),
});

viewRegistry.add('cust_tree', CustListView);

Xml file code :

sale.order.tree
sale.order

primary


cust_tree




Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Buang

Xml file code :

<field name="name">sale.order.tree</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_quotation_tree_with_onboarding"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//tree" position="attributes">
<attribute name="js_class">cust_tree</attribute>
</xpath>
</field>
</record>
</odoo>

Penulis Jawaban Terbai

Hello Jainesh Shah, thank you for the reply.

Checking your answer, we still could not render the button on the page. We found out that part of the problem with the render is a tag named t-name. With this tag, the button would not render:


t t-extend="ListView.buttons" t-name="HrExportListView.buttons"
    t t-jquery="button.o_list_export_xlsx" t-operation="after"
        button type="button" class="oe_export_ins">INS    /t
/t

But without it, it does:

t t-extend="ListView.buttons"
    t t-jquery="button.o_list_export_xlsx" t-operation="after"
        button type="button" class="oe_export_ins">INS    /t
/t


https://pastebin.com/NA8kMxDR

Although the button is being rendered, there’s no reaction when you click it. The Javascript is instantiated in the DOM but the content does not work properly.

In the Javascript, when we print the ListController and ListView instances, the console print out the following message:

ƒ Class(){
    if(this.constructor!==OdooClass){
        throw new Error("You can only instantiate objects with the 'new' operator");
    }
    this._super=null;
    if(!initializing&&this.init){
        var ret=this.init.apply(this,arguments);
        if(ret){
            return ret;
        }
    }
    return this;
}

We tried checking everything but no success. Anyone know why this happens and where could be the problem with my implementation? The Odoo version we are using is 15.0-20220110 (Community Edition).

Avatar
Buang
Penulis

Update

Solution I found:

```
odoo.define('export_ins.print_ins', function (require) {
"use strict";

var ListController = require('web.ListController');
var rpc = require('web.rpc');

ListController.include({
renderButtons: function ($node) {
this._super.apply(this, arguments);
if (this.$buttons) {
this.$buttons.find('.oe_export_ins').click(this.proxy('action_def'));
}
},
action_def: function () {
console.log('click export');
var self = this;
return rpc.query({
model: 'export_ins',
method: 'odoo_button_click'
}, {
shadow: true
}).then(function (res) {
return self.do_action(res)
});
}
});
});
```

```
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_export_xlsx" t-operation="after">
<button t-if="widget.modelName == 'hr.employee'" type="button" class="btn btn-secondary oe_export_ins">INS Report</button>
</t>
</t>
</templates>
```

Post Terkait Replies Tampilan Aktivitas
1
Des 22
3996
0
Feb 23
2331
1
Nov 22
2388
1
Agu 22
6376
0
Jul 20
2961