Skip to content

Commit

Permalink
Merge pull request #722 from rufener/reactivation_affaire
Browse files Browse the repository at this point in the history
Réactivation de l'affaire
  • Loading branch information
rufener authored Mar 9, 2023
2 parents 40e0353 + bf80cdf commit a5c6c04
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 378 deletions.
2 changes: 2 additions & 0 deletions back/infolica/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def includeme(config):
config.add_route('affaire_attribution_change_state', '/infolica/api/affaire_attribution_change_state')
config.add_route('loadfile_bf_rp', '/infolica/api/loadfile_bf_rp')
config.add_route('save_bf_rp', '/infolica/api/save_bf_rp')
config.add_route('activer_affaire', '/infolica/api/activer_affaire')
#Factures
config.add_route('factures', '/infolica/api/factures')
config.add_route('factures_s', '/infolica/api/factures/')
Expand Down Expand Up @@ -114,6 +115,7 @@ def includeme(config):
config.add_route('etapes_s','/infolica/api/etapes/')
config.add_route('etapes_index','/infolica/api/etapes_index')
config.add_route('etapes_index_s','/infolica/api/etapes_index/')
config.add_route('etapes_index_by_affaire_id','/infolica/api/etape_index_by_affaire_id')
config.add_route('affaire_etapes_by_affaire_id','/infolica/api/affaire_etapes/{id}')
config.add_route('controle_etape','/infolica/api/controle_etape')
#Numeros affaires
Expand Down
26 changes: 25 additions & 1 deletion back/infolica/scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sqlalchemy import String
from sqlalchemy.sql.expression import cast
from infolica.models.models import Preavis, PreavisRemarque, Plan
from infolica.models.models import Numero, AffaireNumero
from infolica.models.models import Numero, AffaireNumero, AffaireEtape
from infolica.models.models import Role, ReservationNumerosMO, Operateur
from infolica.scripts.authentication import get_user_functions, check_connected

Expand Down Expand Up @@ -366,5 +366,29 @@ def generate_file_from_template(cls, request, template, data, output_file_name,
doc.save(file_path)

return filename


@classmethod
def newAffaireEtape(cls, request, affaire_id, etape_id, remarque=None, operateur_id=None, datetime_=None):

if datetime_ is None:
datetime_ = datetime.now()

if operateur_id is None:
operateur_id = cls.getOperateurFromUser(request).id,

params = Utils._params(
affaire_id = affaire_id,
etape_id = etape_id,
operateur_id = operateur_id,
datetime = datetime_,
remarque = remarque
)

record = AffaireEtape()
record = Utils.set_model_record(record, params)
request.dbsession.add(record)

return


81 changes: 81 additions & 0 deletions back/infolica/views/affaire.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from infolica.models.models import ModificationAffaire, VAffaire, Facture, Client
from infolica.models.models import ControleGeometre, ControleMutation, ControlePPE, SuiviMandat
from infolica.models.models import AffaireEtape, AffaireEtapeIndex, Preavis
from infolica.models.models import AffaireNumero, Numero, NumeroEtatHisto, NumeroRelation
from infolica.scripts.mail_templates import MailTemplates
from infolica.scripts.utils import Utils
from infolica.scripts.authentication import check_connected
Expand Down Expand Up @@ -848,3 +849,83 @@ def guichet_rf_saisie_pm_view(request):
}

return result


def _reopen_affaire(request, affaire_id):
affaire = request.dbsession.query(Affaire).filter(Affaire.id == affaire_id).first()

affaire.date_envoi = None
affaire.date_cloture = None
affaire.date_validation = None
affaire.abandon = False
affaire.urgent = False
affaire.urgent_echeance = None
affaire.attribution = None

return


def _reinitialiser_etat_numero(request, affaire_id, numeros_type_id, nouvel_etat_id):
# numéros
numeros = request.dbsession.query(Numero).join(
AffaireNumero, AffaireNumero.numero_id == Numero.id
).filter(
AffaireNumero.affaire_id == affaire_id,
AffaireNumero.type_id == numeros_type_id
).all()

for num in numeros:
num.etat_id = nouvel_etat_id

neh = NumeroEtatHisto()
neh.numero_id = num.id
neh.numero_etat_id = nouvel_etat_id
neh.date = datetime.strftime(datetime.now(), '%Y-%m-%d')
request.dbsession.add(neh)

return


def _remove_balance(request, affaire_id):
nr = request.dbsession.query(NumeroRelation).filter(NumeroRelation.affaire_id == affaire_id).all()
for num_rel_i in nr:
request.dbsession.delete(num_rel_i)
return


@view_config(route_name='activer_affaire', request_method='POST', renderer='json')
def activer_affaire_view(request):
"""
Re-activate affaire
"""
# Check connected
if not check_connected(request):
raise exc.HTTPForbidden()

affaire_id = request.params['affaire_id'] if 'affaire_id' in request.params else None
etape_id = request.params['etape_id'] if 'etape_id' in request.params else None

