'Determine reserved, available, reserved but unconfirmed and used seats.'

@api.multi
@api.depends('seats_max', 'registration_ids.state')
def _compute_seats(self):

    for event in self:
        event.seats_unconfirmed = event.seats_reserved = event.seats_used = event.seats_available = 0
    if self.ids:
        state_field = {'draft': 'seats_unconfirmed', 'open': 'seats_reserved', 'done': 'seats_used'}
        query = "    SELECT    event_id,    state,    count(event_id)\n                                                                                                FROM    event_registration\n                                                                                                WHERE    event_id    IN    %s    AND    state    IN    ('draft',    'open',    'done')\n                                                                                                GROUP    BY    event_id,    state\n                                                                                "
        self._cr.execute(query, (tuple(self.ids),))
        for (event_id, state, num) in self._cr.fetchall():
            event = self.browse(event_id)
            event[state_field[state]] += num
    for event in self:
        if (event.seats_max > 0):
            event.seats_available = (event.seats_max - (event.seats_reserved + event.seats_used))
        event.seats_expected = ((event.seats_unconfirmed + event.seats_reserved) + event.seats_used)
