对于特定模型,如何始终在编辑模式下打开表单

How can i open a form always in Edit mode , for a particular model

我有一个模型说 'my.attendance' ,还有一个包含一些出席人数的表单视图 details.What 我需要的是当我打开这个表单视图时它应该总是在编辑中打开 mode.So 我可以直接输入考勤,不用每次都点击编辑按钮。

您必须扩展 ViewManager 才能实现此目的。

odoo.define('my_module.view_manager', function (require) {
"use strict";

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

ViewManager.include({

    custom_events: {

        execute_action: function(event) {
            var data = event.data;
            this.do_execute_action(data.action_data, data.env, data.on_closed)
                .then(data.on_success, data.on_fail);
        },
        search: function(event) {
            var d = event.data;
            _.extend(this.env, this._process_search_data(d.domains, d.contexts, d.groupbys));
            this.active_view.controller.reload(_.extend({offset: 0}, this.env));
        },
        switch_view: function(event) {
            if ('res_id' in event.data) {
                this.env.currentId = event.data.res_id;
            }
            var options = {};
            console.log(event.data)
            if (event.data.view_type === 'form' && !this.env.currentId) {
                options.mode = 'edit';
            } else if (event.data.mode) {
                options.mode = event.data.mode;
            }

            // Extra added code
            if (event.data.model){    
                if (event.data.model == 'my.model'){  // Checking the particular model.
                    options.mode = 'edit';
                }
            }


            this.switch_mode(event.data.view_type, options);
        },
        env_updated: function(event) {
            _.extend(this.env, event.data);
        },
        push_state: function(event) {
            this.do_push_state(event.data);
        },
        get_controller_context: '_onGetControllerContext',
        switch_to_previous_view: '_onSwitchToPreviousView',
    },

 });
});