Python 函数 rpc 方法调用晚于 js 文件 Odoo 11 中的 do_action()

Python function rpc method called late than do_action() in js file Odoo 11

我在时间表列表视图中添加了按钮,并在单击按钮时打开了向导。为此,我在 js 文件中调用 python,当我在 js 的 do_action() 方法(对于 res_id)中传递函数值时,它将在第二次尝试中打开向导, 在第一次尝试时它会打开新向导。这意味着(this.do_action 在 rpc.query 之前调用)函数调用晚了。预期结果应该是 rpc.query 在 this.do_action 之前调用。定义为 'test'.

的变量

我的Python和Js代码在这里:

class TimesheetHelpButton(models.Model):
    _name = 'timesheet.help'
    _description = 'Timesheet Help Button'

    @api.model
    def get_timesheet_help_document(self):
        uid = request.session.uid
        #timesheet_document_view_id = self.env['document.document'].sudo().search([])
        data = {
            'uid': uid,
            'timesheet_document_view_id': 4,
        }
        return data

Js代码:

odoo.define('custom_project.web_export_view', function (require) {

"use strict";       
var core = require('web.core');
var ListView = require('web.ListView'); 
var ListController = require("web.ListController");
var rpc = require('web.rpc');
var test = 0;

var includeDict = {

    renderButtons: function () {
        this._super.apply(this, arguments);
        if (this.modelName === "account.analytic.line") {
            var your_btn = this.$buttons.find('button.o_button_help')
            your_btn.on('click', this.proxy('o_button_help'))
        }
    },
    o_button_help: function(){
        var self = this;
        event.stopPropagation();
        event.preventDefault();
        rpc.query({
            model: 'timesheet.help',
            method: 'get_timesheet_help_document',
            args: [],
        }).then(function (res) {
                    test = res['timesheet_document_view_id'];
                    }).done(function(){
            });
        setTimeout(myfonction, 5000);
        function myfonction() {}
        this.do_action({
            name: ("Help"),
            type: 'ir.actions.act_window',
            res_model: 'document.document',
            view_mode: 'form,tree,kanban',
            view_type: 'form',
            views: [[false, 'form'],[false, 'list'],[false, 'kanban']],
            target: 'new',
            res_id: test,
        },{on_reverse_breadcrumb: function(){ return self.reload();}})
    },

};
ListController.include(includeDict);
});

另请参阅以下屏幕截图:

提前致谢

你能试试这样写你的函数吗

o_button_help: function(){
        var self = this;
        event.stopPropagation();
        event.preventDefault();
        rpc.query({
            model: 'timesheet.help',
            method: 'get_timesheet_help_document',
            args: [],
        }).then(function (res) {
            test = res['timesheet_document_view_id'];
            self.do_action(
                {
                    name: ("Help"),
                    type: 'ir.actions.act_window',
                    res_model: 'document.document',
                    view_mode: 'form,tree,kanban',
                    view_type: 'form',
                    views: [[false, 'form'],[false, 'list'],[false, 'kanban']],
                    target: 'new',
                    res_id: test,
                },
                {
                    on_reverse_breadcrumb: function(){ return self.reload();}
                }
            )
        });

    },