Skip to Content
Menu
This question has been flagged
2 Replies
3970 Views

Hello, I made this JS to add a functionality on a form (backend) that computes a field when the event click is triggered. So far the code recomputes when I use .include but the whole js in all views fails since I'm using .include. When i try to use extend, looks like Odoo  doesn't add the extended code to the js engine so my question is, what am I doing wrong here? Is there something else i need to add so my code as extended works?

PD. Somehow I can't add tags to this question



odoo.define('med_care.TestRenderer', function (require) {
"use strict";

var viewRegistry = require('web.view_registry');
var FormRenderer = require('web.FormRenderer');
var FormView = require('web.FormView');

   var TestFormRenderer = FormRenderer.extend({
events: _.extend({}, FormRenderer.prototype.events, {
'click .selector_simbolo': '_onSelectorSimboloClicked',
}),
init: function (parent, state, params) {
this._super.apply(this, arguments);
this.fields = state.fields;
this._onSelectorSimboloClicked = _.debounce(this._onSelectorSimboloClicked, 300, true);
},
confirmChange: function (state, id, fields, e) {
var self = this;
if (state.model == 'med.test') {
return this._super.apply(this, arguments).then(function () {
self.canBeSaved(self.state.id);
});
}
},
_onSelectorSimboloClicked: function (event) {
           this.state.data.telefono = '333';
           if (this.state.model == 'med.test') {
               var info_test = {
                   dataPointID: this.state.id,
changes: {telefono: '333'},
viewType: "form",
notifyChange: true
               };
               var odoo_event = this.trigger_up('field_changed', info_test);
this.confirmChange(this.state, this.state.id, "telefono",
odoo_event)
            }
},
});
    var TestFormView = FormView.extend({
config: _.extend({}, FormView.prototype.config, {
Renderer: TestFormRenderer,
}),
});
    viewRegistry.add('test_form', TestFormView);
return TestFormView;
});
Avatar
Discard
Author Best Answer

Already discovered how. I just needed to add a JS file with a FormView extension and place the name of the registry in the form>js_class in the XML

Avatar
Discard
Best Answer

Hello Andres Lincango,


Here you need to return "FormRenderer" variable at the end instead of the "FormView" variable


odoo.define('med_care.TestRenderer', function (require) {

"use strict";


    var viewRegistry = require('web.view_registry');

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

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


    var TestFormRenderer = FormRenderer.extend({

        events: _.extend({}, FormRenderer.prototype.events, {

            'click .selector_simbolo': '_onSelectorSimboloClicked',

        }),

        init: function (parent, state, params) {

            this._super.apply(this, arguments);

            this.fields = state.fields;

            this._onSelectorSimboloClicked = _.debounce(this._onSelectorSimboloClicked, 300, true);

        },

        confirmChange: function (state, id, fields, e) {

            var self = this;

            if (state.model == 'med.test') {

                return this._super.apply(this, arguments).then(function () {

                    self.canBeSaved(self.state.id);

                });

            }

        },

        _onSelectorSimboloClicked: function (event) {

           this.state.data.telefono = '333';

           if (this.state.model == 'med.test') {

               var info_test = {

                   dataPointID: this.state.id,

                   changes: {telefono: '333'},

                   viewType: "form",

                   notifyChange: true

               };

               var odoo_event = this.trigger_up('field_changed', info_test);

               this.confirmChange(this.state, this.state.id, "telefono",          

               odoo_event)

            }

        },

    });

    var TestFormView = FormView.extend({

        config: _.extend({}, FormView.prototype.config, {

            Renderer: TestFormRenderer,

        }),

    });

    

    viewRegistry.add('test_form', TestFormView);

    

    return {

    Renderer: BaseSettingRenderer,

};

});


For more detail reference you need to look out this js file in odoo v11E addons -> addons/base/static/src/js/res_config_settings.js

Regards,




Email:   odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

Avatar
Discard