Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
2741 Tampilan

I have been following the Odoo Tutorial, specifically... 

www.odoo.com/documentation/16.0/developer/tutorials/master_odoo_web_framework/03_custom_kanban_view.html

At stage 4 some code is provided to programatically, through javascript, set a filter.

selectCustomer(customer_id, customer_name) {
   this.env.searchModel.setDomainParts({
      customer: {
            domain: [["customer_id", "=", customer_id]],
            facetLabel: customer_name,
      },
   });
}

Is it possible to also fold a specific stage in the kanban view, programatically, through javascript?

Many Thanks,

Simon



Avatar
Buang
Penulis Jawaban Terbai

Thanks for the prompt answer.

Unfortunately, I don't have enough Karma to provide a comment, only to provide an answer. But, this is actually a comment.

Using what you have provided I have managed to invoke the python from the javascript. However, I have a few problems:

1. I had to add @api.model to precede the def model_method so that the self variable was auto added.

@api_model 
def model_method(self, stage_id):
​​self.env['stage.model'].browse(stage_id).fold = True

2. I am unclear what I should put as stage_id in the javascript, is this a number or name of the stage?

rpc.query({
​model: 'model.name',
​method: 'model_method',
​args: [[stage_id]],
})

3. I don't have a 'stage.model' in my self.env. The kanban is grouped by a field.selection called status, which has a number of values ('new', 'pending', 'in_progress') so how do I reference this field and what would the stage_id be?

def model_method(self, stage_id):
​self.env['stage.model'].browse(stage_id).fold = True

Many Thanks,

Simon



Avatar
Buang
Jawaban Terbai

Hi,

Basically, folding a kanban stage depends upon the fold field in the stage model.

So you just have to enable that field from Js. 

You can use rpc.query or ajax.jsonRpc to call python functions or routes respectively and change the boolean field to True, which folds the Kanban stage (You can pass the stage id as argument).

eg:

var rpc = require('web.rpc');

function fun_name() {
rpc.query({
model: 'model.name',
method: 'model_method',
args: [[stage_id]],
})
}

python

def model_method(self, stage_id):
self.env['stage.model'].browse(stage_id).fold = True

Regards

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
2
Jul 23
2773
1
Apr 24
2131
0
Jan 24
1701
1
Sep 23
3135
2
Apr 23
5310