Exemplo n.º 1
0
 def __call__(self):
     path_query = CareerPath.query(self.current_userdatas.id)
     path_query = path_query.options(
         Load(CareerPath).load_only("start_date", "id"),
         joinedload("career_stage").load_only("name"),
     )
     return dict(career_path=path_query.all(),
                 user=self.current_userdatas.user,
                 title=u"Parcours de {0}".format(
                     format_account(self.current_userdatas.user, False)))
Exemplo n.º 2
0
 def __call__(self):
     path_query = CareerPath.query(self.current_userdatas.id)
     path_query = path_query.options(
         Load(CareerPath).load_only("start_date", "id"),
         joinedload("career_stage").load_only("name"),
     )
     return dict(
         career_path=path_query.all(),
         user=self.current_userdatas.user,
         title=u"Parcours de {0}".format(
             format_account(self.current_userdatas.user, False)
         )
     )
Exemplo n.º 3
0
    def get_career_path_by_stages(self):
        """
        Collect CareerPath associated to this instance and stores them by stage
        name

        :returns: A dict {'stage': [List of ordered CareerPath]}
        :rtype: dict
        """
        from autonomie.models.career_path import CareerPath
        from autonomie.models.career_stage import CareerStage
        result = {}
        for stage in CareerStage.query():
            result[stage.name] = CareerPath.query(
                self.id).filter_by(career_stage_id=stage.id).all()
        return result
Exemplo n.º 4
0
    def get_career_path_by_stages(self):
        """
        Collect CareerPath associated to this instance and stores them by stage
        name

        :returns: A dict {'stage': [List of ordered CareerPath]}
        :rtype: dict
        """
        from autonomie.models.career_path import CareerPath
        from autonomie.models.career_stage import CareerStage
        result = {}
        for stage in CareerStage.query():
            result[stage.name] = CareerPath.query(self.id).filter_by(
                career_stage_id=stage.id
            ).all()
        return result
Exemplo n.º 5
0
 def get_cae_situation_from_career_path(self, date):
     """
     Return the CaeSituation of the current user
     at the given date computed from the career path
     """
     from autonomie.models.career_path import CareerPath
     from autonomie.models.user.userdatas import CaeSituationOption
     if date is None:
         date=datetime.date.today()
     last_situation_path = CareerPath.query(self.id).filter(
         CareerPath.start_date <= date
     ).filter(
         CareerPath.cae_situation_id != None
     ).first()
     situation = CaeSituationOption.query().filter(
         CaeSituationOption.id == last_situation_path.cae_situation_id
     ).first()
     return situation
Exemplo n.º 6
0
 def get_cae_situation_from_career_path(self, date):
     """
     Return the CaeSituation of the current user
     at the given date computed from the career path
     """
     from autonomie.models.career_path import CareerPath
     from autonomie.models.user.userdatas import CaeSituationOption
     if date is None:
         date = datetime.date.today()
     last_situation_path = CareerPath.query(self.id).filter(
         CareerPath.start_date <= date
     ).filter(
         CareerPath.cae_situation_id != None
     ).first()
     if last_situation_path is None:
         return None
     else:
         situation = CaeSituationOption.query().filter(
             CaeSituationOption.id == last_situation_path.cae_situation_id
         ).first()
         return situation
