Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

V17. Do not allow make appointments on calendar at specify days

Subscribe

Get notified when there's activity on this post

This question has been flagged
calendarcalendar_view
2 Replies
2195 Views
Avatar
Matias

Hi all. I create a center module to creates appointments using calendar widget.

In my appointment model i have all the restriction when the appointment create (i check open/close, holidays and days when center open) and all works perfect but always when i click the appointment create (i can click wherever i want on the calendar view)

I want to add this controls at the calendar view. I mean, i want to block the click create event appointment on the calendar when when center close or when holidays. I read that with JavaScript this could be done but i dont know how to do it. check some javascript code but they are too old and i dont know what methods have to override to do it. Im literally new at odoo and python hehe. Could some one give a tips on how to do it? Thanks a lot!



1
Avatar
Discard
Avatar
Sandeep Mishra
Best Answer

Hi Matias,


You can do using changing code  extend the web_calendar widget in your module's JavaScript file. You can override the onCreate method to include your restrictions.


odoo.define('your_module_name.CalendarViewRestrictions', function (require) {

    "use strict";


    const CalendarController = require('web.CalendarController');

    const rpc = require('web.rpc');


    CalendarController.include({

        async onCreateEvent(event) {

            const date = event.data.date; // The clicked date


            // Call the backend method to check restrictions

            const is_allowed = await rpc.query({

                model: 'your.model.name',

                method: 'check_calendar_restrictions',

                args: [date],

            });


            if (!is_allowed) {

                this.do_warn('Restriction', 'You cannot create an appointment on this date.');

                return;

            }


            // If allowed, proceed with the default behavior

            this._super.apply(this, arguments);

        },

    });

});


0
Avatar
Discard
Matias
Author

First, thanks for the reply. It helps me a lot to understand more about Odoo.
When i try it, i have this error when open my odoo (I restart odoo server with --dev=assets flag)

"The following modules are needed by other modules but have not been defined, they may not be present in the correct asset bundle:
web.CalendarController
web.rpc
The following modules could not be loaded because they have unmet dependencies, this is a secondary error which is likely caused by one of the above problems:
@cng_appointments/js/appointment"

JavaScript file is added on __manifest__.py file

'assets': {
'web.assets_backend': [
'cng_appointments/static/src/js/calendar_restriction.js',
],
}

Avatar
Jainil Joshi D.
Best Answer

Hello matias,

can you be more specific

If you need to create the appointments via backend/erp you need to pass validations in there, else if you have created the widget in website then can you provide me a screenshot of how it looks based on that i can give you some reference of js for this validations in calender you are asking.

0
Avatar
Discard
Matias
Author

Hello! I cant provide a screenshot (button disabled) but this is what i have.

<record id="action_appointment_calendar" model="ir.actions.act_window">
<field name="name">Calendario de Citas</field>
<field name="res_model">cng_appointments.appointment</field>
<field name="view_mode">calendar,tree</field>
</record>

<record id="view_appointment_calendar" model="ir.ui.view">
<field name="name">cng_appointments.appointment.calendar</field>
<field name="model">cng_appointments.appointment</field>
<field name="arch" type="xml">
<calendar string="Calendario de Citas" mode="day" date_start="date_start" date_stop="date_end" color="box_id">
<field name="patient_id"/>
<field name="service_id"/>
<field name="box_id"/>
<field name="center_id"/>
</calendar>
</field>
</record>

<record id="view_appointment_calendar" model="ir.ui.view">
<field name="name">cng_appointments.appointment.calendar</field>
<field name="model">cng_appointments.appointment</field>
<field name="arch" type="xml">
<calendar string="Calendario de Citas" mode="day" date_start="date_start" date_stop="date_end" color="box_id">
<field name="patient_id"/>
<field name="service_id"/>
<field name="box_id"/>
<field name="center_id"/>
</calendar>
</field>
</record>

<menuitem id="menu_appointment_root" sequence="1" name="Gestión de Citas"/>
<menuitem id="menu_calendar_appointments"
name="Ver Citas"
parent="menu_appointment_root"
action="action_appointment_calendar"/>

I validate all on appointment form (After select a hour/day and confirm the popup create buttom). But i want the validations on the calendar. I mean, disable click or info the person that center is closed before the popup create button appears. @Sandeep Mishra answer i think works well but i have an error when try it.

Sorry with my english, is not good. Hope you understand what i want :')

Jainil Joshi D.

Hello matias
thanks for sharing the code this did me help for understanding your need and your problem.
you need to create a separate model named off days in which youre storing dates which are off dates and also passing a method in the calender model whcih will check the date is an off date and pass then show an warning/validation (depends on that youre passing on the offday) that the day with an off day should not be selected/ your string for the off day choosen and also you can create an boolean which will check the saturday sunday off and add those days in the off days model i believe this would help if it doesnt you can still ask me here or ping me here by upvoting i will surely respond you with your need.
Thanks
and yes this is an view (Calender view) adding constraint/validation via js doesnt make sense doing via backend/python does thus do it via python if you have this form on the portal end/website module then you need to create a validation via js.

Matias
Author

I try what Sandeep Mishra but i have this error when restart odoo server.

"The following modules are needed by other modules but have not been defined, they may not be present in the correct asset bundle:
web.CalendarController
web.rpc
The following modules could not be loaded because they have unmet dependencies, this is a secondary error which is likely caused by one of the above problems:
@cng_appointments/js/appointment"

Do you have any idea what can this error be?

Jainil Joshi D.

Hello matias,
the sandeep mishra thing need to be covered in the asset as in the manifest you need to add the file name under the folder with the path given so the compiler will register your file and thus will need compile your code and give you an needed response you needed thus for the sandeep code you need to add that in manifest file which i will give you an example below.
If this doesnt solve your problem give me your whole js code and then give me your whole error in the message thus i can see that and respond you properly with that i have your calender thing code just give me manifest code andf the js code which you have written for the validation feature.
I am providing you the code of the js file register in the manifest below.
Thanks

#This you need to put below the data file in the manifest file
# "assets": {
# "web.assets_frontend": [
# # assets for frontend
# ],
# },

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Change slotMinTime and slotMaxTime in Odoo calendar v17.
calendar calendar_view
Avatar
0
Feb 25
1248
how change calandar library
calendar calendar_view
Avatar
0
Dec 21
2512
Jalali-calendar- odoo18
calendar
Avatar
Avatar
1
Jul 25
1583
Internal Team Grouping for Calendar Solved
calendar
Avatar
Avatar
2
Jun 25
1886
Odoo 15 community: Calendar view enddate shows wrong date
calendar
Avatar
Avatar
1
May 25
3094
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now