簡體   English   中英

在js文件Odoo 11中比do_action()晚調用的Python函數rpc方法

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

我在時間表列表視圖中添加了按鈕,並在單擊按鈕時打開了向導。 為此,我在js文件中稱為python,當我在js的do_action()方法(用於res_id)中傳遞函數值時,它將在第二次嘗試中打開向導,在第一次嘗試中它將打開新向導。 這意味着(在rpc.query之前調用this.do_action)函數調用較晚。 預期結果應該是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);
});

也可以在下面找到屏幕截圖: 在此處輸入圖片說明 在此處輸入圖片說明

提前致謝

你可以嘗試這樣寫你的函數嗎

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

    },

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM