İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
139 Görünümler

Hi,


I have a question about how to manage a project requirement:


A client uses the projects module in Odoo 16 with tasks and subtasks. They asked me as a requirement that, in the task kanban, when clicking on a task that has subtasks, instead of opening the form with the task data, a Kanban with the subtasks of the parent task should reopen.


I understand that this requirement must be implemented with Owl, but I can't get it to work. In fact, I can't inherit the Kanban view from the tasks and change the on-click behavior to change the functionality. Do you have any examples of how to inherit a Kanban and change the on-click using Owl?


Thank you


Best regards.

Avatar
Vazgeç
En İyi Yanıt

Here,

Create a JS File : project_task_kanban_patch.js

/** @odoo -module **/ import { patch } from "@web/core/utils/patch" ; import { KanbanRecord } from "@web/views/kanban/kanban_record/kanban_record" ; import { useService } from "@web/core/utils/hooks" ; patch ( KanbanRecord . prototype , { setup ( ) { super . setup (); this . action = useService ( "action" ); }, async onRecordClick ( ev ) { const record = this . props . record . data ; // If task has subtasks, open them in Kanban if ( this . props . record . model === "project.task" && record. child_ids . length > 0 ) { house. preventDefault (); await this . action . doAction ({ type : "ir.actions.act_window" , name : `Subtasks of ${record.name} `, res_model : "project.task" , view_mode : "kanban,form" , domain : [[ "id" , "in" , record. child_ids ]], context : { default_parent_id : record. id }, target : "current" , }); return ; } // Otherwise, use default behavior await super . onRecordClick (home); }, });

Include in Manifest

In your __manifest__.py :

"assets" : { "web.assets_backend" : [ "your_module/static/src/js/project_task_kanban_patch.js" , ], },

Ensure child_ids is in the Kanban view

Add this in XML:

<record id = "project.task.kanban.view.inherit" model="ir.ui.view"> <field name = "model" >project.task </field> <field name = "inherit_id" ref ="project.view_task_kanban"/> <field name = "arch" type = "xml"> <field name = "name" position = "before"> <field name = "child_ids"/> </field> </field> </record>

i hope it is usefull

Avatar
Vazgeç
En İyi Yanıt

Hello Santiago Carbonell Forment,


You cannot inherit the KanbanRecord template directly because it is an OWL template.

This means you cannot inherit it using a regular: <odoo><template inherit_id="..."></template></odoo> since that only works for backend QWeb views.


✅ Instead, you can either directly replace the template or patch the existing onClick function.


I’ve attached the code which directly opens the Kanban view of Subtasks, you just have change the module name.


```import { patch } from '@web/core/utils/patch';

import { KanbanRecord } from '@web/views/kanban/kanban_record';


export const CANCEL_GLOBAL_CLICK = ["a", ".dropdown", ".oe_kanban_action", "[data-bs-toggle]"].join(

    ","

);

patch(KanbanRecord.prototype, 'my_module.KanbanRecord', {

        onGlobalClick(ev) {

            const { archInfo, forceGlobalClick, openRecord, record } = this.props;

            console.log("Called", record.data)

            if (record.data.child_text != false) {

                this.env.services.action.doAction({

                    type: 'ir.actions.act_window',

                    name: 'Subtasks',

                    res_model: 'project.task',

                    domain: [['parent_id', '=', record.resId]],

                    view_mode: 'kanban',

                    views: [[false, 'kanban']],

                    target: 'current',

                });

            }

            else {

                if (ev.target.closest(CANCEL_GLOBAL_CLICK)) {

                    return;

                }

                if (!forceGlobalClick && archInfo.openAction) {

                    this.action.doActionButton({

                        name: archInfo.openAction.action,

                        type: archInfo.openAction.type,

                        resModel: record.resModel,

                        resId: record.resId,

                        resIds: record.resIds,

                        context: record.context,

                        onClose: async () => {

                            await record.model.root.load();

                            record.model.notify();

                        },

                    });

                } else if (forceGlobalClick || this.allowGlobalClick) {

                    openRecord(record);

                }

            }

        },


}); ```

⚠️ Please note: this code is only for reference purposes.

If you patch the onClick method, it will change the behavior across all kanban views in Odoo, so you need to handle it carefully and test every case where a kanban view is used.


❓ If you implement this then how user will open the parent task?

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Mar 24
1474
0
Eki 22
1784
3
May 25
3216
3
Eki 23
4940
5
Mar 25
2693