i defined a button on my qweb template and i want to put a condition based on view_id so it appears only on the view with the id that i gave
Denna fråga har flaggats
First off, you'll need to ensure you have access to the view_id in your QWeb context. This might require a bit of backend preparation, depending on how and where you're planning to use this template.
Once you have view_id at your disposal, you can use an t-if directive in your QWeb template to show or hide your button based on the condition. Assuming view_id is the magical number you want to check against, your button code would look something like this

The template is used to add a button that allow to show archives , it's like an activation button near to "new" button on the tree view , can you help me please how pass context from the backend to the template ?? here is my code
@api.model
def default_get(self, fields):
model_name = "bp.cdc"
view_name = 'cdc.tree'
view_id = self.env['ir.actions.act_window'].search([('model', '=', model_name)and('name','=',view_name)], limit=1).id
context = dict(self._context)
context.update({'default_view_id': view_id})
self = self.with_context(context)
return super(BpCdc, self).default_get(fields)
template : <templates xml:space="preserve">
<t t-name="cdcArchivesCdc.Buttons" t-inherit="web.ListView.Buttons" t-inherit-mode="extension">
<xpath expr="//div[hasclass('o_list_buttons')]" position="inside">
<button class="btn btn-secondary" type="button" t-on-click="display_archives"
t-if="view_id == 'view_cdc_tree'" id="display_archives_button">
Archives
</button>
</xpath>
</t>
js :
/** @odoo-module **/
import { ListController } from '@web/views/list/list_controller';
import { patch } from '@web/core/utils/patch';
import { useService } from '@web/core/utils/hooks';
let isChecked = false;
patch(ListController.prototype,{
setup() {
super.setup(...arguments);
this._action = useService("action");
this.isChecked = isChecked;
},
display_archives() {
isChecked = !isChecked;
this.isChecked = isChecked;
if (this.isChecked == true){
this._action.doAction({
type: "ir.actions.act_window",
name: "Cahiers des charges archivés",
domain: [["jours_restants", "=", 0]],
views: [[1927, "list"], [false, "form"]],
res_model: "bp.cdc",
target: 'self',
view_mode: "list,form"
});
}else if(this.isChecked == false){
this._action.doAction({
type: "ir.actions.act_window",
name: "Cahiers des charges en cours",
domain: [["jours_restants", "!=", 0]],
views: [[1927, "list"], [false, "form"]],
res_model: "bp.cdc",
target: 'self',
view_mode: "list,form"
});
}
}
});
btw i wanted to change the style of the button to btn-primary when its clicked and i didnt know how
any help to get acces to the view_id in the qweb contaxt , i didnt know how to prepare it in the backend !!!
any help to get acces to the view_id in the qweb contaxt , i didnt know how to prepare it in the backend !!!
Njuter du av diskussionen? Läs inte bara, delta också!
Skapa ett konto idag för att ta del av exklusiva funktioner och engagera dig i vår fantastiska community!
Registrera dig| Relaterade inlägg | Svar | Vyer | Verksamhet | |
|---|---|---|---|---|
|
|
3
juli 17
|
12736 | ||
|
|
1
aug. 24
|
5012 | ||
|
|
6
maj 24
|
115599 | ||
|
|
0
nov. 23
|
3798 | ||
|
|
0
dec. 22
|
4337 |