示例#1
0
    def cancel(self, cr, uid, ids, params, context=None):
        #print("test"+params)
        project_obj = self.pool.get(self._name)
        project = project_obj.browse(cr, uid, ids[0], context)
        task_obj = self.pool.get('project.task')
        ask_obj = self.pool.get('openstc.ask')

        #update intervention's tasks
        if openstc._test_params(params, ['state','cancel_reason'])!= False:
            for task in project.tasks:
                 task_obj.write(cr, uid, [task.id], {
                    'state' : params['state'],
                    'user_id': None,
                    'team_id': None,
                    'partner_id': None,
                    'date_end': None,
                    'date_start': None,
                }, context=context)

            #update intervention with cancel's reason
            project_obj.write(cr, uid, ids[0], {
                    'state' : params['state'],
                    'cancel_reason': params['cancel_reason'],
                }, context=context)

            ask_id = project.ask_id.id
            #update ask state of intervention
            if ask_id :
                ask_obj.write(cr, uid, ask_id , {
                            'state': 'finished',
                        }, context=context)
        return True;
示例#2
0
    def updateEquipment(self, cr, uid, params, task_id, context):
        equipment_obj = self.pool.get('openstc.equipment')
        equipment_lines_obj = self.pool.get('openstc.equipment.lines')
        #Update kilometers on vehucule
        if openstc._test_params(params, ['vehicule', 'km']) != False:
            equipment_obj.write(
                cr,
                uid,
                params['vehicule'], {
                    'km': 0 if params.has_key('km') == False else params['km'],
                },
                context=context)

            equipment_lines_obj.create(
                cr,
                uid, {
                    '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'],
                    'equipment_id':
                    params['vehicule'],
                    'task_id':
                    task_id
                },
                context=context)
示例#3
0
    def updateEquipment(self, cr, uid, params, task_id, context):
        equipment_obj = self.pool.get('openstc.equipment')
        equipment_lines_obj = self.pool.get('openstc.equipment.lines')
        #Update kilometers on vehucule
        if openstc._test_params(params,['vehicule','km'])!= False :
            equipment_obj.write(cr, uid, params['vehicule'], {
                    'km': 0 if params.has_key('km')== False else params['km'],
                 }, context=context)

            equipment_lines_obj.create(cr, uid, {
                    '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'],
                    'equipment_id': params['vehicule'],
                    'task_id': task_id
                }, context=context)
示例#4
0
    def cancel(self, cr, uid, ids, params, context=None):
        #print("test"+params)
        project_obj = self.pool.get(self._name)
        project = project_obj.browse(cr, uid, ids[0], context)
        task_obj = self.pool.get('project.task')
        ask_obj = self.pool.get('openstc.ask')

        #update intervention's tasks
        if openstc._test_params(params, ['state', 'cancel_reason']) != False:
            for task in project.tasks:
                task_obj.write(cr,
                               uid, [task.id], {
                                   'state': params['state'],
                                   'user_id': None,
                                   'team_id': None,
                                   'partner_id': None,
                                   'date_end': None,
                                   'date_start': None,
                               },
                               context=context)

            #update intervention with cancel's reason
            project_obj.write(cr,
                              uid,
                              ids[0], {
                                  'state': params['state'],
                                  'cancel_reason': params['cancel_reason'],
                              },
                              context=context)

            ask_id = project.ask_id.id
            #update ask state of intervention
            if ask_id:
                ask_obj.write(cr,
                              uid,
                              ask_id, {
                                  'state': 'finished',
                              },
                              context=context)
        return True
示例#5
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
示例#6
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