コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
2763 ビュー

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



アバター
破棄
著作者 最善の回答

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



アバター
破棄
最善の回答

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

アバター
破棄
関連投稿 返信 ビュー 活動
2
7月 23
2788
1
4月 24
2148
0
1月 24
1720
1
9月 23
3164
2
4月 23
5341