Odoo 10日历视图点击直接打开表单视图而非摘要窗口
Hey there! Let's get this sorted so clicking on your Odoo 10 calendar (either empty spots or existing events) opens the form view directly, skipping that default quick summary popup. Your current code is modifying the popup's buttons, but we need to replace the entire click behavior instead. Here's how to do it properly:
Step 1: Create a Custom Module
First, you'll need a custom module to override the calendar's default behavior. Let's outline the structure:
your_custom_calendar/ ├── __init__.py ├── __manifest__.py ├── static/ │ └── src/ │ └── js/ │ └── calendar_direct_form.js └── views/ └── assets.xml
Step 2: Module Manifest (__manifest__.py)
Make sure your module depends on web_calendar so it loads after the core calendar module:
{ 'name': 'Calendar Direct Form View', 'version': '1.0', 'depends': ['web_calendar'], 'data': ['views/assets.xml'], 'installable': True, 'auto_install': False, }
Step 3: Override Calendar Click Behavior (calendar_direct_form.js)
This JS file will inherit the core CalendarView widget and replace the click handlers to open the form view directly:
odoo.define('your_custom_calendar.calendar_view', function (require) { "use strict"; var CalendarView = require('web_calendar.CalendarView'); var core = require('web.core'); CalendarView.include({ // Handle clicks on existing calendar events: open form view directly _onEventClick: function (event) { event.stopPropagation(); // Block the default popup var eventRecord = event.data.event; // Trigger the form view action this.do_action({ type: 'ir.actions.act_window', res_model: this.modelName, res_id: eventRecord.id, views: [[false, 'form']], target: 'current', // Open in the current tab/window }); }, // Handle clicks on empty calendar slots: open form view with pre-filled dates _onDayClick: function (event) { event.stopPropagation(); // Block the default quick-create popup var startDate = event.data.start; var endDate = event.data.end; // Trigger form view with default start/end times this.do_action({ type: 'ir.actions.act_window', res_model: this.modelName, views: [[false, 'form']], target: 'current', context: { default_start: startDate.toISOString(), default_stop: endDate.toISOString(), }, }); }, }); });
Step 4: Load the Custom JS (assets.xml)
This file tells Odoo to include your custom JS in the backend assets:
<?xml version="1.0" encoding="utf-8"?> <odoo> <template id="assets_backend" name="Calendar Direct Form Assets" inherit_id="web.assets_backend"> <xpath expr="." position="inside"> <script type="text/javascript" src="/your_custom_calendar/static/src/js/calendar_direct_form.js"></script> </xpath> </template> </odoo>
Step 5: Install & Test
- Install your custom module in Odoo
- Refresh your browser
- Now, clicking any empty spot on the calendar will open the event form with pre-filled start/end times, and clicking an existing event will open its form view directly—no more summary popups!
Why Your Original Code Didn't Work
Your code was modifying the content and buttons of the default quick-create popup, but your goal was to skip that popup entirely. Instead of tweaking the popup, we're replacing the click event handlers to directly trigger the form view action.
内容的提问来源于stack exchange,提问作者Pawan Kumar Sharma

