project_service.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api, tools
  3. from openerp.exceptions import ValidationError, except_orm, Warning, RedirectWarning
  4. class ProjectService(models.Model):
  5. _name = 'project.service'
  6. name = fields.Char('Nombre')
  7. sequence = fields.Integer(string='Sequence')
  8. image_medium = fields.Binary('Binary File')
  9. active = fields.Boolean('Activo')
  10. color = fields.Integer('Color Index')
  11. project_service_task_ids = fields.One2many(
  12. 'project.service.task',
  13. 'project_id',
  14. )
  15. project_service_task_count = fields.Integer(
  16. string='Contador de trabajos',
  17. compute='_get_project_service_task_count',
  18. )
  19. _defaults = {
  20. 'active': 1,
  21. }
  22. @api.multi
  23. def unlink(self):
  24. for project in self:
  25. if len(project.project_service_task_ids) > 0:
  26. raise Warning('No puedes borrar un proyecto que tiene tareas')
  27. return super(ProjectService, self).unlink()
  28. @api.one
  29. @api.depends('project_service_task_ids')
  30. def _get_project_service_task_count(self):
  31. self.project_service_task_count = len(self.project_service_task_ids)