İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
5676 Görünümler

I want to add my custom code inside SectionAndNoteListRenderer 
But its not working. In console.log its saying Undefined.

odoo.define('pack_so_product.pack_so_product_widget', function (require) {

"use strict";


var SectionAndNoteListRenderer = require('account.section_and_note_backend');

var core = require('web.core');


var _t = core._t;

var QWeb = core.qweb;


console.log(SectionAndNoteListRenderer);


SectionAndNoteListRenderer.include({

    

    _onAddRecord: function (ev) {

        // we don't want the browser to navigate to a the # url

        ev.preventDefault();


        // we don't want the click to cause other effects, such as unselecting

        // the row that we are creating, because it counts as a click on a tr

        ev.stopPropagation();


        // but we do want to unselect current row

        var self = this;

        this._super.apply(this, arguments);

        this.unselectRow().then(function () {

            var context = ev.currentTarget.dataset.context;

            if (context && pyUtils.py_eval(context).open_package_product){

                self._rpc({

                    model: 'ir.model.data',

                    method: 'xmlid_to_res_id',

                    kwargs: {xmlid: 'pack_so_product.sale_product_package_view_form'},

                }).then(function (res_id) {

                    self.do_action({

                        name: _t('Add a package'),

                        type: 'ir.actions.act_window',

                        res_model: 'sale.package.product',

                        views: [[res_id, 'form']],

                        target: 'new',

                        context: {

                            'open_package_product': true

                        }

                    });

                });

            } else {

                self.trigger_up('add_record', {context: context && [context]}); // TODO write a test, the deferred was not considered

            }

        });

    },

});


});

Avatar
Vazgeç
En İyi Yanıt

The module account/static/src/js/section_and_note_fields_backend.js does not return the created widgets. 

Therefore, you cannot use "include" or "extend" to override the widget code.
This is an annoying error in the code, 
which would be worth writing a request to github.com/odoo/odoo/issues,
because most js modules return created widgets, 
but in this module they apparently forgot to insert


return {
    SectionAndNoteListRenderer: SectionAndNoteListRenderer,
    SectionAndNoteFieldOne2Many: SectionAndNoteFieldOne2Many,
    SectionAndNoteFieldText: SectionAndNoteFieldText,
};
I have the same problem, but I do not know how to get around this problem.
You can try creating your own widget based on an existing one like this:
var SectionAndNoteFieldOne2Many = fieldRegistry.get('section_and_note_one2many');
fieldRegistry.add('my_section_and_note_one2many', SectionAndNoteFieldOne2Many.extend({
myCode: function () {
// insert your core here
},
}));
and then insert in my_views.XML <field my_field widget='my_section_and_note_one2many'>
Avatar
Vazgeç

Excellent! Your answer was extremely helpful to me in resolving this issue. Thanks!

I am pleased to hear that.

I implemented adding kits based on this.

If interesting, then I can post my code.

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
May 23
7209
1
Tem 16
4064
1
Haz 23
2998
0
Oca 21
2804
2
Ara 19
8499