Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
2727 Vizualizări

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



Imagine profil
Abandonează
Autor Cel mai bun răspuns

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



Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
2
iul. 23
2763
1
apr. 24
2125
0
ian. 24
1700
1
sept. 23
3129
2
apr. 23
5305