Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class prueba_consultor_voto(models.Model):
- _name = 'prueba_consultor.voto'
- # Fields
- active = fields.Boolean('Activo/Borrado', default=True)
- persona_id = fields.Many2one(
- 'res.users',
- 'Votante',
- default=lambda self: self._context.get('uid', None),
- )
- calificacion = fields.Float('Calificación')
- fecha = fields.Date(
- 'fecha',
- default = fields.Date.today()
- )
- idea_id = fields.Many2one(
- 'prueba_consultor.idea',
- 'Idea',
- default=lambda self: self._context.get('idea_id', None),
- )
- @api.constrains('persona_id')
- def check_persona_id(self):
- if self.idea_id.autor_id == self.persona_id:
- raise Warning('El autor de la idea no puede votar por ella')
- return False
- ids = self.env['prueba_consultor.voto'].search([('persona_id', '=', self.persona_id.id)])
- if len(ids):
- raise Warning('El usuario ya realizó el voto')
- return False
- return True
- @api.constrains('calificacion')
- def check_calificacion(self):
- if self.calificacion >=0 and self.calificacion <= 10:
- return True
- else:
- raise Warning('la calificación debe estar entre 0 y 10')
- return False
- @api.model
- def create(self, vals):
- print vals
- record_idea = self.env['prueba_consultor.idea'].browse(vals['idea_id']);
- if record_idea.fecha_inicio and record_idea.fecha_fin:
- if vals['fecha'] >= record_idea.fecha_inicio and vals['fecha'] <= record_idea.fecha_fin:
- voto = super(prueba_consultor_voto, self).create(vals)
- return voto
- elif vals['fecha'] > record_idea.fecha_fin:
- raise Warning('Las votaciones estan cerradas')
- elif vals['fecha'] < record_idea.fecha_inicio:
- raise Warning('Las votaciones aun no se han abierto')
- else:
- raise Warning('Pendiente definir fecha de inicio de votaciones')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement