1

我制作了这个 JS 来在表单(后端)上添加一个功能,该功能在触发事件点击时计算一个字段。到目前为止,当我使用“.include”时代码会重新计算,但所有视图中的整个 JS 都失败了,因为我使用的是“.include”。当我尝试使用扩展时,我的代码什么也不做。看起来 Odoo 没有将扩展代码添加到 JS 引擎所以我的问题是,我在这里做错了什么?还有什么我需要添加的,所以我的代码可以扩展吗?

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 .sign_selector': '_onSignSelectorClicked',
    }),
    init: function (parent, state, params) {
        this._super.apply(this, arguments);
        this.fields = state.fields;
        this._onSignSelectorClicked = _.debounce(this._onSignSelectorClicked, 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);
            });
        }
    },
    _onSignSelectorClicked: function (event) {
       this.state.data.telephone = '333';
       if (this.state.model == 'med.test') {
           var info_test = {
               dataPointID: this.state.id,
               changes: {telephone: '333'},
               viewType: "form",
               notifyChange: true
           };
           var odoo_event = this.trigger_up('field_changed', info_test);
           this.confirmChange(this.state, this.state.id, "telephone",          
           odoo_event)
        }
    },
});
var TestFormView = FormView.extend({
    config: _.extend({}, FormView.prototype.config, {
        Renderer: TestFormRenderer,
    }),
});
viewRegistry.add('test_form', TestFormView);
return TestFormView;
});
4

0 回答 0