Search code examples
odoo-10

odoo 10 Many2many field in calendar view


I created a many2many field in odoo, but when I view it in the calendar view it displays the id but I want display name.

enter image description here

The field definition is:

doctor = fields.Many2many('crm.account.doctor.line',
                          'crm_account_doctor_name',
                          'doctor_name','id', required=True)

The XML:

<record id="doctor_calender" model="ir.ui.view"> 
  <field name="model">plan.new</field> 
  <field name="arch" type="xml"> 
    <calendar color="state" date_start="date" mode="month" quick_add="False" > 
      <field name="doctor" write_model="crm.account.doctor.line" write_field="doctor" avatar_model="crm.account.doctor.line"/> 
    </calendar> 
  </field>
</record>

Solution

  • I don't know of a good way to do what you're asking for. What I would do is define a computed field with the display string you're looking for and use that in the view.

    display_doctor = fields.Char(string='Display String for doctor field',
                                 compute='_compute_display_doctor')
    
    def _compute_display_doctor(self):
       '''
       Compute the display string for the doctor field
       '''
       for record in self:
         display_str = ','.join(record.doctor.mapped('name'))
         record.display_doctor = display_str
    

    Then in the xml you can use that field instead of the many2many version.