From b616d249ee1484f416491639fe16d27238811029 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Fri, 5 Jan 2024 12:23:45 +0100 Subject: [PATCH] [IMP] resource_booking: No create/unlink call if nothing to do Depending on how the create/unlink overrides are programmed, there can be overheads or blocking things when calling unconditionally these methods, even with an empty list, so let's only call them when there is really something to delete or to create. This has been discovered as `google_calendar` module is calling Google API on calendar event create (although vals_list being empty), and due to an error with Google API right now, I was not able to create a draft resource booking. --- resource_booking/models/resource_booking.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/resource_booking/models/resource_booking.py b/resource_booking/models/resource_booking.py index 9c381be5..77fb74c2 100644 --- a/resource_booking/models/resource_booking.py +++ b/resource_booking/models/resource_booking.py @@ -417,8 +417,10 @@ def _sync_meeting(self): to_create.append(meeting_vals) else: to_delete |= one.meeting_id - to_delete.unlink() - _self.env["calendar.event"].create(to_create) + if to_delete: + to_delete.unlink() + if to_create: + _self.env["calendar.event"].create(to_create) @api.constrains("combination_id", "meeting_id", "type_id") def _check_scheduling(self):