This question has been flagged
3 Replies
8239 Views

I need to set 'Everybody's Calendar' always check by default in the right side of odoo calendar. It's always on Administrator[Me] and i have to select 'everybody's calendar' to see the events.

Yenthe Van Ginneken said here https://www.odoo.com/fr_FR/forum/aide-1/question/where-is-the-code-for-the-everybody-s-calendars-boolean-in-the-calendar-app-150133 that the code for this is in _loadFilter but i can't figure how to do it.. Thank you!

I can't post a print, but here it is https://stackoverflow.com/questions/57115029/how-to-set-everybodys-calendar-by-default





Avatar
Discard
Author Best Answer
    <record id="view_l10n_cu_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">
<data>
<field name="partner_ids" position="replace" >
<field name="partner_ids"/>
</field>
</data>
</field>
</record>


Avatar
Discard

Where do you implement this in order to make this work on V 10 please?

Best Answer

Was able to 'default' to the All option (Everything/Everybody) by manually toggling the checkboxes during initialization. This results in selection loading twice but acheives desired affect. Leaving here for others:


odoo.define('service.CalendarModel', function (require) {

    "use strict"


var waitFor = function(selector, callback) {

    var element = $(selector);

    if (element.length) {

        callback(element);

    } else {

        setTimeout(function() {

            waitFor(selector, callback);

        }, 100);

    }

};


var CalendarModel = require('web.CalendarModel')


CalendarModel.include({

    /**

     * @override

     */

    init: function (context) {

        this._super.apply(this, arguments)

        // This is a hack to select 'Everything/Everybod's calendars' filters by default (instead of just 'Username [Me]')

        waitFor('.o_calendar_filter_item', function(filters) {

            filters.map(function() {

                var isAll = $(this).data('value') === 'all';

                var checkbox = $(this).find('.custom-control input').get(0);

                if (checkbox && (isAll && !checkbox.checked) || (!isAll && checkbox.checked)) {

                    return checkbox;

                }

            }).click();

        });

    }

})

});

Avatar
Discard

Can you specify which Odoo version you are using?

Best Answer

here is my code for v14 . 

need to set "not_init" so it only calls on _loadFilter on initial load


var CalendarModel = require('web.CalendarModel')
CalendarModel.include({
   _loadFilter: function(filter){
       if (!filter.not_init){
           filter.not_init = true;
           filter.all = true;
       }
       return this._super(filter);
   },
});
Avatar
Discard