跳至內容
選單
此問題已被標幟
2 回覆
304 瀏覽次數

Hello,

I am trying to display the database ID of each record on the Kanban view for projects. To start, I just want to test modifying the Kanban view by adding a simple visual element.

Here is the XML I am using:

<odoo> <template id="project_task_kanban_inherit" inherit_id="project.view_task_kanban"> <xpath expr="//div[contains(@class,'o_kanban_record')]" position="inside"> <div style="width: 100%; height: 50px; background-color: black;"></div> </xpath> </template> </odoo>

This should display a black box on every record in the Kanban view. However, nothing is being displayed.

Could anyone please point out what I might be doing wrong?

Thank you in advance for your help!



UPDATE: See my answer in the comments for a solution

頭像
捨棄
最佳答案

Hi,

Please refer to the code:

<odoo>

    <template id="project_task_kanban_inherit" inherit_id="project.view_task_kanban">

        <xpath expr="//div[contains(@class,'o_kanban_content')]" position="inside">

            <div style="width: 100%; height: 50px; background-color: black;">

                <!-- Optional: Display record ID -->

                <t t-esc="record.id"/>

            </div>

        </xpath>

    </template>

</odoo>


Hope it helps.

頭像
捨棄
作者

Element '<xpath expr="//div[contains(@class,&#39;o_kanban_content&#39;)]">' cannot be located in parent view

I get this error

作者 最佳答案

I have found the solution:

<odoo>
<template id="project_task_kanban_inherit" inherit_id="project.view_task_kanban">
<xpath expr="//div[contains(@class,'o_kanban_record')]" position="inside">
<div style="background-color: #222; color: #fff; padding: 5px; margin-bottom: 5px;">
<div style="background-color: black; color: white; padding: 5px;">
Task ID: <field name="x_task_id"/>
</div>
</div>
</xpath>
</template>
</odoo>

class ProjectTask(models.Model):
_inherit = "project.task"

x_task_id = fields.Integer(string="Task ID", store=True)

@api.model_create_multi
def create(self, vals_list):
tasks = super().create(vals_list)
for task in tasks:
task.x_task_id = task.id
return tasks

You cannot access the ID because the BaseView does not include it. So in order to access it you have to create your own field and then display that. There is probably a way better way to do this. 
Also sidenote: already created tasks will not have x_task_id populated. Only new tasks. 
Im sure there is a way to actually populate already existing tasks fields with values. 

Also for some unknown reason this would not display anything before i explicitly set 'Model of the View' under Technical -> Views -> this view to 'Task'

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
3月 15
10483
0
2月 16
5430
1
5月 23
4488
1
9月 21
8523
1
11月 19
9939