Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
5690 Widoki

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

            }

        });

    },

});


});

Awatar
Odrzuć
Najlepsza odpowiedź

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'>
Awatar
Odrzuć

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.

Powiązane posty Odpowiedzi Widoki Czynność
1
maj 23
7216
1
lip 16
4066
1
cze 23
3000
0
sty 21
2806
2
gru 19
8503