I have an entity "appointment" with a date_appointment attribute. I have also created a Calendar view for that appointment. An appointment should never be scheduled on weekends, so I have disable those days in odoo datepicker (in the doem view). But when I clic on any Satursday or sunday in the Calendar view it shows the form view where I can create an appointment for that day. Is there any way I can disable those days in Odoo Calendar, so the user cannot clic on any weekend an create appointments. I have already disable the quick_add option
<record id="appointment_view_calendar" model="ir.ui.view">
<field name="name">appointment.view.calendar</field>
<field name="model">tico_hospital.appointment</field>
<field name="arch" type="xml">
<calendar string="Consultas programadas" mode="week" date_start="date_appointment" quick_add="False" color="patient_id">
<field name="patient_id"/>
<field name="reason"/>
</calendar>
</field>
</record>
According to the documentation, there is no option to disable the click on a specific day in the calendar view.
You can add a constraint to alert users when they try to create an appointment for weekdays.
If you need to avoid opening the form view when clicking on weekdays, override the _onOpenCreate
method in the calendar controller.
The following example checks if the user has clicked on a weekday, if yes it shows an alert and avoids opening the form view.
odoo.define('web.CustomCalendar', function (require) {
"use strict";
var core = require('web.core');
var Dialog = require('web.Dialog');
var _t = core._t;
var WebCalendarController = require('web.CalendarController');
WebCalendarController.include({
_onOpenCreate: function (event) {
if(event.target.model==='tico_hospital.appointment' && [0, 6].includes(event.data.start.day())) {
Dialog.alert(this, _t("You cannot create an appointment for Sunday or Saturday!"));
return;
}
return this._super(event);
},
});
});
Edit:
To add the files in an asset bundle, you need to:
assets.xml
file in the views/
folderviews/assets.xml
in the data
key in the manifest filecreate an inherited view of the desired bundle (here web.assets_backend
), and add the file(s) with an XPath expression. For example,
<template id="assets_backend" name="stack_overflow assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/stack_overflow/static/src/js/script.js"></script>
</xpath>
</template>
There are many different reasons why a file may not be properly loaded. Here are a few things you can try to solve the issue:
F12
) to make sure there are no obvious errorsdebug=assets
mode. This will actually bypass the asset bundles (note that it does not actually solve the issue. The server still uses outdated bundles)