Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Update Gantt view automatically

Martin Varela
on 11/4/13, 9:32 AM 742 views

I have extended project.task to add task dependency, so one task can only start after that another one has finished. I´ve added a new field with the id of the previous task. When the end_date of a task is changed, if another task depends of this task, I have to update the start and end date of it. I´ve tried to do it by modifying the write method, it works but you have to reload the page to see the changes, and want it to be automatically. (The write method has another function that converts datetime to date and saves it in another field) Any suggestions?

The code:

   def _x_probar(self, cr, uid, ids, vals):
        #MVARELA - Verifico si se modifico la fecha final de la tarea (x_date_fin)
        if vals.get('date_end'):
            #MVARELA - Obtengo la fecha final
            for rec in self.browse(cr, uid, ids):
                id_reg = str(rec.id)
                fecha_final_pred = rec.date_end
            #MVARELA - Busco las tareas que tienen como predecesora a la que se le modifico la fecha final
            tareas = self.pool.get('project.task')
            ids2 = tareas.search(cr, uid, [('x_id_predecesora', '=', rec.id)])
            #MVARELA para cada una, corremos las fechas de la tarea
            #la fecha inicial es la fecha final de la predecesora, y la fecha final se corre en relacion a la inicial
            for task in self.browse(cr, uid, ids2):
                x_start = datetime.strptime(task.date_start, '%Y-%m-%d %H:%M:%S')
                x_end = datetime.strptime(task.date_end, '%Y-%m-%d %H:%M:%S')
                duracion = x_end - x_start
                self.write(cr, uid, [task.id], {'date_start': fecha_final_pred, 'date_end': datetime.strptime(fecha_final_pred, '%Y-%m-%d %H:%M:%S') + duracion}, context=None)
        return True

    def write(self, cr, uid, ids, vals, context=None):
        super(x_obvio_task, self).write(cr, uid, ids, vals, context=context)
        if isinstance(ids, (int, long)):
            ids = [ids]
        for t in self.browse(cr, uid, ids, context=context):
            if t.x_solo_fecha == True:
                if t.x_date_ini != False:
                    fecha_ini = datetime.strptime(t.x_date_ini + ' 09:00', '%Y-%m-%d %H:%M')
                    fecha_local_ini = fields.datetime.context_timestamp(cr, uid, fecha_ini, context=context) 
                    fecha_local_ini = fecha_local_ini.replace(tzinfo=None)
                    aux_ini = fecha_ini - fecha_local_ini
                    vals.update({'date_start': fecha_ini + aux_ini})
                if t.x_date_fin != False:
                    fecha_fin = datetime.strptime(t.x_date_fin + ' 18:00', '%Y-%m-%d %H:%M')
                    fecha_local_fin = fields.datetime.context_timestamp(cr, uid, fecha_fin, context=context) 
                    fecha_local_fin = fecha_local_fin.replace(tzinfo=None)
                    aux_fin = fecha_fin - fecha_local_fin
                    vals.update({'date_end': fecha_fin + aux_fin})
            self._x_probar(cr, uid, ids, vals)
            super(x_obvio_task, self).write(cr, uid, ids, vals, context=context)
            return True

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 11/4/13, 9:32 AM
Seen: 742 times
Last updated: 3/16/15, 8:10 AM