From 6b25f07c09388c15cbd6d0d3dd3b162cb809e709 Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Thu, 21 Jan 2021 15:29:36 +0000 Subject: [PATCH] [FIX] google_calendar: enable the event deletion When using the Calender synced with Google, if the user tries to delete an event, an error message is displayed: he has to archive it instead. To reproduce the error: 1. Sync Odoo Calendar with Gogle Calendar 2. Add an event 3. Click on it > Delete Error: UserError message: "You cannot delete a record synchronized with Google Calendar, archive it instead" To make the flow simpler and faster, when clicking on "Delete", the server will archive the event. When archiving an event, the server deletes the corresponding event on Google Calendar. As a result, the next time the user loads his Odoo Calendar, the sync Google->Odoo will delete the archived event. OPW-2440339 closes odoo/odoo#64957 X-original-commit: 109ffab4a5d3e77d330d7fa4cc5fd39017bdf561 Signed-off-by: Adrien Widart --- addons/google_calendar/i18n/google_calendar.pot | 12 ++---------- addons/google_calendar/models/google_sync.py | 13 ++++++------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/addons/google_calendar/i18n/google_calendar.pot b/addons/google_calendar/i18n/google_calendar.pot index e76e934fbf7..629573f0c7c 100644 --- a/addons/google_calendar/i18n/google_calendar.pot +++ b/addons/google_calendar/i18n/google_calendar.pot @@ -4,10 +4,10 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 14.0\n" +"Project-Id-Version: Odoo Server 14.0+e\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2020-11-27 11:24+0000\n" -"PO-Revision-Date: 2020-11-27 11:24+0000\n" +"PO-Revision-Date: 2021-01-22 08:05+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -364,14 +364,6 @@ msgstr "" msgid "Users" msgstr "" -#. module: google_calendar -#: code:addons/google_calendar/models/google_sync.py:0 -#, python-format -msgid "" -"You cannot delete a record synchronized with Google Calendar, archive it " -"instead." -msgstr "" - #. module: google_calendar #. openerp-web #: code:addons/google_calendar/static/src/js/google_calendar.js:0 diff --git a/addons/google_calendar/models/google_sync.py b/addons/google_calendar/models/google_sync.py index 06c09bc48b5..0007e5d10c8 100644 --- a/addons/google_calendar/models/google_sync.py +++ b/addons/google_calendar/models/google_sync.py @@ -97,13 +97,6 @@ class GoogleSync(models.AbstractModel): record._google_insert(google_service, record._google_values(), timeout=3) return records - @api.ondelete(at_uninstall=False) - def _unlink_except_synchronized(self): - if self.env.context.get('archive_on_error') and self._active_name: - return - if self.filtered('google_id'): - raise UserError(_("You cannot delete a record synchronized with Google Calendar, archive it instead.")) - def unlink(self): """We can't delete an event that is also in Google Calendar. Otherwise we would have no clue that the event must must deleted from Google Calendar at the next sync. @@ -113,6 +106,12 @@ class GoogleSync(models.AbstractModel): if self.env.context.get('archive_on_error') and self._active_name: synced.write({self._active_name: False}) self = self - synced + elif synced: + # Since we can not delete such an event (see method comment), we archive it. + # Notice that archiving an event will delete the associated event on Google. + # Then, since it has been deleted on Google, the event is also deleted on Odoo DB (_sync_google2odoo). + self.action_archive() + return True return super().unlink() @api.model