forked from ScoDoc/ScoDoc
ajout siret provisoire, changement formulaire
This commit is contained in:
parent
f4514ad4ea
commit
999b0487c7
@ -10,6 +10,7 @@ from app.models import Departement
|
||||
bp = Blueprint("entreprises", __name__)
|
||||
|
||||
LOGS_LEN = 5
|
||||
SIRET_PROVISOIRE_START = "xx"
|
||||
|
||||
|
||||
@bp.app_template_filter()
|
||||
|
@ -348,6 +348,7 @@ def check_entreprise_import(entreprise_data):
|
||||
if EntreprisePreferences.get_check_siret():
|
||||
if re.match("^\d{14}$", siret) is None:
|
||||
return False
|
||||
else:
|
||||
try:
|
||||
req = requests.get(
|
||||
f"https://entreprise.data.gouv.fr/api/sirene/v1/siret/{siret}"
|
||||
|
@ -65,6 +65,7 @@ from app.entreprises.models import (
|
||||
from app import db
|
||||
from app.models import Identite, Departement
|
||||
from app.auth.models import User
|
||||
from app.entreprises import SIRET_PROVISOIRE_START
|
||||
|
||||
CHAMP_REQUIS = "Ce champ est requis"
|
||||
SUBMIT_MARGE = {"style": "margin-bottom: 10px;"}
|
||||
@ -87,9 +88,11 @@ class EntreprisesFilterForm(FlaskForm):
|
||||
|
||||
|
||||
class EntrepriseCreationForm(FlaskForm):
|
||||
siret = _build_string_field(
|
||||
"SIRET (*)",
|
||||
siret = StringField(
|
||||
"SIRET",
|
||||
validators=[Optional()],
|
||||
render_kw={"placeholder": "Numéro composé de 14 chiffres"},
|
||||
description="Laissez vide pour générer un SIRET provisoire",
|
||||
)
|
||||
association = BooleanField("Association")
|
||||
nom_entreprise = _build_string_field("Nom de l'entreprise (*)")
|
||||
@ -124,6 +127,39 @@ class EntrepriseCreationForm(FlaskForm):
|
||||
if not FlaskForm.validate(self):
|
||||
validate = False
|
||||
|
||||
if EntreprisePreferences.get_check_siret() and self.siret.data != "":
|
||||
siret_data = self.siret.data.strip().replace(" ", "")
|
||||
self.siret.data = siret_data
|
||||
if re.match("^\d{14}$", siret_data) is None:
|
||||
self.siret.errors.append("Format incorrect")
|
||||
validate = False
|
||||
else:
|
||||
try:
|
||||
req = requests.get(
|
||||
f"https://entreprise.data.gouv.fr/api/sirene/v1/siret/{siret_data}"
|
||||
)
|
||||
if req.status_code != 200:
|
||||
self.siret.errors.append("SIRET inexistant")
|
||||
validate = False
|
||||
except requests.ConnectionError:
|
||||
self.siret.errors.append(
|
||||
"Impossible de vérifier l'existance du SIRET"
|
||||
)
|
||||
validate = False
|
||||
entreprise = Entreprise.query.filter_by(siret=siret_data).first()
|
||||
if entreprise is not None:
|
||||
if entreprise.visible is True:
|
||||
lien = f'<a href="/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}">ici</a>'
|
||||
self.siret.errors.append(
|
||||
Markup(
|
||||
f"Entreprise déjà présent, lien vers la fiche : {lien}"
|
||||
)
|
||||
)
|
||||
validate = False
|
||||
else:
|
||||
self.siret.errors.append("Entreprise en phase de validation")
|
||||
validate = False
|
||||
|
||||
if (
|
||||
self.nom_correspondant.data.strip()
|
||||
or self.prenom_correspondant.data.strip()
|
||||
@ -148,12 +184,36 @@ class EntrepriseCreationForm(FlaskForm):
|
||||
|
||||
return validate
|
||||
|
||||
def validate_siret(self, siret):
|
||||
if EntreprisePreferences.get_check_siret():
|
||||
siret_data = siret.data.strip().replace(" ", "")
|
||||
self.siret.data = siret_data
|
||||
|
||||
class EntrepriseModificationForm(FlaskForm):
|
||||
siret = StringField("SIRET (*)")
|
||||
new_siret = StringField(
|
||||
"Modification du SIRET provisoire (*)",
|
||||
description="Activé uniquement pour les entreprises avec SIRET provisoire",
|
||||
)
|
||||
association = BooleanField("Association")
|
||||
nom = _build_string_field("Nom de l'entreprise (*)")
|
||||
adresse = _build_string_field("Adresse (*)")
|
||||
codepostal = _build_string_field("Code postal (*)")
|
||||
ville = _build_string_field("Ville (*)")
|
||||
pays = _build_string_field("Pays", required=False)
|
||||
submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.siret.render_kw = {"disabled": ""}
|
||||
if self.siret.data.startswith(SIRET_PROVISOIRE_START) is True:
|
||||
self.new_siret.validators = [Optional()]
|
||||
else:
|
||||
self.new_siret.render_kw = {"disabled": ""}
|
||||
|
||||
def validate_new_siret(self, new_siret):
|
||||
if EntreprisePreferences.get_check_siret() and new_siret.data is not None:
|
||||
siret_data = new_siret.data.strip().replace(" ", "")
|
||||
self.new_siret.data = siret_data
|
||||
if re.match("^\d{14}$", siret_data) is None:
|
||||
raise ValidationError("Format incorrect")
|
||||
else:
|
||||
try:
|
||||
req = requests.get(
|
||||
f"https://entreprise.data.gouv.fr/api/sirene/v1/siret/{siret_data}"
|
||||
@ -167,27 +227,14 @@ class EntrepriseCreationForm(FlaskForm):
|
||||
if entreprise.visible is True:
|
||||
lien = f'<a href="/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}">ici</a>'
|
||||
raise ValidationError(
|
||||
Markup(f"Entreprise déjà présent, lien vers la fiche : {lien}")
|
||||
Markup(
|
||||
f"Entreprise déjà présent, lien vers la fiche : {lien}"
|
||||
)
|
||||
)
|
||||
else:
|
||||
raise ValidationError("Entreprise en phase de validation")
|
||||
|
||||
|
||||
class EntrepriseModificationForm(FlaskForm):
|
||||
siret = StringField("SIRET (*)")
|
||||
association = BooleanField("Association")
|
||||
nom = _build_string_field("Nom de l'entreprise (*)")
|
||||
adresse = _build_string_field("Adresse (*)")
|
||||
codepostal = _build_string_field("Code postal (*)")
|
||||
ville = _build_string_field("Ville (*)")
|
||||
pays = _build_string_field("Pays", required=False)
|
||||
submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.siret.render_kw = {"disabled": ""}
|
||||
|
||||
|
||||
class SiteCreationForm(FlaskForm):
|
||||
hidden_entreprise_id = HiddenField()
|
||||
nom = _build_string_field("Nom du site (*)")
|
||||
|
@ -260,3 +260,19 @@ class EntreprisePreferences(db.Model):
|
||||
else:
|
||||
cs.value = check_siret
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def entreprises_reset_database():
|
||||
db.session.query(EntrepriseContact).delete()
|
||||
db.session.query(EntrepriseStageApprentissage).delete()
|
||||
db.session.query(EntrepriseTaxeApprentissage).delete()
|
||||
db.session.query(EntrepriseCorrespondant).delete()
|
||||
db.session.query(EntrepriseSite).delete()
|
||||
db.session.query(EntrepriseEnvoiOffre).delete()
|
||||
db.session.query(EntrepriseEnvoiOffreEtudiant).delete()
|
||||
db.session.query(EntrepriseOffreDepartement).delete()
|
||||
db.session.query(EntrepriseOffre).delete()
|
||||
db.session.query(Entreprise).delete()
|
||||
db.session.query(EntrepriseHistorique).delete()
|
||||
db.session.query(EntreprisePreferences).delete()
|
||||
db.session.commit()
|
||||
|
@ -10,7 +10,7 @@ from flask_login import current_user
|
||||
|
||||
from app.decorators import permission_required
|
||||
|
||||
from app.entreprises import LOGS_LEN
|
||||
from app.entreprises import LOGS_LEN, SIRET_PROVISOIRE_START
|
||||
from app.entreprises.forms import (
|
||||
ActivationConfirmationForm,
|
||||
CorrespondantsCreationForm,
|
||||
@ -331,7 +331,10 @@ def add_entreprise():
|
||||
if form.validate_on_submit():
|
||||
entreprise = Entreprise(
|
||||
nom=form.nom_entreprise.data.strip(),
|
||||
siret=form.siret.data.strip(),
|
||||
siret=form.siret.data.strip()
|
||||
if form.siret.data.strip()
|
||||
else f"{SIRET_PROVISOIRE_START}{datetime.now().strftime('%d%m%y%H%M%S')}", # siret provisoire
|
||||
siret_provisoire=False if form.siret.data.strip() else True,
|
||||
association=form.association.data,
|
||||
adresse=form.adresse.data.strip(),
|
||||
codepostal=form.codepostal.data.strip(),
|
||||
@ -409,6 +412,9 @@ def edit_entreprise(entreprise_id):
|
||||
if form.validate_on_submit():
|
||||
lien_entreprise = f"<a href=/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}>{form.nom.data.strip()}</a>"
|
||||
logs_text = []
|
||||
if form.new_siret.data:
|
||||
logs_text.append(f"{lien_entreprise} - Modification du SIRET")
|
||||
entreprise.siret = form.new_siret.data.strip()
|
||||
if entreprise.nom != form.nom.data.strip():
|
||||
logs_text.append(
|
||||
f"{lien_entreprise} - Modification du nom (ancien nom: {entreprise.nom})"
|
||||
|
16
scodoc.py
16
scodoc.py
@ -31,6 +31,7 @@ from app.models import ModuleImpl, ModuleImplInscription
|
||||
from app.models import Identite
|
||||
from app.models import departements
|
||||
from app.models.evaluations import Evaluation
|
||||
from app.entreprises.models import entreprises_reset_database
|
||||
from app.scodoc.sco_permissions import Permission
|
||||
from app.views import notes, scolar
|
||||
import tools
|
||||
@ -518,6 +519,21 @@ def recursive_help(cmd, parent=None):
|
||||
recursive_help(sub, ctx)
|
||||
|
||||
|
||||
@app.cli.command()
|
||||
def entreprises_reset_db():
|
||||
"""Remet a zéro les tables du module relations entreprises"""
|
||||
click.confirm(
|
||||
"This will erase all the tables from the blueprint 'entreprises'.\nAre you sure you want to continue?",
|
||||
abort=True,
|
||||
)
|
||||
db.reflect()
|
||||
try:
|
||||
entreprises_reset_database()
|
||||
except:
|
||||
db.session.rollback()
|
||||
raise
|
||||
|
||||
|
||||
@app.cli.command()
|
||||
def dumphelp():
|
||||
"""Génère la page d'aide complète pour la doc."""
|
||||
|
Loading…
Reference in New Issue
Block a user