if affaire_id is None or etape_id is None:
exc.HTTPBadRequest('Il manque un paramètre à la requête (affaire_id et etape_id).')

### Affaire
_reopen_affaire(request, affaire_id)

### Numéros
affaire_numero_type_ancien_id = request.registry.settings['affaire_numero_type_ancien_id']
affaire_numero_type_nouveau_id = request.registry.settings['affaire_numero_type_nouveau_id']
numero_projet_id = request.registry.settings['numero_projet_id']
numero_vigueur_id = request.registry.settings['numero_vigueur_id']
# anciens numéros
_reinitialiser_etat_numero(request, affaire_id, numeros_type_id=affaire_numero_type_nouveau_id, nouvel_etat_id=numero_projet_id)

# Nouveaux numéros
_reinitialiser_etat_numero(request, affaire_id, numeros_type_id=affaire_numero_type_ancien_id, nouvel_etat_id=numero_vigueur_id)

# Effacer la balance
_remove_balance(request, affaire_id)

# set new affaire_etape
Utils.newAffaireEtape(request, affaire_id, etape_id, remarque="RÉACTIVATION DE L'AFFAIRE")

return exc.HTTPOk('Affaire réactivée avec succès. L''état des numéros liés à l''affaire a été réinitialisé.' )
49 changes: 48 additions & 1 deletion back/infolica/views/affaire_etape.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from infolica.exceptions.custom_error import CustomError
from infolica.models.constant import Constant
from infolica.models.models import AffaireEtape, AffaireEtapeIndex, VEtapesAffaires
from infolica.models.models import Affaire, VAffaire, Facture
from infolica.models.models import Affaire, VAffaire, AffaireType, Facture
from infolica.scripts.mail_templates import MailTemplates
from infolica.scripts.utils import Utils
from infolica.scripts.authentication import check_connected
Expand All @@ -18,6 +18,53 @@
###########################################################
# ETAPES AFFAIRE
###########################################################
@view_config(route_name='etapes_index_by_affaire_id', request_method='GET', renderer='json')
def etape_index_by_affaire_id_view(request):
"""
GET etape index by affaire_id
"""
# Check connected
if not check_connected(request):
raise exc.HTTPForbidden()

affaire_id = request.params['affaire_id'] if 'affaire_id' in request.params else None

if affaire_id is None:
raise exc.HTTPBadRequest(detail="Aucun index spécifié")

etape = request.dbsession.query(
AffaireEtapeIndex
).join(
AffaireEtape, AffaireEtape.etape_id == AffaireEtapeIndex.id
).filter(
AffaireEtape.affaire_id == affaire_id,
AffaireEtapeIndex.ordre != None
).order_by(AffaireEtape.datetime.desc()).limit(1).first()

# get next step id
logique_processus = request.dbsession.query(
AffaireType.logique_processus
).join(
Affaire, Affaire.type_id == AffaireType.id
).filter(
Affaire.id == affaire_id
).scalar()

next_step_id = None
if logique_processus is not None and etape.id in logique_processus:
idx = logique_processus.index(etape.id)

if idx < len(logique_processus)-1:
next_step_id = logique_processus[idx + 1]

data = {
'etape': etape.nom if etape is not None else None,
'predicted_next_step_id': next_step_id
}

return data


@view_config(route_name='etapes_index', request_method='GET', renderer='json')
@view_config(route_name='etapes_index_s', request_method='GET', renderer='json')
def etapes_index_view(request):
Expand Down
2 changes: 2 additions & 0 deletions front/.env
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ VUE_APP_MODIFICATION_AFFAIRE_BY_AFFAIRE_FILLE_ENDPOINT = "/modification_affaire_
VUE_APP_AFFAIRES_COCKPIT_ENDPOINT = "/affaires_cockpit"
VUE_APP_ABANDON_AFFAIRE_REOUVERTURE_AFFAIRE_PARENT_ENDPOINT = "/abandon_affaire_reopen_parent_affaire"
VUE_APP_AFFAIRE_ATTRIBUTION_CHANGE_STATE_ENDPOINT = "/affaire_attribution_change_state"
VUE_APP_ACTIVATE_AFFAIRE_ENDPOINT = "/activer_affaire"

#Preavis
VUE_APP_PREAVIS_ENDPOINT = "/preavis"
Expand Down Expand Up @@ -111,6 +112,7 @@ VUE_APP_EXPORT_EMOLUMENTS_PDF_ENDPOINT = "/export_emoluments_pdf"

#Etapes de l'affaire
VUE_APP_ETAPES_INDEX_ENDPOINT = "/etapes_index/"
VUE_APP_ETAPE_INDEX_BY_AFFAIRE_ID_ENDPOINT = "/etape_index_by_affaire_id"

#Numéros relations
VUE_APP_NUMERO_RELATIONS_BASE_ENDPOINT = "/numero_base_relations/"
Expand Down
Loading

0 comments on commit a5c6c04

Please sign in to comment.