-
How to Solve display several calculated fields on a single form view in OpenErp-8
over 9 years ago
-
almost 9 years ago
You can make a fields as function type
in odoo-8.0 there is the compute attribute to make the field as a function
For Example: seats_reserved = fields.Integer(oldname='register_current', string='Reserved Seats', store=True, readonly=True, compute='_compute_seats')
@api.multi @api.depends('seats_max', 'registration_ids.state', 'registration_ids.nb_register') def _compute_seats(self): """ Determine reserved, available, reserved but unconfirmed and used seats. """ # initialize fields to 0 for event in self: event.seats_unconfirmed = event.seats_reserved = event.seats_used = 0 # aggregate registrations by event and by state if self.ids: state_field = { 'draft': 'seats_unconfirmed', 'open':'seats_reserved', 'done': 'seats_used', } query = """ SELECT event_id, state, sum(nb_register) FROM event_registration WHERE event_id IN %s AND state IN ('draft', 'open', 'done') GROUP BY event_id, state """ 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 # compute seats_available for event in self: event.seats_available = \ event.seats_max - (event.seats_reserved + event.seats_used) \ if event.seats_max > 0 else 0
You can see in the event module in event.py file
Thanks
-
1 Answer(s)