From b90ee11ef30a4cd00e3889799e4ebab439538dcc Mon Sep 17 00:00:00 2001 From: Kevin Baptiste Date: Wed, 17 Nov 2021 15:15:03 +0000 Subject: [PATCH] [FIX] hr_holidays, *_calendar: disable sync on new leave On large databases, the `postcommit` hook for Google|Microsoft Calendar was taking up to 10% of a leave validation even if the user has the sync disabled. This commit disables the postcommit hook for new leaves, as the event will be synced through the cron eventually. closes odoo/odoo#80160 Taskid: 2693265 X-original-commit: 88884292e105eab2c36b2a334c617ac4978fa79c Signed-off-by: Arnaud Joset Signed-off-by: Kevin Baptiste --- addons/google_calendar/models/google_sync.py | 3 +++ addons/hr_holidays/models/hr_leave.py | 1 + addons/microsoft_calendar/models/microsoft_sync.py | 3 +++ 3 files changed, 7 insertions(+) diff --git a/addons/google_calendar/models/google_sync.py b/addons/google_calendar/models/google_sync.py index 7022716ad9d..d304eb90f95 100644 --- a/addons/google_calendar/models/google_sync.py +++ b/addons/google_calendar/models/google_sync.py @@ -31,6 +31,9 @@ def after_commit(func): context = self.env.context uid = self.env.uid + if self.env.context.get('no_calendar_sync'): + return + @self.env.cr.postcommit.add def called_after(): db_registry = registry(dbname) diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index cb62e2b8ee4..59ffa5044c2 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -1230,6 +1230,7 @@ class HolidaysRequest(models.Model): tracking_disable=True, mail_activity_automation_skip=True, leave_fast_create=True, + no_calendar_sync=True, leave_skip_state_check=True, ).create(values) diff --git a/addons/microsoft_calendar/models/microsoft_sync.py b/addons/microsoft_calendar/models/microsoft_sync.py index 75f6f7832bf..7ff2bdafe84 100644 --- a/addons/microsoft_calendar/models/microsoft_sync.py +++ b/addons/microsoft_calendar/models/microsoft_sync.py @@ -33,6 +33,9 @@ def after_commit(func): context = self.env.context uid = self.env.uid + if self.env.context.get('no_calendar_sync'): + return + @self.env.cr.postcommit.add def called_after(): db_registry = registry(dbname)