def add_internal_number(session, logger):
    logger.warn("Adding internal_number to Task")
    NUMBER_TMPLS = {
        'estimation': u"{s.project.code}_{s.customer.code}_D{s.project_index}\
_{s.date:%m%y}",
        'invoice': u"{s.project.code}_{s.customer.code}_F{s.project_index}\
_{s.date:%m%y}",
        'cancelinvoice': u"{s.project.code}_{s.customer.code}_A{s.project_index}\
_{s.date:%m%y}"
    }
    from autonomie.models.task import Task
    from autonomie.models.customer import Customer
    from autonomie.models.project import Project
    from autonomie.models.project import Phase

    from sqlalchemy.orm import joinedload
    from sqlalchemy.orm import load_only

    query = Task.query().options(
        load_only("project_index", "company_index", "date", "phase_id", 'type_')
    )

    query = query.filter(
        Task.type_.in_(['invoice', 'estimation', 'cancelinvoice'])
    )
    query = query.options(joinedload(Task.customer).load_only(Customer.code))
    query = query.options(joinedload(Task.project).load_only(Project.code))

    for task in query:
        tmpl = NUMBER_TMPLS[task.type_]
        if Phase.get(task.phase_id) is None:
            session.delete(task)
        else:
            task.internal_number = tmpl.format(s=task).upper()
            session.merge(task)
Exemple #2
0
    def submit_success(self, appstruct):
        if self.factory is None:
            raise Exception("Forgot to set the factory attribute")

        name = appstruct['name']
        phase_id = appstruct['phase_id']
        phase = Phase.get(phase_id)
        project_id = appstruct['project_id']
        project = Project.get(project_id)
        customer_id = appstruct['customer_id']
        customer = Customer.get(customer_id)

        new_object = self.factory(
            self.context.company,
            customer,
            project,
            phase,
            self.request.user,
        )
        new_object.name = name

        if hasattr(self, "_more_init_attributes"):
            self._more_init_attributes(new_object, appstruct)

        self.dbsession.add(new_object)
        self.dbsession.flush()

        if hasattr(self, "_after_flush"):
            self._after_flush(new_object)

        url = self.request.route_path("/%ss/{id}" % new_object.type_,
                                      id=new_object.id)
        return HTTPFound(url)
Exemple #3
0
def add_internal_number(session, logger):
    logger.warn("Adding internal_number to Task")
    NUMBER_TMPLS = {
        'estimation': u"{s.project.code}_{s.customer.code}_D{s.project_index}\
_{s.date:%m%y}",
        'invoice': u"{s.project.code}_{s.customer.code}_F{s.project_index}\
_{s.date:%m%y}",
        'cancelinvoice': u"{s.project.code}_{s.customer.code}_A{s.project_index}\
_{s.date:%m%y}"
    }
    from autonomie.models.task import Task
    from autonomie.models.customer import Customer
    from autonomie.models.project import Project
    from autonomie.models.project import Phase

    from sqlalchemy.orm import joinedload
    from sqlalchemy.orm import load_only

    query = Task.query().options(
        load_only("project_index", "company_index", "date", "phase_id", 'type_')
    )

    query = query.filter(
        Task.type_.in_(['invoice', 'estimation', 'cancelinvoice'])
    )
    query = query.options(joinedload(Task.customer).load_only(Customer.code))
    query = query.options(joinedload(Task.project).load_only(Project.code))

    for task in query:
        tmpl = NUMBER_TMPLS[task.type_]
        if Phase.get(task.phase_id) is None:
            session.delete(task)
        else:
            task.internal_number = tmpl.format(s=task).upper()
            session.merge(task)
Exemple #4
0
    def submit_success(self, appstruct):
        logger.debug("# Duplicating a document #")

        name = appstruct['name']
        phase_id = appstruct['phase_id']
        phase = Phase.get(phase_id)
        project_id = appstruct['project_id']
        project = Project.get(project_id)
        customer_id = appstruct['customer_id']
        customer = Customer.get(customer_id)

        task = self.context.duplicate(
            self.request.user,
            project,
            phase,
            customer,
        )
        task.name = name
        task.course = appstruct['course']
        self.dbsession.add(task)
        self.dbsession.flush()
        logger.debug(
            u"The {t.type_} {t.id} has been duplicated to {new_t.id}".format(
                t=self.context, new_t=task))
        return HTTPFound(
            self.request.route_path('/%ss/{id}' % self.context.type_,
                                    id=task.id))
