Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
298 Представления

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'

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
мар. 15
10482
0
февр. 16
5430
1
мая 23
4481
1
сент. 21
8509
1
нояб. 19
9938