def migrate_datas(situations_ids, stages_ids):
    """
    Migrate parcours's data from user_datas and related tables to career_path
    """
    from autonomie.models.career_path import CareerPath
    session = DBSESSION()
    cnx = op.get_bind()
    userdatas = cnx.execute("SELECT \
        id,\
        parcours_contract_type,\
        parcours_start_date,\
        parcours_end_date,\
        parcours_last_avenant,\
        parcours_taux_horaire,\
        parcours_taux_horaire_letters,\
        parcours_num_hours,\
        parcours_salary,\
        parcours_salary_letters,\
        parcours_employee_quality_id,\
        sortie_date,\
        sortie_motif_id,\
        sortie_type_id \
        FROM user_datas")
    for u in userdatas:
        # Diagnotic
        diagnotics = cnx.execute(
            "SELECT date FROM date_diagnostic_datas WHERE date>'2000-01-01' AND userdatas_id=%s"
            % u.id)
        for diagnotic in diagnotics:
            session.add(
                CareerPath(userdatas_id=u.id,
                           career_stage_id=stages_ids[0],
                           start_date=diagnotic.date))
        # CAPE
        capes = cnx.execute(
            "SELECT date, end_date FROM date_convention_cape_datas WHERE date>'2000-01-01' AND userdatas_id=%s"
            % u.id)
        for cape in capes:
            session.add(
                CareerPath(userdatas_id=u.id,
                           career_stage_id=stages_ids[1],
                           start_date=cape.date,
                           end_date=cape.end_date,
                           cae_situation_id=situations_ids[0],
                           stage_type="entry"))
        # DPAE
        dpaes = cnx.execute(
            "SELECT date FROM date_dpae_datas WHERE date>'2000-01-01' AND userdatas_id=%s"
            % u.id)
        for dpae in dpaes:
            session.add(
                CareerPath(userdatas_id=u.id,
                           career_stage_id=stages_ids[2],
                           start_date=dpae.date))
        # Contrat
        if u.parcours_start_date and u.parcours_contract_type is not None:
            from autonomie.models.career_path import TypeContratOption
            cdi_type = session.query(TypeContratOption).filter(
                TypeContratOption.label ==
                u.parcours_contract_type.upper()).first()
            if cdi_type:
                cdi_type_id = cdi_type.id
            else:
                cdi_type_id = None
            session.add(
                CareerPath(userdatas_id=u.id,
                           career_stage_id=stages_ids[3],
                           start_date=u.parcours_start_date,
                           end_date=u.parcours_end_date,
                           cae_situation_id=situations_ids[1],
                           stage_type="contrat",
                           type_contrat_id=cdi_type_id,
                           employee_quality_id=u.parcours_employee_quality_id,
                           taux_horaire=u.parcours_taux_horaire,
                           num_hours=u.parcours_num_hours))
        # Avenant contrat
        if u.parcours_last_avenant:
            avenants = cnx.execute(
                "SELECT date, number FROM contract_history WHERE date>'2000-01-01' AND userdatas_id=%s"
                % u.id)
            for avenant in avenants:
                model_avenant = CareerPath(userdatas_id=u.id,
                                           career_stage_id=stages_ids[4],
                                           start_date=avenant.date,
                                           stage_type="amendment",
                                           amendment_number=avenant.number)
                if u.parcours_last_avenant == avenant.date:
                    model_avenant.taux_horaire = u.parcours_taux_horaire
                    model_avenant.num_hours = u.parcours_num_hours
                session.add(model_avenant)
        # Sortie
        if u.sortie_date:
            session.add(
                CareerPath(userdatas_id=u.id,
                           career_stage_id=stages_ids[5],
                           start_date=u.sortie_date,
                           cae_situation_id=situations_ids[2],
                           stage_type="exit",
                           type_sortie_id=u.sortie_type_id,
                           motif_sortie_id=u.sortie_motif_id))
        # Historique des situations
        changes = cnx.execute(
            "SELECT date, situation_id FROM cae_situation_change WHERE date>'2000-01-01' AND userdatas_id=%s"
            % u.id)
        for change in changes:
            session.add(
                CareerPath(userdatas_id=u.id,
                           start_date=change.date,
                           cae_situation_id=change.situation_id))
        # Sauvegarde du parcours de l'utilisateur
        session.flush()
