Skip to Content
मेन्यू
This question has been flagged
1 Reply
299 Views

I need to add the "location" field next to the name of the event afrter a "-" for every event that i want to insert.


I need to see it without clicking to the event info

Avatar
Discard
Author

Hi, i tried with your methods but it didn't work, i also started to work on the xml but i'm not being able to set the name of the event in the way i want to.

the name of the "location" previously mentioned is: "x_studio_stringa_mezzi" 

I want to display this to elements separated by a "-"

with the changes that i made i was able to change elements on the description of the event but not on the title.

I'm working on the 18 version of odoo and i'm trying to edit files (both py and xml) whit filezilla. 

 

Best Answer

Hii,

I don`t know which version you will use so here is code that can use to solve your error
Override get_event_title to return the combined string.


from odoo import models class CalendarEvent (models.Model): _inherit = 'calendar.event' # or your custom model def get_event_title ( self, meeting ): name = meeting.get( 'name' , '' ) location = meeting.get( 'location' , '' ) if location: return f" {name} - {location} " return name

This method is called by Odoo's JS calendar renderer to determine what to show in the calendar slot.

Ensure location is in the calendar view fields

Odoo Calendar fetches fields defined in the calendar view XML:

<field name = "calendar_view"> <calendar string = "Calendar" date_start = "start" date_stop = "stop" color = "user_id"> <field name = "name"/> <field name = "location"/> </calendar> </field>

Make sure location is included, or it won’t be available in meeting.get(...) during title formatting.


I hope it is use full

Avatar
Discard
Author

thanks but it didn't work, can you see the other comment to see if you can help me?

Model File
# your_module/models/calendar_event.py

from odoo import models

class CalendarEvent(models.Model):
_inherit = 'calendar.event'

def name_get(self):
res = []
for record in self:
name = record.name or ''
location = record.x_studio_stringa_mezzi or ''
display_name = f"{name} - {location}" if location else name
res.append((record.id, display_name))
return res
Ensure x_studio_stringa_mezzi is in the calendar view
<record id="calendar_event_view_calendar_inherit" model="ir.ui.view">
<field name="name">calendar.event.calendar.view.inherit</field>
<field name="model">calendar.event</field>
<field name="inherit_id" ref="calendar.view_calendar_event_calendar"/>
<field name="arch" type="xml">
<calendar string="Calendar" date_start="start" date_stop="stop" color="user_id">
<field name="x_studio_stringa_mezzi"/>
<field name="name"/>
</calendar>
</field>
</record>
try this code i hope it is use full