问题
I am trying to customise the calendar view of the calendar.event
model, whose code is:
<record id="view_calendar_event_calendar" model="ir.ui.view">
<field name="name">calendar.event.calendar</field>
<field name="model">calendar.event</field>
<field name="priority" eval="2"/>
<field name="arch" type="xml">
<calendar string="Meetings" date_start="start" date_stop="stop" date_delay="duration" all_day="allday"
display="[name]" color="color_partner_id" attendee="partner_ids" avatar_model="res.partner"
use_contacts="True" event_open_popup="%(calendar.view_calendar_event_form_popup)s">
<field name="name"/>
<field name="user_id"/>
<field name="color_partner_id"/>
<field name="partner_ids"/>
</calendar>
</field>
</record>
I want to show some new fields and make the background color depend on a new field named color_confirmed
. The perfect way would be to replace the kanban shown in the calendar view by a customised one. The Odoo documentation (https://www.odoo.com/documentation/11.0/reference/views.html#calendar) says the following:
templates
defines the QWeb template calendar-box. Cards definition may be split into multiple templates for clarity which will be rendered once for each record.
The kanban view uses mostly-standard javascript qweb and provides the following context variables:
...
I am trying to use that templates attribute, but I have no idea how, and I was not able to find an example in all the available modules I have downloaded. One of my attempts:
<record id="view_calendar_event_calendar" model="ir.ui.view">
<field name="name">calendar.event.calendar</field>
<field name="model">calendar.event</field>
<field name="inherit_id" ref="calendar.view_calendar_event_calendar"/>
<field name="arch" type="xml">
<xpath expr="//calendar[1]" position="replace">
<calendar string="Meetings" date_start="start" date_stop="stop" date_delay="duration"
all_day="allday" display="[color_confirmed]" color="color_confirmed" attendee="partner_ids"
avatar_model="res.partner" use_contacts="False" event_open_popup="%(calendar.view_calendar_event_form_popup)s" mode="month">
<field name="name"/>
<templates>
<t t-name="calendar-box">
<div class="oe_kanban_global_click">
<div class="oe_kanban_details">
<strong class="oe_partner_heading"><field name="name"/></strong>
<ul>
<li>TEST ITEM 1</li>
<li>TEST ITEM 2</li>
</ul>
</div>
</div>
</t>
</templates>
</calendar>
</xpath>
</field>
</record>
As expected, it throws a JS error. I have tried several ways and I am wasting a lot of time in such a single task. Does anyone have an idea of how this works? (or a better way to achieve my purpose).
回答1:
the js error should be because of the avatar_model
, use_contacts
, and attendee
in the calendar definition. because the calendar is not accepting those values.
if you remove those fields and add your code will work well. here I have rendered your calendar-box
template
Let me know if I am missing anything.
来源:https://stackoverflow.com/questions/59411841/how-to-display-your-own-kanban-card-in-calendar-view-in-odoo-11