Exemple #5
0
 def pre_phasechange_process(self, task, status, params):
     """
         pre process method for phase changing
     """
     form = get_phasechange_form(self.request)
     appstruct = form.validate(params.items())
     log.debug(u" * Form has been validated")
     phase_id = appstruct.get('phase')
     phase = Phase.get(phase_id)
     appstruct['phase'] = phase
     return appstruct
Exemple #6
0
    def __call__(self):
        phase_id = self.request.params.get('phase')
        if phase_id:
            phase = Phase.get(phase_id)
            if phase in self.context.project.phases:
                self.context.phase_id = phase_id
                self.request.dbsession.merge(self.context)

        return HTTPFound(
            self.request.route_path(PROJECT_ITEM_PHASE_ROUTE,
                                    id=self.context.project_id,
                                    _query={'phase': phase_id}))
Exemple #7
0
def test_editphase(config, dbsession, project, get_csrf_request_with_db):
    from autonomie.views.project import PhaseEditFormView
    from autonomie.models.project import Phase
    phase = Phase(name='test', project=project)
    dbsession.merge(phase)
    dbsession.flush()

    config.add_route('project/{id}', '/')
    req = get_csrf_request_with_db()
    req.context = phase
    view = PhaseEditFormView(req)
    view.submit_success({'name': u'Phasé'})
    dbsession.flush()
    phase = Phase.get(phase.id)
    assert (phase.name == u'Phasé')
Exemple #8
0
def test_editphase(config, dbsession, project, get_csrf_request_with_db):
    from autonomie.views.project import PhaseEditFormView
    from autonomie.models.project import Phase
    phase = Phase(name='test', project=project)
    dbsession.merge(phase)
    dbsession.flush()

    config.add_route('project/{id}', '/')
    req = get_csrf_request_with_db()
    req.context = phase
    view = PhaseEditFormView(req)
    view.submit_success({'name': u'Phasé'})
    dbsession.flush()
    phase = Phase.get(phase.id)
    assert(phase.name == u'Phasé')
Exemple #9
0
    def __call__(self):
        phase_id = self.request.params.get('phase')
        if phase_id:
            phase = Phase.get(phase_id)
            if phase in self.context.project.phases:
                self.context.phase_id = phase_id
                self.request.dbsession.merge(self.context)

        return HTTPFound(
            self.request.route_path(
                PROJECT_ITEM_PHASE_ROUTE,
                id=self.context.project_id,
                _query={'phase': phase_id}
            )
        )
Exemple #10
0
def get_latest_phase(request, phases):
    """
    Return the phase where we can identify the last modification
    :param list phases: The list of phases of the given project
    """
    result = 0
    if 'phase' in request.GET:
        result = Phase.get(request.GET['phase'])

    else:
        # We get the latest used task and so we get the latest used phase
        all_tasks = []
        for phase in phases:
            all_tasks.extend(phase.tasks)
        all_tasks.sort(key=lambda task: task.status_date, reverse=True)

        if all_tasks:
            result = all_tasks[0].phase
    return result
Exemple #11
0
 def pre_duplicate_process(self, task, status, params):
     """
         Common pre process method for document duplication
     """
     form = get_duplicate_form(self.request)
     # if an error is raised here, it will be cached a level higher
     appstruct = form.validate(params.items())
     logger.debug(u" * Form has been validated")
     customer_id = appstruct.get('customer')
     customer = Customer.get(customer_id)
     project_id = appstruct.get('project')
     project = Project.get(project_id)
     phase_id = appstruct.get('phase')
     phase = Phase.get(phase_id)
     logger.debug(u" * Phase : %s" % phase)
     logger.debug(u" * Project : %s" % project)
     appstruct['phase'] = phase
     appstruct['project'] = project
     appstruct['customer'] = customer
     appstruct['user'] = self.request.user
     return appstruct
Exemple #12
0
 def pre_duplicate_process(self, task, status, params):
     """
         Common pre process method for document duplication
     """
     form = get_duplicate_form(self.request)
     # if an error is raised here, it will be cached a level higher
     appstruct = form.validate(params.items())
     log.debug(u" * Form has been validated")
     customer_id = appstruct.get('customer')
     customer = Customer.get(customer_id)
     project_id = appstruct.get('project')
     project = Project.get(project_id)
     phase_id = appstruct.get('phase')
     phase = Phase.get(phase_id)
     log.debug(u" * Phase : %s" % phase)
     log.debug(u" * Project : %s" % project)
     appstruct['phase'] = phase
     appstruct['project'] = project
     appstruct['customer'] = customer
     appstruct['user'] = self.request.user
     return appstruct