spacebiker
spacebiker

Reputation: 3875

Odoo v12 Many2many Fields in calendar view

I can succesfully display many2many fields in the form view:

enter image description here

but when I try to display it in the calendar view I get "No Records" or "X records" but not the field content.

enter image description here

This is the field in my model:

user_ids = fields.Many2many('res.users', 'events_user_rel', 'user_id', 'id', string='Event users', select= True, track_visibility='onchange')

this is the code in the view:

<record id="view_calendar" model="ir.ui.view">
    <field name="name">my.calendar</field>
    <field name="model">my.model</field>
    <field name="inherit_id" ref="my.view_calendar"/>
    <field eval="2" name="priority"/>
    <field name="arch" type="xml">
        <xpath expr="//calendar" position="replace">
          <calendar color="event_id" date_start="date_start" date_stop="date_end" string="Events" all_day="date_start" mode="month">
            <field name="user_ids"/>
          </calendar>
        </xpath>
    </field>
</record>

What should I do to get the values "Joel Willis, etc.." in the calendar view

Upvotes: 0

Views: 1229

Answers (2)

Adan Cortes
Adan Cortes

Reputation: 1068

If instead of having a many-to-many relationship with res.users you define a relationship to res.partner you may use the many2manyattendee widget

<field name="partner_ids" widget="many2manyattendee"/>

Just be aware that this widget is designed to work with res.partner only.

See <path_to_v12>/addons/calendar/static/src/js/base_calendar.js and <path_to_v12>/addons/calendar/static/tests/calendar_tests.js

Upvotes: 1

Adan Cortes
Adan Cortes

Reputation: 1068

Try <field name="user_ids" write_model="res.users" write_field="name"/>.

See an example at <path_to_v12>/addons/calendar/views/calendar_views.xml lines 266-281. Those parameters are used at <path_to_v12>/addons/web/static/src/js/views/calendar/calendar_view.js lines 63-94.

Upvotes: 1

Related Questions