Vigneshwaran Thenraj
Vigneshwaran Thenraj

Reputation: 708

Disable the create option from calendar view ODOO

I can able to disable the quick_add in calendar view while clicking, but it leads to open of "form view" and user can able to create a task.

My Snippet is as follows as

<!--  Calendar View Begins-->
  <record id="pms_view_task_calendar" model="ir.ui.view">
        <field name="name">project.task.calendar</field>
        <field name="model">project.task</field>
        <field name="inherit_id" ref="project.view_task_calendar"/>
        <field name="arch" type="xml">
            <calendar position="attributes">
                <attribute name="quick_add">false</attribute>
            </calendar>
        </field>
  </record>
  <!--  Calendar View Ends-->

How to disable the create option in calendar view while clicking the calendar

Upvotes: 0

Views: 3120

Answers (3)

A. Cbr
A. Cbr

Reputation: 33

Update for Odoo 11 and how to make the calendar view fully readonly for a specific model :

the JS file:

odoo.define('your_module.CalendarView', function (require) {
"use strict";

    var CalendarView = require('web.CalendarView');
    CalendarView.include({
        init: function (viewInfo, params) {
            this._super.apply(this, arguments);
            if (this.controllerParams.modelName == 'your.model.name') {
                this.loadParams.editable = false;
                this.loadParams.creatable = false;
            }
        },
    });

    return CalendarView;
});

And don't forget to "include" the js through your xml:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <template id="assets_backend" name="handling assets" inherit_id="web.assets_backend">
        <xpath expr="." position="inside">
            <script type="text/javascript" src="/your_module/static/src/js/your_javascript_file_name.js"/>
        </xpath>
    </template>
</odoo>

Upvotes: 2

Shameem
Shameem

Reputation: 2814

Vigneshwaran's answer works well. I have modified his answer to set multiple models.

var calenderView = require('web_calendar.CalendarView');
calenderView.include({
    open_quick_create: function(){
        var calendar_models = ['project.task', 'sale.order', 'crm.lead'];
        if (!(calendar_models.includes(this.model))) {
            this._super();
        }
    }
 });

Upvotes: 0

Vigneshwaran Thenraj
Vigneshwaran Thenraj

Reputation: 708

Finally, I removed the create option from the calendar view in click action by inheriting the JS.

odoo.define('module_name.calender_view', function (require) {
"use strict";

var calenderView = require('web_calendar.CalendarView');
    calenderView.include({
    open_quick_create: function(){
    if (this.model != 'model.name') {
        this._super();
    }
}
});
});

Upvotes: 3

Related Questions