跳至内容
菜单
此问题已终结
2 回复
2730 查看

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
2766
1
4月 24
2126
0
1月 24
1700
1
9月 23
3131
2
4月 23
5306