12345678910111213141516171819202122232425262728293031323334353637 |
- # -*- coding: utf-8 -*-
- from openerp import models, fields, api, tools
- from openerp.exceptions import ValidationError, except_orm, Warning, RedirectWarning
- class ProjectService(models.Model):
- _name = 'project.service'
- name = fields.Char('Nombre')
- sequence = fields.Integer(string='Sequence')
- image_medium = fields.Binary('Binary File')
- active = fields.Boolean('Activo')
- color = fields.Integer('Color Index')
- project_service_task_ids = fields.One2many(
- 'project.service.task',
- 'project_id',
- )
- project_service_task_count = fields.Integer(
- string='Contador de trabajos',
- compute='_get_project_service_task_count',
- )
- _defaults = {
- 'active': 1,
- }
- @api.multi
- def unlink(self):
- for project in self:
- if len(project.project_service_task_ids) > 0:
- raise Warning('No puedes borrar un proyecto que tiene tareas')
- return super(ProjectService, self).unlink()
- @api.one
- @api.depends('project_service_task_ids')
- def _get_project_service_task_count(self):
- self.project_service_task_count = len(self.project_service_task_ids)
|