跳至内容
菜单
此问题已终结
1 回复
5561 查看

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
7047
1
7月 16
3944
1
6月 23
2855
0
1月 21
2633
2
12月 19
8339