Skip to Content
Menu
This question has been flagged

I have a custom button near list view and opened the action from javascript with target:new and it worked when record is single as i have passed the id of the record and it opened the form view on button click but when there are multiple records, I have opened the tree view and displayed all records in case of multiple and clicked on record but doesn't opened the form view of the particular record.


here is my code:-


odoo.define('module_name.file_name', function (require) {
"use strict";
var ListController = require('web.ListController');
var ListView = require('web.ListView');
var viewRegistry = require('web.view_registry');
var rpc = require('web.rpc');
var test = [];
var count_doc = 0;
var TreeButton = ListController.extend({
   buttons_template: 'button_template.buttons',
   events: _.extend({}, ListController.prototype.events, {
   'click .button_class': '_OpenWizardAttendance',
  }),
  _OpenWizardAttendance: function () {
   var self = this;
   rpc.query({
        model: 'hr.attendance',
        method: 'get_attendance_id',
        args: [],
   }).then (function(res){
   alert(res)
   test = res['id'];
   count_doc = res['count']
   if (count_doc ==1){
   self.do_action({        //action for single record
       type: 'ir.actions.act_window',
       res_model: 'res.model.model',
       name :'Help',
       view_mode: 'form',
        view_type: 'form',
        views: [[false, 'form']],
       target: 'new',
       res_id: test,
   })
   }
   else{
    self.do_action({       //action for multiple records
        name: _("Help"),
        type: 'ir.actions.act_window',
        res_model: 'res.model.model',
        view_mode: 'form,tree',
        view_type: 'form',
        views: [[false, 'list'],[false, 'form']],
        target: 'new',
        domain: [],
    },{on_reverse_breadcrumb: function(){ return self.reload();}})
    }
   });
   }
  });
 var SaleOrderListView = ListView.extend({
   config: _.extend({}, ListView.prototype.config, {
       Controller: TreeButton,
 }),
});
 viewRegistry.add('button_in_tree', SaleOrderListView);
});

How can i open the particular record on click event? I have tried to pass current_target event but doesn't work for me. Also when i am passing target: current it opens the form view in that case.

Do am I missing something? Can anyone suggest me a path to solve this?

Avatar
Discard
Related Posts Replies Views Activity
0
Feb 24
1299
1
Dec 22
4168
0
Mar 24
1196
1
Feb 24
1887
2
Jan 24
2431