def schedule_tasks(self, cr, uid, ids, context=None):
        """
        Schedule task base on faces lib
        """
        if context is None:
            context = {}
        if type(ids) in (
                long,
                int,
        ):
            ids = [ids]
        task_pool = self.pool.get('project.task')
        resource_pool = self.pool.get('resource.resource')
        data_pool = self.pool.get('ir.model.data')
        data_model, day_uom_id = data_pool.get_object_reference(
            cr, uid, 'product', 'uom_day')

        for project in self.browse(cr, uid, ids, context=context):
            calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False
            start_date = project.date_start

            #Checking the Valid Phase resource allocation from project member
            flag = False
            res_missing = []
            members_ids = []
            if project.members:
                members_ids = [user.id for user in project.members]
            for phase in project.phase_ids:
                if phase.resource_ids:
                    res_ids = [re.id for re in phase.resource_ids]
                    for res in self.pool.get(
                            'project.resource.allocation').browse(
                                cr, uid, res_ids, context=context):
                        if res.resource_id.user_id.id not in members_ids:
                            res_missing += [res.resource_id.name]
                            flag = True
            if flag:
                raise osv.except_osv(
                    _('Warning !'),
                    _("Resource(s) %s is(are) not member(s) of the project '%s' ."
                      ) % (",".join(res_missing), project.name))
            #Creating resources using the member of the Project
            u_ids = [i.id for i in project.members]
            resource_objs = resource_pool.generate_resources(cr,
                                                             uid,
                                                             u_ids,
                                                             calendar_id,
                                                             context=context)
            try:
                start_date = datetime.strftime(
                    (datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d")
            except:
                raise osv.except_osv(
                    _('Error !'),
                    _('Task Scheduling is not possible.\nProject should have the Start date for scheduling.'
                      ))
            func_str = ''
            start = start_date
            minimum_time_unit = 1
            # default values
            working_hours_per_day = 24
            working_days_per_week = 7
            working_days_per_month = 30
            working_days_per_year = 365

            vacation = []
            if calendar_id:
                working_hours_per_day = 8  #TODO: it should be come from calendars
                working_days_per_week = 5
                working_days_per_month = 20
                working_days_per_year = 200
                vacation = tuple(
                    resource_pool.compute_vacation(cr,
                                                   uid,
                                                   calendar_id,
                                                   context=context))

            working_days = resource_pool.compute_working_calendar(
                cr, uid, calendar_id, context=context)

            cls_str = ''
            # Creating Resources for the Project
            for key, vals in resource_objs.items():
                cls_str += '''
    class Resource_%s(Resource):
        title = \"%s\"
        vacation = %s
        efficiency = %s
''' % (key, vals.get('name', False), vals.get(
                    'vacation', False), vals.get('efficiency', False))

            # Create a new project for each phase
            func_str += '''
def Project_%d():
    from resource.faces import Resource
    title = \"%s\"
    start = \'%s\'
    minimum_time_unit = %s
    working_hours_per_day = %s
    working_days_per_week = %s
    working_days_per_month = %s
    working_days_per_year = %s
    vacation = %s
    working_days =  %s
''' % (project.id, project.name, start, minimum_time_unit,
            working_hours_per_day, working_days_per_week, working_days_per_month,
            working_days_per_year, vacation, working_days)

            parent = False
            task_ids = []
            todo_task_ids = task_pool.search(
                cr,
                uid, [('project_id', '=', project.id),
                      ('state', 'in', ['draft', 'open', 'pending'])],
                order='sequence')
            if todo_task_ids:
                for task in task_pool.browse(cr,
                                             uid,
                                             todo_task_ids,
                                             context=context):
                    func_str += task_pool.generate_task(cr,
                                                        uid,
                                                        task.id,
                                                        parent=parent,
                                                        flag=True,
                                                        context=context)
                    if not parent:
                        parent = task
                    task_ids.append(task.id)
            func_str += cls_str

            if not project.date_start:  # or not project.members:
                raise osv.except_osv(
                    _('Error !'),
                    _('Task Scheduling is not possible.\nProject should have the Start date for scheduling.'
                      ))
            # Allocating Memory for the required Project and Phases and Resources
            exec(func_str)
            Project = eval('Project_%d' % project.id)
            project = None
            try:
                project = Task.BalancedProject(Project)
            except Exception, e:
                raise osv.except_osv(_('Error !'), e)

            for task_id in task_ids:
                task = eval("project.Task_%d" % task_id)
                start_date = task.start.to_datetime()
                end_date = task.end.to_datetime()

                task_pool.write(
                    cr,
                    uid, [task_id], {
                        'date_start': start_date.strftime('%Y-%m-%d'),
                        'date_end': end_date.strftime('%Y-%m-%d')
                    },
                    context=context)
    def schedule_tasks(self, cr, uid, ids, context=None):
        """
        Schedule tasks base on faces lib
        """
        if context is None:
            context = {}
        if type(ids) in (
                long,
                int,
        ):
            ids = [ids]
        task_pool = self.pool.get('project.task')
        resource_pool = self.pool.get('resource.resource')
        for phase in self.browse(cr, uid, ids, context=context):
            project = phase.project_id
            calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False
            start_date = project.date_start
            #Creating resources using the member of the Project
            u_ids = [i.id for i in project.members]
            resource_objs = resource_pool.generate_resources(cr,
                                                             uid,
                                                             u_ids,
                                                             calendar_id,
                                                             context=context)
            start_date = datetime.strftime(
                (datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d")
            func_str = ''
            start = start_date
            minimum_time_unit = 1
            # default values
            working_hours_per_day = 24
            working_days_per_week = 7
            working_days_per_month = 30
            working_days_per_year = 365

            vacation = []
            if calendar_id:
                working_hours_per_day = 8  #TODO: it should be come from calendars
                working_days_per_week = 5
                working_days_per_month = 20
                working_days_per_year = 200
                vacation = tuple(
                    resource_pool.compute_vacation(cr,
                                                   uid,
                                                   calendar_id,
                                                   context=context))

            working_days = resource_pool.compute_working_calendar(
                cr, uid, calendar_id, context=context)

            cls_str = ''
            # Creating Resources for the Project
            for key, vals in resource_objs.items():
                cls_str += '''
    class Resource_%s(Resource):
        title = \"%s\"
        vacation = %s
        efficiency = %s
''' % (key, vals.get('name', False), vals.get(
                    'vacation', False), vals.get('efficiency', False))

            # Create a new project for each phase
            func_str += '''
def Phase_%d():
    from resource.faces import Resource
    title = \"%s\"
    start = \'%s\'
    minimum_time_unit = %s
    working_hours_per_day = %s
    working_days_per_week = %s
    working_days_per_month = %s
    working_days_per_year = %s
    vacation = %s
    working_days =  %s
''' % (phase.id, phase.name, start, minimum_time_unit, working_hours_per_day,
            working_days_per_week, working_days_per_month, working_days_per_year,
            vacation, working_days)

            parent = False
            task_ids = []
            todo_task_ids = task_pool.search(
                cr,
                uid, [('id', 'in', map(lambda x: x.id, phase.task_ids)),
                      ('state', 'in', ['draft', 'open', 'pending'])],
                order='sequence')
            for task in task_pool.browse(cr,
                                         uid,
                                         todo_task_ids,
                                         context=context):
                func_str += task_pool.generate_task(cr,
                                                    uid,
                                                    task.id,
                                                    parent=parent,
                                                    flag=True,
                                                    context=context)
                if not parent:
                    parent = task
                task_ids.append(task.id)
            func_str += cls_str
            phase_id = phase.id
            #check known constraints before running Face algorithm in order to have the error translated
            if not phase.project_id.date_start:
                raise osv.except_osv(
                    _('Error !'),
                    _('Task Scheduling is not possible.\nProject should have the Start date for scheduling.'
                      ))
            # Allocating Memory for the required Project and Pahses and Resources
            exec(func_str)
            Phase = eval('Phase_%d' % phase.id)
            phase = None
            try:
                phase = Task.BalancedProject(Phase)
            except Exception, e:
                raise osv.except_osv(_('Error !'), e)

            for task_id in task_ids:
                task = eval("phase.Task_%d" % task_id)
                start_date = task.start.to_datetime()
                end_date = task.end.to_datetime()

                task_pool.write(
                    cr,
                    uid, [task_id], {
                        'date_start': start_date.strftime('%Y-%m-%d'),
                        'date_end': end_date.strftime('%Y-%m-%d')
                    },
                    context=context)