Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
300 Weergaven

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

Avatar
Annuleer
Beste antwoord

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.

Avatar
Annuleer
Auteur

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

I get this error

Auteur Beste antwoord

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'

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
mrt. 15
10482
0
feb. 16
5430
1
mei 23
4483
1
sep. 21
8509
1
nov. 19
9938