From f00919461ef95b3a3826d623febddb4e31165352 Mon Sep 17 00:00:00 2001 From: Florian Damhaut Date: Fri, 17 Feb 2023 14:18:45 +0000 Subject: [PATCH] [IMP] calendar: delete recurrent event This PR change the delete button in the attendee calendar if the event is recurrent. If the event is recurrent, a wizard pop up to ask if you wish to remove : - The selected event - The selected event and the following - All the event in the recurrence task-id : 3148011 closes odoo/odoo#113024 Signed-off-by: Arnaud Joset --- addons/calendar/__manifest__.py | 3 ++- addons/calendar/security/ir.model.access.csv | 1 + .../attendee_calendar_controller.js | 22 +++++++++++++++- .../calendar/tests/test_event_recurrence.py | 23 +++++++++++++++-- addons/calendar/wizard/__init__.py | 1 + .../wizard/calendar_popover_delete_wizard.py | 25 +++++++++++++++++++ .../wizard/calendar_popover_delete_wizard.xml | 16 ++++++++++++ 7 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 addons/calendar/wizard/calendar_popover_delete_wizard.py create mode 100644 addons/calendar/wizard/calendar_popover_delete_wizard.xml diff --git a/addons/calendar/__manifest__.py b/addons/calendar/__manifest__.py index 69d27030d60..5535bb02013 100644 --- a/addons/calendar/__manifest__.py +++ b/addons/calendar/__manifest__.py @@ -34,7 +34,8 @@ If you need to manage your meetings, you should install the CRM module. 'views/calendar_templates.xml', 'views/calendar_views.xml', 'views/res_partner_views.xml', - 'wizard/calendar_provider_config.xml' + 'wizard/calendar_provider_config.xml', + 'wizard/calendar_popover_delete_wizard.xml', ], 'installable': True, 'application': True, diff --git a/addons/calendar/security/ir.model.access.csv b/addons/calendar/security/ir.model.access.csv index da97d846e0a..41c0bfcc3a2 100644 --- a/addons/calendar/security/ir.model.access.csv +++ b/addons/calendar/security/ir.model.access.csv @@ -1,6 +1,7 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_calendar_attendee_portal,calendar.attendee_portal,model_calendar_attendee,base.group_portal,0,0,0,0 access_calendar_attendee_employee,calendar.attendee_employee,model_calendar_attendee,base.group_user,1,1,1,1 +access_calendar_attendee_employee_delete_wizard,calendar.attendee_employee_delete_wizard,model_calendar_popover_delete_wizard,base.group_user,1,1,1,1 access_calendar_alarm,calendar.alarm,model_calendar_alarm,base.group_user,1,1,1,1 access_calendar_event_all_user,calendar.event_all_user,model_calendar_event,base.group_portal,1,0,0,0 access_calendar_event_all_employee,calendar.event_all_employee,model_calendar_event,base.group_user,1,1,1,1 diff --git a/addons/calendar/static/src/views/attendee_calendar/attendee_calendar_controller.js b/addons/calendar/static/src/views/attendee_calendar/attendee_calendar_controller.js index c5c06619c25..e588dc9d813 100644 --- a/addons/calendar/static/src/views/attendee_calendar/attendee_calendar_controller.js +++ b/addons/calendar/static/src/views/attendee_calendar/attendee_calendar_controller.js @@ -32,7 +32,11 @@ export class AttendeeCalendarController extends CalendarController { */ deleteRecord(record) { if (this.user.partnerId === record.attendeeId && this.user.partnerId === record.rawRecord.partner_id[0]) { - super.deleteRecord(...arguments); + if (record.rawRecord.recurrency) { + this.openRecurringDeletionWizard(record); + } else { + super.deleteRecord(...arguments); + } } else { // Decline event this.orm.call( @@ -43,6 +47,22 @@ export class AttendeeCalendarController extends CalendarController { } } + openRecurringDeletionWizard(record) { + this.actionService.doAction({ + type: 'ir.actions.act_window', + res_model: 'calendar.popover.delete.wizard', + views: [[false, 'form']], + view_mode: "form", + name: 'Delete Recurring Event', + context: {'default_record': record.id}, + target: 'new' + }, { + onClose: () => { + location.reload(); + }, + }); + } + configureCalendarProviderSync(providerName) { this.actionService.doAction({ name: this.env._t('Connect your Calendar'), diff --git a/addons/calendar/tests/test_event_recurrence.py b/addons/calendar/tests/test_event_recurrence.py index 799a1382edc..d477e1b8359 100644 --- a/addons/calendar/tests/test_event_recurrence.py +++ b/addons/calendar/tests/test_event_recurrence.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo.exceptions import UserError import pytz from datetime import datetime, date from dateutil.relativedelta import relativedelta -from odoo.tests.common import TransactionCase +from odoo.tests.common import TransactionCase, Form class TestRecurrentEvents(TransactionCase): @@ -580,6 +579,26 @@ class TestUpdateRecurrentEvents(TestRecurrentEvents): self.assertTrue(self.recurrence) self.assertEqual(self.events.exists(), self.events[0]) + def test_unlink_recurrence_wizard_next(self): + event = self.events[1] + wizard = self.env['calendar.popover.delete.wizard'].create({'record': event.id}) + form = Form(wizard) + form.delete = 'next' + form.save() + wizard.close() + self.assertTrue(self.recurrence) + self.assertEqual(self.events.exists(), self.events[0]) + + def test_unlink_recurrence_wizard_all(self): + event = self.events[1] + wizard = self.env['calendar.popover.delete.wizard'].create({'record': event.id}) + form = Form(wizard) + form.delete = 'all' + form.save() + wizard.close() + self.assertFalse(self.recurrence.exists()) + self.assertFalse(self.events.exists()) + class TestUpdateMultiDayWeeklyRecurrentEvents(TestRecurrentEvents): diff --git a/addons/calendar/wizard/__init__.py b/addons/calendar/wizard/__init__.py index 0d1fe747cc7..7ec0558710c 100644 --- a/addons/calendar/wizard/__init__.py +++ b/addons/calendar/wizard/__init__.py @@ -3,3 +3,4 @@ from . import calendar_provider_config +from . import calendar_popover_delete_wizard diff --git a/addons/calendar/wizard/calendar_popover_delete_wizard.py b/addons/calendar/wizard/calendar_popover_delete_wizard.py new file mode 100644 index 00000000000..92de385fbee --- /dev/null +++ b/addons/calendar/wizard/calendar_popover_delete_wizard.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class CalendarProviderConfig(models.TransientModel): + _name = 'calendar.popover.delete.wizard' + _description = 'Calendar Popover Delete Wizard' + + + record = fields.Many2one('calendar.event', 'Calendar Event') + delete = fields.Selection([('one', 'Delete this event'), ('next', 'Delete this and following events'), ('all', 'Delete all the events')], default='one') + + def close(self): + if not self.record or not self.delete: + pass + elif self.delete == 'one': + self.record.unlink() + else: + switch = { + 'next': 'future_events', + 'all': 'all_events' + } + self.record.action_mass_deletion(switch.get(self.delete, '')) diff --git a/addons/calendar/wizard/calendar_popover_delete_wizard.xml b/addons/calendar/wizard/calendar_popover_delete_wizard.xml new file mode 100644 index 00000000000..8eb8bc4e700 --- /dev/null +++ b/addons/calendar/wizard/calendar_popover_delete_wizard.xml @@ -0,0 +1,16 @@ + + + + calendar.popover.delete.wizard.view.form + calendar.popover.delete.wizard + +
+ + + +
+
+