콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
5733 화면

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

            }

        });

    },

});


});

아바타
취소
베스트 답변

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'>
아바타
취소

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.

관련 게시물 답글 화면 활동
1
5월 23
7224
1
7월 16
4085
1
6월 23
3013
0
1월 21
2821
2
12월 19
8517