Beispiel #1
0
def other_project_type(dbsession, mk_business_type):
    other_business_type = mk_business_type(name="other")
    from autonomie.models.project.types import ProjectType
    result = ProjectType(name="other", label="other")
    result.default_business_type = other_business_type
    dbsession.add(result)
    dbsession.flush()
    return result
Beispiel #2
0
def project_type(dbsession, default_business_type, mk_business_type):
    from autonomie.models.project.types import ProjectType
    proj = ProjectType(name="default", label=u"Par défaut")
    other_business_type = mk_business_type(name="other", label=u"Cycle long")
    proj.other_business_types.append(other_business_type)
    proj.default_business_type = default_business_type
    dbsession.add(proj)
    dbsession.flush()
    default_business_type.project_type = proj
    return proj
Beispiel #3
0
def migrate_datas():
    from autonomie_base.models.base import DBSESSION
    session = DBSESSION()
    from autonomie.models.populate import populate_project_types
    populate_project_types(session)

    from autonomie.models.project.types import (
        ProjectType,
        BusinessType,
    )

    from autonomie.models.populate import populate_project_types
    populate_project_types(session)

    default_ptype_id = ProjectType.get_default().id
    default_btype_id = BusinessType.get_default().id

    course_ptype_id = ProjectType.query().filter_by(name='training').first().id
    course_btype_id = BusinessType.query().filter_by(
        name='training').first().id

    op.execute("update project set project_type_id=%s" % default_ptype_id)

    op.execute("update task set version='4.1'")

    for typ_ in ('estimation', 'invoice'):
        query = "update task join {type_} on {type_}.id=task.id set \
business_type_id={btype_id} where {type_}.course={course}"

        op.execute(
            query.format(type_=typ_, btype_id=default_btype_id, course=0))
        op.execute(query.format(type_=typ_, btype_id=course_btype_id,
                                course=1))

        query2 = "update project set project_type_id={ptype_id} where \
(select count(task.id) from task join {type_} on {type_}.id=task.id \
where {type_}.course=1 and task.project_id=project.id ) > 0;"

        op.execute(query2.format(
            type_=typ_,
            ptype_id=course_ptype_id,
        ))

    query = "update task join cancelinvoice on cancelinvoice.id=task.id set \
business_type_id={btype_id}".format(btype_id=default_btype_id)
    op.execute(query)
    query = "update task join cancelinvoice on cancelinvoice.id=task.id join \
task as task2 on cancelinvoice.invoice_id=task2.id set \
task.business_type_id={btype_id} where task2.business_type_id=4".format(
        btype_id=course_btype_id)
    op.execute(query)

    _add_business_to_all_invoices(session)
 def func(name, label=None, default_btype=default_business_type,
          other_business_types=[]):
     if label is None:
         label = name
     if not hasattr(other_business_types, '__iter__'):
         other_business_types = [other_business_types]
     ptype = ProjectType(name=name, label=label)
     ptype.default_business_type = default_btype
     ptype.other_business_types = other_business_types
     dbsession.add(ptype)
     dbsession.flush()
     default_btype.project_type = ptype
     return ptype
Beispiel #5
0
 def func(name,
          label=None,
          default_btype=default_business_type,
          other_business_types=[]):
     if label is None:
         label = name
     if not hasattr(other_business_types, '__iter__'):
         other_business_types = [other_business_types]
     ptype = ProjectType(name=name, label=label)
     ptype.default_business_type = default_btype
     ptype.other_business_types = other_business_types
     dbsession.add(ptype)
     dbsession.flush()
     default_btype.project_type = ptype
     return ptype
Beispiel #6
0
 def __call__(self):
     for item in ProjectType.query():
         item.default = False
         self.request.dbsession.merge(item)
     self.context.default = True
     self.request.dbsession.merge(item)
     return HTTPFound(self.back_link)
Beispiel #7
0
 def load_items(self):
     """
     Return the sqlalchemy models representing current queried elements
     :rtype: SQLAlchemy.Query object
     """
     items = ProjectType.query()
     items = items.order_by(self.factory.default).order_by(self.factory.name)
     return items
Beispiel #8
0
def populate_project_types(session):
    from autonomie.models.project.types import (
        ProjectType,
        BusinessType,
    )
    for name, label, subtype_label, private, default in (
        (
            "default",
            u"Projet classique",
            "Affaire simple",
            False,
            True,
        ),
        ("training", u"Convention de formation", "Formation", True, False),
        ("construction", u"Chantiers", u"Chantier", True, False),
    ):
        ptype = ProjectType.query().filter_by(name=name).first()
        if ptype is None:
            ptype = ProjectType(
                name=name,
                label=label,
                editable=False,
                private=private,
                default=default,
            )
            session.add(ptype)
            session.flush()
            if name is not 'default':
                default_btype = BusinessType.query().filter_by(
                    name='default').first()
                default_btype.other_project_types.append(ptype)
                session.merge(default_btype)
                session.flush()

        if session.query(BusinessType.id).filter_by(name=name).count() == 0:
            session.add(
                BusinessType(
                    name=name,
                    label=subtype_label,
                    editable=False,
                    private=private,
                    project_type_id=ptype.id,
                ))
    session.flush()
Beispiel #9
0
def _get_project_type_options(request):
    """
    collect project type options
    """
    project_types = ProjectType.query_for_select()

    context = request.context

    for project_type in project_types:
        if not project_type.private or \
                request.has_permission('add.%s' % project_type.name):
            if isinstance(context, Project):
                if not _is_compatible_project_type(context, project_type):
                    continue
            yield project_type
Beispiel #10
0
def populate_project_types(session):
    from autonomie.models.project.types import (
        ProjectType,
        BusinessType,
    )
    for name, label, subtype_label, private, default in (
        ("default", u"Projet classique", "Affaire simple", False, True,),
        ("training", u"Convention de formation", "Formation", True, False),
        ("construction", u"Chantiers", u"Chantier", True, False),
    ):
        ptype = ProjectType.query().filter_by(name=name).first()
        if ptype is None:
            ptype = ProjectType(
                name=name,
                label=label,
                editable=False,
                private=private,
                default=default,
            )
            session.add(ptype)
            session.flush()
            if name is not 'default':
                default_btype = BusinessType.query().filter_by(
                    name='default').first()
                default_btype.other_project_types.append(ptype)
                session.merge(default_btype)
                session.flush()

        if session.query(BusinessType.id).filter_by(name=name).count() == 0:
            session.add(
                BusinessType(
                    name=name,
                    label=subtype_label,
                    editable=False,
                    private=private,
                    project_type_id=ptype.id,
                )
            )
    session.flush()