Calendar views

This recipe walks you through how to display and edit information about dates and durations in your records in a visual way.

How to do it...

  1. Define a calendar view:
    <record id="calendar_project_task" model="ir.ui.view">
        <field name="model">project.task</field>
        <field name="arch" type="xml">
            <calendar date_start="date_start" date_stop="date_end" color="project_id">
                <field name="name" />
                <field name="user_id" />
            </calendar>
        </field>
    </record>
  2. Add menus and actions using this view. This is left as an exercise for the reader.

How it works...

The calendar view needs to be passed field names in the attributes date_start and date_stop to indicate which fields to look at when building the visual representation. Use fields of type Datetime as everything else will get you weird results. While date_start is required, you can leave out date_stop and set the attribute date_delay instead, which is expected to be a Float field representing the duration in hours.

The calendar view allows you to give records which have the same value in a field the same (arbitrarily assigned) color. To use this functionality, set the attribute color to the name of the field you need. In our example, we can see in one glance which tasks belong to the same project, because we assigned project_id as the field to determine the color groups.

The fields you name in the calendar element's body are shown within the block representing the time interval covered, separated by commas.

There's more...

The calendar view has some other helpful attributes. If you want to open calendar entries in a popup instead of the standard form view, set event_open_popup to 1. If you want to be able to create a new entry by just filling in some text, set quick_add to 1. Internally, this calls the model's name_create function to actually create the record.

If your model has a notion of covering a whole day, set all_day to a field's name that is true if the record covers the whole day, and false otherwise.

In case you need more fine grained control over the text displayed within the calendar items, set the attribute display to a format string using field names in brackets. In our case, we could say display="[name] (assigned to [user_id])" to have a more verbose representation of which task is assigned to whom.

Note that this recipe contained information about a legacy view type gantt, which has been obsoleted during writing and was removed from the text.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset