Beispiel #1
0
    def createWork(self, cr, uid, task, params, context):
        task_obj = self.pool.get('project.task')
        task_work_obj = self.pool.get('project.task.work')
        #update task work
        work_id = task_work_obj.create(cr, uid, {
             'name': task.name,
             #TODO : manque l'heure
             'date':  datetime.now().strftime('%Y-%m-%d') if params.has_key('date')== False  else params['date'],
             'task_id': task.id,
             'hours':  openstc._get_param(params, 'report_hours'),
             'user_id': task.user_id.id or False,
             'team_id': task.team_id.id or False,
             'partner_id': task.partner_id.id or False,
             'company_id': task.company_id.id or False,
            }, context=context)

        work_consumables_obj = self.pool.get('openstc.task.work.consumables')
        if params.has_key('consumables'):
            consumables = params['consumables']
            for consumable in consumables:
                  work_consumable_id = work_consumables_obj.create(cr, uid, {
                     'dqe': '' if consumable['dqe']== False else consumable['dqe'],
                     'quantity':  0 if consumable['quantity']== False else consumable['quantity'],
                     'unit_price': 0 if consumable['unit_price']== False else consumable['unit_price'],
                     'work_id': work_id,
                     'consumable_id': consumable['id']
                    }, context=context)
Beispiel #2
0
    def write(self, cr, uid, ids, vals, context=None):
        #if we want to cancel task, we update some values automatically
        if 'state' in vals and vals['state'] == 'cancelled':
            for mTask in self.browse(cr, uid, ids, context=context):
                if mTask.state <> 'cancelled':
                    values = {}
                    values.update({
                        'cancel_reason':
                        openstc._get_param(vals, 'cancel_reason')
                    })
                    values.update({'remaining_hours': 0.0})
                    vals.update(values)
                    if not mTask.date_end:
                        vals.update(
                            {'date_end': time.strftime('%Y-%m-%d %H:%M:%S')})
                    super(task, self).write(cr,
                                            uid, [mTask.id],
                                            vals,
                                            context=context)
                    self.pool.get("project.project").action_finished(
                        cr, uid, [mTask.project_id.id])
        else:
            res = super(task, self).write(cr, uid, ids, vals, context=context)
            #if task(s) have hours to report, we update task works and those tasks
            if not isinstance(ids, list):
                ids = [ids]
            self.reportHours(cr, uid, ids, vals, context=context)

        return True
Beispiel #3
0
    def createWork(self, cr, uid, task, params, context):
        task_obj = self.pool.get('project.task')
        task_work_obj = self.pool.get('project.task.work')
        #update task work
        work_id = task_work_obj.create(
            cr,
            uid,
            {
                'name':
                task.name,
                #TODO : manque l'heure
                'date':
                datetime.now().strftime('%Y-%m-%d')
                if params.has_key('date') == False else params['date'],
                'task_id':
                task.id,
                'hours':
                openstc._get_param(params, 'report_hours'),
                'user_id':
                task.user_id.id or False,
                'team_id':
                task.team_id.id or False,
                'partner_id':
                task.partner_id.id or False,
                'company_id':
                task.company_id.id or False,
            },
            context=context)

        work_consumables_obj = self.pool.get('openstc.task.work.consumables')
        if params.has_key('consumables'):
            consumables = params['consumables']
            for consumable in consumables:
                work_consumable_id = work_consumables_obj.create(
                    cr,
                    uid, {
                        'dqe':
                        ''
                        if consumable['dqe'] == False else consumable['dqe'],
                        'quantity':
                        0 if consumable['quantity'] == False else
                        consumable['quantity'],
                        'unit_price':
                        0 if consumable['unit_price'] == False else
                        consumable['unit_price'],
                        'work_id':
                        work_id,
                        'consumable_id':
                        consumable['id']
                    },
                    context=context)
Beispiel #4
0
    def cancel(self, cr, uid, ids, params, context={}):
        """
        Cancel Task
        """
        if not isinstance(ids,list): ids = [ids]
        for task in self.browse(cr, uid, ids, context=context):
            if task.state <> 'cancelled':
                vals = {}

                vals.update({'state': 'cancelled'})
                vals.update({'cancel_reason': openstc._get_param(params, 'cancel_reason') })
                vals.update({'remaining_hours': 0.0})
                if not task.date_end:
                    vals.update({ 'date_end':time.strftime('%Y-%m-%d %H:%M:%S')})
                self.write(cr, uid, [task.id],vals, context=context)
            #message = _("The task '%s' is done") % (task.name,)
            #self.log(cr, uid, task.id, message)
        return True
Beispiel #5
0
    def write(self, cr, uid, ids, vals, context=None):
        #if we want to cancel task, we update some values automatically
        if 'state' in vals and vals['state'] == 'cancelled':
            for mTask in self.browse(cr, uid, ids, context=context):
                if mTask.state <> 'cancelled':
                    values = {}
                    values.update({'cancel_reason': openstc._get_param(vals, 'cancel_reason') })
                    values.update({'remaining_hours': 0.0})
                    vals.update(values)
                    if not mTask.date_end:
                        vals.update({ 'date_end':time.strftime('%Y-%m-%d %H:%M:%S')})
                    super(task,self).write(cr, uid, [mTask.id],vals, context=context)
                    self.pool.get("project.project").action_finished(cr, uid, [mTask.project_id.id])
        else:
            res = super(task, self).write(cr, uid, ids, vals, context=context)
            #if task(s) have hours to report, we update task works and those tasks
            if not isinstance(ids, list):
                ids = [ids]
            self.reportHours(cr, uid, ids, vals, context=context)

        return True
Beispiel #6
0
    def cancel(self, cr, uid, ids, params, context={}):
        """
        Cancel Task
        """
        if not isinstance(ids, list): ids = [ids]
        for task in self.browse(cr, uid, ids, context=context):
            if task.state <> 'cancelled':
                vals = {}

                vals.update({'state': 'cancelled'})
                vals.update({
                    'cancel_reason':
                    openstc._get_param(params, 'cancel_reason')
                })
                vals.update({'remaining_hours': 0.0})
                if not task.date_end:
                    vals.update(
                        {'date_end': time.strftime('%Y-%m-%d %H:%M:%S')})
                self.write(cr, uid, [task.id], vals, context=context)
            #message = _("The task '%s' is done") % (task.name,)
            #self.log(cr, uid, task.id, message)
        return True
Beispiel #7
0
    def reportHours(self, cr, uid, ids, params, context=None):

        #report_hours
        #remaining_hours

        task_obj = self.pool.get(self._name)
        #Get current task
        task = task_obj.browse(cr, uid, ids[0], context)
        #do nothing if task no found or not report hours
        if task==None or task == False : return False
        if not openstc._get_param(params, 'report_hours') : return False
        project = None
        project_obj = self.pool.get('project.project')
        ask_obj = self.pool.get('openstc.ask')
        #Get intervention's task
        if task.project_id!=None and task.project_id!=False :
            if task.project_id.id > 0 :
                project = project_obj.browse(cr, uid, [task.project_id.id], context=context)[0]
                #update intervention state
                if (project.state != 'template'):
                    #update intervention state  : pending because remaining_hours>0
                    project_obj.write(cr, uid, project.id, {
                        'state': 'pending',
                    }, context=context)

        #Prepare equipment list
        if params.has_key('equipment_ids') and len(params['equipment_ids'])>0 :
            equipment_ids = params['equipment_ids']
            if not isinstance(equipment_ids[0], list) and not isinstance(equipment_ids[0], tuple):
                equipment_ids = [(6,0,equipment_ids)]
        else :
            equipment_ids = []

        #Prepare consumable list
        consumable_ids = []
        if params.has_key('consumables') and len(params['consumables'])>0 :
            for consumable in params['consumables']:
                if consumable['id'] not in consumable_ids :
                    consumable_ids.append(consumable['id'])

        #update mobile equipment kilometers
        self.updateEquipment(cr, uid, params, ids[0], context)


        #Records report time
        self.createWork(cr, uid, task, params, context)

        #TODO cost calculation
        task = self.browse(cr, uid, ids[0], context=context)
        cost=hr_cost=equipment_cost=consumable_cost = 0.0
        for task_work in task.work_ids:
            presta_cost = 0.0 if params.has_key('cost')== False or params['cost']== '' else float(params['cost'])
            hr_cost += self._get_hr_cost(cr, uid, task, task_work, presta_cost , context)
            equipment_cost +=   self._get_equipment_cost(cr, uid, task, task_work, context)
            consumable_cost +=  self._get_consumable_cost(cr, uid, task, task_work, context)
        cost = hr_cost + equipment_cost + consumable_cost

        self.__logger.warning('----------------- Write task %s ------------------------------', ids[0])
        #Update Task
        task_obj.write(cr, uid, ids[0], {
                'state': 'done',
                'date_start': task.date_start or openstc._get_param(params, 'date_start'),
                'date_end': task.date_end or openstc._get_param(params, 'date_end'),
                'team_id': task.team_id and task.team_id.id or openstc._get_param(params, 'team_id'),
                'user_id': task.user_id and task.user_id.id or openstc._get_param(params, 'user_id'),
                'partner_id': task.partner_id and task.partner_id.id or openstc._get_param(params, 'partner_id'),
                'cost': cost ,
                'hr_cost': hr_cost ,
                'equipment_cost': equipment_cost ,
                'consumable_cost': consumable_cost ,
                'equipment_ids': equipment_ids,
                'consumable_ids': [(6,0,consumable_ids)],
                'remaining_hours': 0,
                'km': 0 if params.has_key('km')== False else params['km'],
                'oil_qtity': 0 if params.has_key('oil_qtity')== False else params['oil_qtity'],
                'oil_price': 0 if params.has_key('oil_price')== False else params['oil_price'],
            }, context=context)

        if openstc._test_params(params,['remaining_hours'])!=False:
            #Not finnished task : Create new task for planification
            task_obj.create(cr, uid, {
                 'name'              : task.name,
                 'parent_id'         : task.id,
                 'project_id'        : task.project_id.id or False,
                 'state'             : 'draft',
                 'planned_hours'     : 0 if params.has_key('remaining_hours')== False else params['remaining_hours'],
                 'remaining_hours'   : 0 if params.has_key('remaining_hours')== False else params['remaining_hours'],
                 'user_id'           : None,
                 'team_id'           : None,
                 'partner_id'        : None,
                 'date_end'          : None,
                 'date_start'        : None,
             }, context)
        else:
            #Finnished task
            if project:
                project_obj.check_remaining_tasks_and_validate(cr, uid, project.id, context=context)

        return True
