【问题标题】:Python function rpc method called late than do_action() in js file Odoo 11Python函数rpc方法调用晚于js文件Odoo 11中的do_action()
【发布时间】:2019-11-24 02:57:57
【问题描述】:

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

我的 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);
});

还可以在下面找到屏幕截图:

提前致谢

【问题讨论】:

    标签: javascript odoo rpc odoo-11


    【解决方案1】:

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

    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();}
                    }
                )
            });
    
        },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多