def migrate_datas(situations_ids, stages_ids):
    """
    Migrate parcours's data from user_datas and related tables to career_path
    """
    from autonomie.models.career_path import CareerPath
    session = DBSESSION()
    cnx = op.get_bind()
    userdatas = cnx.execute("SELECT \
        id,\
        parcours_contract_type,\
        parcours_start_date,\
        parcours_end_date,\
        parcours_last_avenant,\
        parcours_taux_horaire,\
        parcours_taux_horaire_letters,\
        parcours_num_hours,\
        parcours_salary,\
        parcours_salary_letters,\
        parcours_employee_quality_id,\
        sortie_date,\
        sortie_motif_id,\
        sortie_type_id \
        FROM user_datas")
    for u in userdatas:
        # Diagnotic
        diagnotics = cnx.execute("SELECT date FROM date_diagnostic_datas WHERE date>'2000-01-01' AND userdatas_id=%s" % u.id)
        for diagnotic in diagnotics:
            session.add(CareerPath(userdatas_id=u.id, career_stage_id=stages_ids[0], start_date=diagnotic.date))
        # CAPE
        capes = cnx.execute("SELECT date, end_date FROM date_convention_cape_datas WHERE date>'2000-01-01' AND userdatas_id=%s" % u.id)
        for cape in capes:
            session.add(CareerPath(
                userdatas_id=u.id,
                career_stage_id=stages_ids[1],
                start_date=cape.date,
                end_date=cape.end_date,
                cae_situation_id=situations_ids[0],
                stage_type="entry"
            ))
        # DPAE
        dpaes = cnx.execute("SELECT date FROM date_dpae_datas WHERE date>'2000-01-01' AND userdatas_id=%s" % u.id)
        for dpae in dpaes:
            session.add(CareerPath(userdatas_id=u.id, career_stage_id=stages_ids[2], start_date=dpae.date))
        # Contrat
        if u.parcours_start_date and u.parcours_contract_type is not None:
            from autonomie.models.career_path import TypeContratOption
            cdi_type = session.query(TypeContratOption).filter(
                TypeContratOption.label==u.parcours_contract_type.upper()
            ).first()
            if cdi_type:
                cdi_type_id = cdi_type.id
            else:
                cdi_type_id = None
            session.add(CareerPath(
                userdatas_id=u.id,
                career_stage_id=stages_ids[3],
                start_date=u.parcours_start_date,
                end_date=u.parcours_end_date,
                cae_situation_id=situations_ids[1],
                stage_type="contrat",
                type_contrat_id=cdi_type_id,
                employee_quality_id=u.parcours_employee_quality_id,
                taux_horaire=u.parcours_taux_horaire,
                num_hours=u.parcours_num_hours
            ))
        # Avenant contrat
        if u.parcours_last_avenant:
            avenants = cnx.execute("SELECT date, number FROM contract_history WHERE date>'2000-01-01' AND userdatas_id=%s" % u.id)
            for avenant in avenants:
                model_avenant = CareerPath(
                    userdatas_id=u.id,
                    career_stage_id=stages_ids[4],
                    start_date=avenant.date,
                    stage_type="amendment",
                    amendment_number=avenant.number
                )
                if u.parcours_last_avenant==avenant.date:
                    model_avenant.taux_horaire=u.parcours_taux_horaire
                    model_avenant.num_hours=u.parcours_num_hours
                session.add(model_avenant)
        # Sortie
        if u.sortie_date:
            session.add(CareerPath(
                userdatas_id=u.id,
                career_stage_id=stages_ids[5],
                start_date=u.sortie_date,
                cae_situation_id=situations_ids[2],
                stage_type="exit",
                type_sortie_id=u.sortie_type_id,
                motif_sortie_id=u.sortie_motif_id
            ))
        # Historique des situations
        changes = cnx.execute("SELECT date, situation_id FROM cae_situation_change WHERE date>'2000-01-01' AND userdatas_id=%s" % u.id)
        for change in changes:
            session.add(CareerPath(userdatas_id=u.id, start_date=change.date, cae_situation_id=change.situation_id))
        # Sauvegarde du parcours de l'utilisateur
        session.flush()