From 5fdbd08afced3cd75fa978a508f97cc0a14a9ac0 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Wed, 17 Feb 2016 16:17:33 +0100 Subject: [PATCH 1/2] Make no type count as a type. Fix #35. When an event had no type, it was not getting in the mapping because of the way Odoo generates recordsets. --- .../tests/test_event_registration_cancel_reason.py | 8 ++++++++ .../wizard/event_registration_cancel_log_reason.py | 13 +++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/event_registration_cancel_reason/tests/test_event_registration_cancel_reason.py b/event_registration_cancel_reason/tests/test_event_registration_cancel_reason.py index 7274764e0..eb2c76cfa 100644 --- a/event_registration_cancel_reason/tests/test_event_registration_cancel_reason.py +++ b/event_registration_cancel_reason/tests/test_event_registration_cancel_reason.py @@ -44,3 +44,11 @@ def test_cancel_multi_event_type(self): self.wizard_model.with_context( active_ids=self.registrations.ids).create( {'reason_id': self.cancel_reason.id}) + + def test_cancel_one_event_without_type(self): + """Registration cancel from 2 events (1 typed, 1 not) are aborted.""" + self.event2.type = False + with self.assertRaises(exceptions.ValidationError): + self.wizard_model.with_context( + active_ids=self.registrations.ids).create( + {'reason_id': self.cancel_reason.id}) diff --git a/event_registration_cancel_reason/wizard/event_registration_cancel_log_reason.py b/event_registration_cancel_reason/wizard/event_registration_cancel_log_reason.py index e5c6de467..7abdd81d7 100644 --- a/event_registration_cancel_reason/wizard/event_registration_cancel_log_reason.py +++ b/event_registration_cancel_reason/wizard/event_registration_cancel_log_reason.py @@ -23,12 +23,13 @@ def default_get(self, var_fields): var_fields) registrations = self.env['event.registration'].browse( self.env.context['active_ids']) - event_type = registrations.mapped("event_id.type") - if len(event_type) != 1: - raise exceptions.ValidationError( - _("You cannot cancel registrations from events of different " - "types at once.")) - res['event_type_id'] = event_type.id + first_type = registrations[0].event_id.type + for event in registrations.mapped("event_id"): + if event.type != first_type: + raise exceptions.ValidationError( + _("You cannot cancel registrations from events of " + "different types at once.")) + res['event_type_id'] = first_type.id return res @api.multi From e2cd4678aa25bcbdaadd8e3892cf0d681b9db1e7 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Wed, 17 Feb 2016 18:21:34 +0100 Subject: [PATCH 2/2] Select empty recordset if that case happens, instead of excepting. --- .../wizard/event_registration_cancel_log_reason.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/event_registration_cancel_reason/wizard/event_registration_cancel_log_reason.py b/event_registration_cancel_reason/wizard/event_registration_cancel_log_reason.py index 7abdd81d7..2e68460e4 100644 --- a/event_registration_cancel_reason/wizard/event_registration_cancel_log_reason.py +++ b/event_registration_cancel_reason/wizard/event_registration_cancel_log_reason.py @@ -23,7 +23,7 @@ def default_get(self, var_fields): var_fields) registrations = self.env['event.registration'].browse( self.env.context['active_ids']) - first_type = registrations[0].event_id.type + first_type = registrations[:1].event_id.type for event in registrations.mapped("event_id"): if event.type != first_type: raise exceptions.ValidationError(