Beispiel #8
0
    def reportHours(self, cr, uid, ids, params, context=None):

        #report_hours
        #remaining_hours

        task_obj = self.pool.get(self._name)
        #Get current task
        task = task_obj.browse(cr, uid, ids[0], context)
        #do nothing if task no found or not report hours
        if task == None or task == False: return False
        if not openstc._get_param(params, 'report_hours'): return False
        project = None
        project_obj = self.pool.get('project.project')
        ask_obj = self.pool.get('openstc.ask')
        #Get intervention's task
        if task.project_id != None and task.project_id != False:
            if task.project_id.id > 0:
                project = project_obj.browse(cr,
                                             uid, [task.project_id.id],
                                             context=context)[0]
                #update intervention state
                if (project.state != 'template'):
                    #update intervention state  : pending because remaining_hours>0
                    project_obj.write(cr,
                                      uid,
                                      project.id, {
                                          'state': 'pending',
                                      },
                                      context=context)

        #Prepare equipment list
        if params.has_key('equipment_ids') and len(
                params['equipment_ids']) > 0:
            equipment_ids = params['equipment_ids']
            if not isinstance(equipment_ids[0], list) and not isinstance(
                    equipment_ids[0], tuple):
                equipment_ids = [(6, 0, equipment_ids)]
        else:
            equipment_ids = []

        #Prepare consumable list
        consumable_ids = []
        if params.has_key('consumables') and len(params['consumables']) > 0:
            for consumable in params['consumables']:
                if consumable['id'] not in consumable_ids:
                    consumable_ids.append(consumable['id'])

        #update mobile equipment kilometers
        self.updateEquipment(cr, uid, params, ids[0], context)

        #Records report time
        self.createWork(cr, uid, task, params, context)

        #TODO cost calculation
        task = self.browse(cr, uid, ids[0], context=context)
        cost = hr_cost = equipment_cost = consumable_cost = 0.0
        for task_work in task.work_ids:
            presta_cost = 0.0 if params.has_key(
                'cost') == False or params['cost'] == '' else float(
                    params['cost'])
            hr_cost += self._get_hr_cost(cr, uid, task, task_work, presta_cost,
                                         context)
            equipment_cost += self._get_equipment_cost(cr, uid, task,
                                                       task_work, context)
            consumable_cost += self._get_consumable_cost(
                cr, uid, task, task_work, context)
        cost = hr_cost + equipment_cost + consumable_cost

        self.__logger.warning(
            '----------------- Write task %s ------------------------------',
            ids[0])
        #Update Task
        task_obj.write(
            cr,
            uid,
            ids[0], {
                'state':
                'done',
                'date_start':
                task.date_start or openstc._get_param(params, 'date_start'),
                'date_end':
                task.date_end or openstc._get_param(params, 'date_end'),
                'team_id':
                task.team_id and task.team_id.id
                or openstc._get_param(params, 'team_id'),
                'user_id':
                task.user_id and task.user_id.id
                or openstc._get_param(params, 'user_id'),
                'partner_id':
                task.partner_id and task.partner_id.id
                or openstc._get_param(params, 'partner_id'),
                'cost':
                cost,
                'hr_cost':
                hr_cost,
                'equipment_cost':
                equipment_cost,
                'consumable_cost':
                consumable_cost,
                'equipment_ids':
                equipment_ids,
                'consumable_ids': [(6, 0, consumable_ids)],
                'remaining_hours':
                0,
                'km':
                0 if params.has_key('km') == False else params['km'],
                'oil_qtity':
                0 if params.has_key('oil_qtity') == False else
                params['oil_qtity'],
                'oil_price':
                0 if params.has_key('oil_price') == False else
                params['oil_price'],
            },
            context=context)

        if openstc._test_params(params, ['remaining_hours']) != False:
            #Not finnished task : Create new task for planification
            task_obj.create(
                cr, uid, {
                    'name':
                    task.name,
                    'parent_id':
                    task.id,
                    'project_id':
                    task.project_id.id or False,
                    'state':
                    'draft',
                    'planned_hours':
                    0 if params.has_key('remaining_hours') == False else
                    params['remaining_hours'],
                    'remaining_hours':
                    0 if params.has_key('remaining_hours') == False else
                    params['remaining_hours'],
                    'user_id':
                    None,
                    'team_id':
                    None,
                    'partner_id':
                    None,
                    'date_end':
                    None,
                    'date_start':
                    None,
                }, context)
        else:
            #Finnished task
            if project:
                project_obj.check_remaining_tasks_and_validate(cr,
                                                               uid,
                                                               project.id,
                                                               context=context)

        return True