Skip to content

Commit

Permalink
[FIX] event_registration_partner_unique: Change all references to att…
Browse files Browse the repository at this point in the history
…endee_partner_id
  • Loading branch information
pedrobaeza committed Nov 8, 2018
1 parent c60737e commit 530a807
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions event_registration_partner_unique/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EventRegistration(models.Model):
_inherit = "event.registration"

@api.multi
@api.constrains("event_id", "partner_id")
@api.constrains("event_id", "attendee_partner_id")
def _check_forbid_duplicates(self):
"""Ensure no duplicated attendees are found in the event."""
for s in self.filtered("event_id.forbid_duplicates"):
Expand All @@ -34,7 +34,7 @@ def _check_forbid_duplicates(self):
raise exceptions.DuplicatedPartnerError(
s.event_id.display_name,
", ".join(d.display_name
for d in dupes.mapped("partner_id")),
for d in dupes.mapped("attendee_partner_id")),
registrations=dupes,
)

Expand Down
13 changes: 10 additions & 3 deletions event_registration_partner_unique/tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def setUp(self):
self.registration = self.env["event.registration"].create({
"event_id": self.event.id,
"partner_id": self.partner.id,
"attendee_partner_id": self.partner.id,
})

def test_allowed(self):
Expand All @@ -23,18 +24,24 @@ def test_forbidden(self):
"""Cannot when it is forbidden."""
self.event.forbid_duplicates = True
with self.assertRaises(exceptions.DuplicatedPartnerError):
self.registration.copy()
self.registration.copy({
'attendee_partner_id': self.registration.attendee_partner_id.id
})

def test_saved_in_exception(self):
"""The failing partners are saved in the exception."""
self.event.forbid_duplicates = True
try:
self.registration.copy()
self.registration.copy({
'attendee_partner_id': self.registration.attendee_partner_id.id
})
except exceptions.DuplicatedPartnerError as error:
self.assertEqual(error._kwargs["registrations"], self.registration)

def test_duplicates_already_exist(self):
"""Cannot forbid what already happened."""
self.registration.copy()
self.registration.copy({
'attendee_partner_id': self.registration.attendee_partner_id.id,
})
with self.assertRaises(exceptions.DuplicatedPartnerError):
self.event.forbid_duplicates = True

0 comments on commit 530a807

Please sign in to comment.