diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index 6c1bd1160..3ab5fb1f8 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -311,6 +311,24 @@ class CorrespondantModificationForm(FlaskForm): return validate +class ContactCreationForm(FlaskForm): + date = _build_string_field( + "Date", + render_kw={"type": "datetime-local"}, + ) + notes = TextAreaField("Notes (*)", validators=[DataRequired(message=CHAMP_REQUIS)]) + submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE) + + +class ContactModificationForm(FlaskForm): + date = _build_string_field( + "Date", + render_kw={"type": "datetime-local"}, + ) + notes = TextAreaField("Notes (*)", validators=[DataRequired(message=CHAMP_REQUIS)]) + submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE) + + class StageApprentissageCreationForm(FlaskForm): etudiant = _build_string_field( "Étudiant (*)", diff --git a/app/entreprises/models.py b/app/entreprises/models.py index ca3204ccd..2cb8e3d8f 100644 --- a/app/entreprises/models.py +++ b/app/entreprises/models.py @@ -61,6 +61,17 @@ class EntrepriseCorrespondant(db.Model): } +class EntrepriseContact(db.Model): + __tablename__ = "are_contacts" + id = db.Column(db.Integer, primary_key=True) + date = db.Column(db.DateTime(timezone=True)) + user = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="cascade")) + entreprise = db.Column( + db.Integer, db.ForeignKey("are_entreprises.id", ondelete="cascade") + ) + notes = db.Column(db.Text) + + class EntrepriseOffre(db.Model): __tablename__ = "are_offres" id = db.Column(db.Integer, primary_key=True) diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index ca4e7f367..30ae040f6 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -19,6 +19,8 @@ from app.entreprises.forms import ( OffreModificationForm, CorrespondantCreationForm, CorrespondantModificationForm, + ContactCreationForm, + ContactModificationForm, StageApprentissageCreationForm, StageApprentissageModificationForm, EnvoiOffreForm, @@ -33,6 +35,7 @@ from app.entreprises.models import ( EntrepriseOffre, EntrepriseCorrespondant, EntrepriseLog, + EntrepriseContact, EntrepriseStageApprentissage, EntrepriseEnvoiOffre, EntrepriseOffreDepartement, @@ -784,6 +787,69 @@ def delete_correspondant(id): ) +@bp.route("fiche_entreprise/add_contact/", methods=["GET", "POST"]) +@permission_required(Permission.RelationsEntreprisesChange) +def add_contact(id): + """ + Permet d'ajouter un contact avec une entreprise + """ + entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404( + description=f"entreprise {id} inconnue" + ) + form = ContactCreationForm() + if form.validate_on_submit(): + contact = EntrepriseContact( + date=form.date.data, + user=current_user.id, # a voir + entreprise=entreprise.id, + notes=form.notes.data.strip(), + ) + db.session.add(contact) + db.session.commit() + return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id)) + return render_template( + "entreprises/form.html", + title="Ajout contact", + form=form, + ) + + +@bp.route("fiche_entreprise/edit_contact/", methods=["GET", "POST"]) +@permission_required(Permission.RelationsEntreprisesChange) +def edit_contact(id): + """ + Permet d'editer un contact avec une entreprise + """ + contact = EntrepriseContact.query.filter_by(id=id).first_or_404( + description=f"contact {id} inconnu" + ) + form = ContactModificationForm() + if form.validate_on_submit(): + contact.date = form.date.data + contact.notes = form.notes.data + db.session.commit() + return redirect(url_for("entreprises.fiche_entreprise", id=contact.entreprise)) + elif request.method == "GET": + form.date.data = contact.date + form.notes.data = contact.notes + return render_template( + "entreprises/form.html", + title="Modification contact", + form=form, + ) + + +@bp.route("/fiche_entreprise/contacts/") +def contacts(id): + contacts = EntrepriseContact.query.filter_by(entreprise=id).all() + return render_template( + "entreprises/contacts.html", + title="Liste des contacts", + contacts=contacts, + entreprise_id=id, + ) + + @bp.route("/add_stage_apprentissage/", methods=["GET", "POST"]) @permission_required(Permission.RelationsEntreprisesChange) def add_stage_apprentissage(id): @@ -1229,6 +1295,9 @@ def import_correspondants(): correspondant_data[6], ) ) + entreprise = Entreprise.query.filter_by( + siret=correspondant_data[6] + ).first() correspondant = EntrepriseCorrespondant( nom=correspondant_data[0], prenom=correspondant_data[1], @@ -1236,7 +1305,7 @@ def import_correspondants(): mail=correspondant_data[3], poste=correspondant_data[4], service=correspondant_data[5], - entreprise_id=correspondant_data[6], + entreprise_id=entreprise.id, ) correspondants_import.append(correspondant) else: diff --git a/app/templates/entreprises/contacts.html b/app/templates/entreprises/contacts.html new file mode 100644 index 000000000..cb01d4ed1 --- /dev/null +++ b/app/templates/entreprises/contacts.html @@ -0,0 +1,87 @@ +{# -*- mode: jinja-html -*- #} +{% extends 'base.html' %} + +{% block styles %} +{{super()}} + + + +{% endblock %} + +{% block app_content %} +
+

Liste des contacts

+ Ajouter contact + + + + + + + {% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %} + + {% endif %} + + + + {% for contact in contacts %} + + + + + {% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %} + + {% endif %} + + {% endfor %} + + + + + + + {% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %} + + {% endif %} + + +
DateUtilisateurNotesAction
{{ contact.date.strftime('%d/%m/%Y %Hh%M') }}{{ contact.user|get_nomcomplet_by_id }}{{ contact.notes }} + +
DateUtilisateurNotesAction
+
+ + +{% endblock %} \ No newline at end of file diff --git a/app/templates/entreprises/fiche_entreprise.html b/app/templates/entreprises/fiche_entreprise.html index 732df7e4b..a146e5dd4 100644 --- a/app/templates/entreprises/fiche_entreprise.html +++ b/app/templates/entreprises/fiche_entreprise.html @@ -43,6 +43,7 @@ Supprimer Ajouter offre Ajouter correspondant + Ajouter contact {% endif %} Voir les offres expirées
diff --git a/migrations/versions/71e760aa626a_tables_module_gestion_relations_.py b/migrations/versions/e5043b68e6b9_tables_module_gestion_relations_.py similarity index 93% rename from migrations/versions/71e760aa626a_tables_module_gestion_relations_.py rename to migrations/versions/e5043b68e6b9_tables_module_gestion_relations_.py index 5b3152399..bc57fbf5b 100644 --- a/migrations/versions/71e760aa626a_tables_module_gestion_relations_.py +++ b/migrations/versions/e5043b68e6b9_tables_module_gestion_relations_.py @@ -1,8 +1,8 @@ """tables module gestion relations entreprises -Revision ID: 71e760aa626a +Revision ID: e5043b68e6b9 Revises: b9aadc10227f -Create Date: 2022-03-29 18:39:24.772970 +Create Date: 2022-04-04 09:14:54.605480 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. -revision = "71e760aa626a" +revision = "e5043b68e6b9" down_revision = "b9aadc10227f" branch_labels = None depends_on = None @@ -51,6 +51,19 @@ def upgrade(): sa.Column("value", sa.Text(), nullable=True), sa.PrimaryKeyConstraint("id"), ) + op.create_table( + "are_contacts", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("date", sa.DateTime(timezone=True), nullable=True), + sa.Column("user", sa.Integer(), nullable=True), + sa.Column("entreprise", sa.Integer(), nullable=True), + sa.Column("notes", sa.Text(), nullable=True), + sa.ForeignKeyConstraint( + ["entreprise"], ["are_entreprises.id"], ondelete="cascade" + ), + sa.ForeignKeyConstraint(["user"], ["user.id"], ondelete="cascade"), + sa.PrimaryKeyConstraint("id"), + ) op.create_table( "are_correspondants", sa.Column("id", sa.Integer(), nullable=False), @@ -151,9 +164,9 @@ def upgrade(): sa.ForeignKeyConstraint(["offre_id"], ["are_offres.id"], ondelete="cascade"), sa.PrimaryKeyConstraint("id"), ) + op.drop_index("ix_entreprises_dept_id", table_name="entreprises") op.drop_table("entreprise_contact") op.drop_table("entreprise_correspondant") - op.drop_index("ix_entreprises_dept_id", table_name="entreprises") op.drop_table("entreprises") # ### end Alembic commands ### @@ -198,15 +211,7 @@ def downgrade(): op.create_index("ix_entreprises_dept_id", "entreprises", ["dept_id"], unique=False) op.create_table( "entreprise_correspondant", - sa.Column( - "id", - sa.INTEGER(), - server_default=sa.text( - "nextval('entreprise_correspondant_id_seq'::regclass)" - ), - autoincrement=True, - nullable=False, - ), + sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), sa.Column("entreprise_id", sa.INTEGER(), autoincrement=False, nullable=True), sa.Column("nom", sa.TEXT(), autoincrement=False, nullable=True), sa.Column("prenom", sa.TEXT(), autoincrement=False, nullable=True), @@ -225,7 +230,6 @@ def downgrade(): name="entreprise_correspondant_entreprise_id_fkey", ), sa.PrimaryKeyConstraint("id", name="entreprise_correspondant_pkey"), - postgresql_ignore_search_path=False, ) op.create_table( "entreprise_contact", @@ -262,6 +266,7 @@ def downgrade(): op.drop_table("are_offres") op.drop_table("are_stages_apprentissages") op.drop_table("are_correspondants") + op.drop_table("are_contacts") op.drop_table("are_preferences") op.drop_table("are_logs") op.drop_table("are_entreprises")