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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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 !!!
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
3
thg 7 17
|
10574 | ||
|
1
thg 8 24
|
2115 | ||
Qweb if-else condition?
Đã xử lý
|
|
6
thg 5 24
|
110642 | |
|
0
thg 11 23
|
1478 | ||
|
0
thg 12 22
|
2648 |