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

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
يوليو 23
2780
1
أبريل 24
2137
0
يناير 24
1705
1
سبتمبر 23
3148
2
أبريل 23
5317