تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
6492 أدوات العرض

Hello All,

I'm added button on the timesheet list view and opened wizard on button click. For this, I'm called python in the js file and when I pass function value in do_action() method(for res_id) of js then it will open wizard in the second attempt, in the first attempt it open the new wizard. It means(this.do_action called before rpc.query) function calling late. The expected result should be rpc.query call before this.do_action. variable defined as 'test'.

My Python and Js code are here:

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 Code:

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

Also find screenshots below:


Thanks in advance

الصورة الرمزية
إهمال
أفضل إجابة


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


الصورة الرمزية
إهمال
الكاتب

Thanks Jiger.... It's working.

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
سبتمبر 23
7600
1
يناير 23
10822
0
يوليو 19
7725
1
مايو 25
4238
1
نوفمبر 22
1850