# -*- coding: utf-8 -*- from openerp import models, api, fields, _ from datetime import datetime from openerp.exceptions import ValidationError import json class project_task_activity(models.Model): _name = 'project.task.activity' _order = "sequence" task_id = fields.Many2one( 'project.task', string='Task', required=True, ondelete='cascade') project_id = fields.Many2one( 'project.project', string='Project', related='task_id.project_id', store=True) company_id = fields.Many2one( 'res.company', string='Compañía', related='task_id.company_id', readonly=True, store=True) name = fields.Char('Name', required=True) user_id = fields.Many2one('res.users', 'Responsible') planned_date = fields.Datetime('Fecha Inicial',default=datetime.today()) done_date = fields.Datetime('Fecha Final') duration= fields.Char(compute='_get_duration', string='Duracion') description = fields.Text('Description') sequence = fields.Integer( 'Sequence', help="Gives the sequence order when selecting an activitiy.", default=10) is_done = fields.Boolean('Done?') state= fields.Selection( [('pending', 'Pendiente'), ('done', 'Realizado'), ('cancel', 'Cancelado')], 'State', required=True) hex_value=fields.Char(string='Color', compute='_get_state_value') _defaults = { 'user_id': lambda obj, cr, uid, ctx=None: uid, 'state':'pending', 'hex_value': '#FA5858', } @api.multi @api.onchange('state') def _get_state_value(self): for record in self: if record.state=='pending': record.hex_value='#FA5858' if record.state=='done': record.hex_value='#58ACFA' if record.state=='cancel': record.hex_value='#A4A4A4' @api.multi def unlink(self): res = super(project_task_activity,self).unlink() # res= self.env.cr.execute("DELETE FROM project_task_activity WHERE id= %s" % (self.id)) return res @api.onchange('done_date') def _get_duration(self): res={} if self.done_date and self.planned_date: d1 = datetime.strptime(self.planned_date, "%Y-%m-%d %H:%M:%S") d2 = datetime.strptime(self.done_date, "%Y-%m-%d %H:%M:%S") if d2