1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- # -*- coding:utf-8 -*-
- from openerp import fields, models, api
- from datetime import datetime
- class CrmTask(models.Model):
- _name="crm.task"
- name = fields.Char(string="Actividad")
- date_action_next = fields.Datetime('Fecha Prox. Accion')
- user_id = fields.Many2one('res.users', 'Responsable')
- partner_id = fields.Many2one('res.partner', 'Cliente')
- company_id = fields.Many2one('res.company', 'Compañia')
- description = fields.Text('Descripción')
- state = fields.Selection([
- ('pending', 'Pendiente'),
- ('done', 'Realizado'),
- ('cancel','Cancelado')],
- string='Estado', track_visibility='onchange', default='pending')
- priority = fields.Selection([('0','P'), ('1','Poco'),('2','Normal'), ('3','Alto')], 'Prioridad')
- date_closed = fields.Datetime('Cerrado', readonly=True)
- opportunity_id = fields.Many2one ('crm.lead', 'Oportunidad')
- create_date = fields.Datetime('Fecha de creación')
- task_type_id = fields.Many2one('crm.task.type',
- string="Tipo de Tarea", track_visibility='onchange')
- hex_value = fields.Char(
- string="Hex Value",
- related="task_type_id.color",
- store=False,
- size=7)
- def onchange_stage_id(self, cr, uid, ids, stage_id, context=None):
- return {'state': stage_id}
- def onchange_task_type(self, cr, uid, ids, task_type_id, context=None):
- return {'task_type_id': task_type_id}
- @api.one
- def action_done(self):
- if self.state == 'pending':
- self.state = 'done'
- # self.hex_value='#58ACFA'
- else:
- self.state = 'pending'
- # self.hex_value='#FA5858'
- @api.one
- def action_cancel(self):
- self.state = 'cancel'
- # self.hex_value='#A4A4A4'
- @api.multi
- def unlink(self):
- for all_id in self:
- res= self.env.cr.execute("DELETE FROM crm_task WHERE id= %s" % (all_id.id))
- return res
- # @api.multi
- # def write(self, vals):
- # vals = {
- # 'name': self.name,
- # 'date_action_next':self.date_action_next,
- # 'user_id': self.user_id.id,
- # 'partner_id': self.partner_id.id,
- # 'company_id': self.company_id.id,
- # 'description': self.description,
- # 'state': self.state,
- # 'priority': self.priority,
- # 'date_closed':self.date_closed,
- # 'opportunity_id':self.opportunity_id.id,
- # 'task_type_id': self.task_type_id.id,
- # 'hex_value': self.hex_value
- # }
- # res = super(CrmTask, self).create(vals)
- # return res
- @api.one
- def _current_datetime(self):
- now = datetime.now()
- if self.date_action_next < now.strftime("%Y-%m-%d %H:%M:00"):
- self.expired_date = True
- expired_date = fields.Boolean(string="Fecha Vencida", compute="_current_datetime", store=False)
- # @api.model
- # def create(self, vals):
- # return super(CrmTask, self).create(vals)
|