Skip to content

Commit

Permalink
Easier to read constrain.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jairo Llopis committed Dec 31, 2015
1 parent 072cb5d commit 42787aa
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions event_product/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ class EventEvent(models.Model):
@api.constrains("type", "product_id")
def _check_product_type(self):
"""Ensure product and event types match."""
for s in self:
if s.product_id:
if not s.product_id.is_event:
raise ex.ProductIsNotEventError(s.product_id.name)
if s.product_id.event_type_id not in (s.type,
self.env["event.type"]):
raise ex.TypeMismatchError(
product_type=s.product_id.event_type_id.name,
event_type=s.type.name)
for s in self.filtered("product_id"):
if not s.product_id.is_event:
raise ex.ProductIsNotEventError(s.product_id.display_name)
elif (s.product_id.event_type_id and
s.product_id.event_type_id != s.type):
raise ex.TypeMismatchError(
product_type=s.product_id.event_type_id.display_name,
event_type=s.type.display_name)

@api.multi
@api.onchange("type")
Expand Down

0 comments on commit 42787aa

Please sign in to comment.