Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Besoins): Connaitre la source de la transaction #1124

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lemarche/tenders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
"siae_detail_cocontracting_click_count_annotated_with_link",
"siae_detail_not_interested_click_count_annotated_with_link",
"siae_ai_count_annotated_with_link",
"siae_transactioned_source",
"siae_transactioned_last_updated",
"logs_display",
"extra_data_display",
"source",
Expand Down Expand Up @@ -336,12 +338,9 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
"Transaction ?",
{
"fields": (
"survey_transactioned_send_date",
"survey_transactioned_answer",
"survey_transactioned_amount",
"survey_transactioned_feedback",
"survey_transactioned_answer_date",
*Tender.FIELDS_SURVEY_TRANSACTIONED,
"siae_transactioned",
"siae_transactioned_source",
"siae_transactioned_last_updated",
)
},
Expand Down
9 changes: 9 additions & 0 deletions lemarche/tenders/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@
(SOURCE_TALLY, "TALLY"),
)

TENDER_SIAE_TRANSACTIONED_SOURCE_ADMIN = "ADMIN"
TENDER_SIAE_TRANSACTIONED_SOURCE_AUTHOR = "AUTHOR"
TENDER_SIAE_TRANSACTIONED_SOURCE_SIAE = "SIAE"
TENDER_SIAE_TRANSACTIONED_SOURCE_CHOICES = (
(TENDER_SIAE_TRANSACTIONED_SOURCE_ADMIN, "Admin"),
(TENDER_SIAE_TRANSACTIONED_SOURCE_AUTHOR, "Auteur"),
(TENDER_SIAE_TRANSACTIONED_SOURCE_SIAE, "Structure"),
)

TENDER_SIAE_SOURCE_EMAIL = "EMAIL"
TENDER_SIAE_SOURCE_DASHBOARD = "DASHBOARD"
TENDER_SIAE_SOURCE_LINK = "LINK"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 4.2.9 on 2024-03-11 15:21

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("tenders", "0079_tender_siae_transactioned_last_updated"),
]

operations = [
migrations.AddField(
model_name="tender",
name="siae_transactioned_source",
field=models.CharField(
blank=True,
choices=[("ADMIN", "Admin"), ("AUTHOR", "Auteur"), ("SIAE", "Structure")],
help_text="Champ mis à jour automatiquement",
max_length=20,
null=True,
verbose_name="Abouti à une transaction : source",
),
),
migrations.AlterField(
model_name="tender",
name="siae_transactioned_last_updated",
field=models.DateTimeField(
blank=True,
help_text="Champ mis à jour automatiquement",
null=True,
verbose_name="Abouti à une transaction : date de mise à jour",
),
),
]
20 changes: 18 additions & 2 deletions lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
from lemarche.tenders.utils import find_amount_ranges
from lemarche.users.models import User
from lemarche.utils.apis import api_elasticsearch
from lemarche.utils.constants import ADMIN_FIELD_HELP_TEXT, MARCHE_BENEFIT_CHOICES, RECALCULATED_FIELD_HELP_TEXT
from lemarche.utils.constants import (
ADMIN_FIELD_HELP_TEXT,
AUTO_FIELD_HELP_TEXT,
MARCHE_BENEFIT_CHOICES,
RECALCULATED_FIELD_HELP_TEXT,
)
from lemarche.utils.fields import ChoiceArrayField
from lemarche.utils.urls import get_object_admin_url

Expand Down Expand Up @@ -514,8 +519,19 @@ class Tender(models.Model):
blank=True,
null=True,
)
siae_transactioned_source = models.CharField(
verbose_name="Abouti à une transaction : source",
help_text=AUTO_FIELD_HELP_TEXT,
max_length=20,
choices=tender_constants.TENDER_SIAE_TRANSACTIONED_SOURCE_CHOICES,
blank=True,
null=True,
)
siae_transactioned_last_updated = models.DateTimeField(
"Abouti à une transaction : date de mise à jour", blank=True, null=True
verbose_name="Abouti à une transaction : date de mise à jour",
help_text=AUTO_FIELD_HELP_TEXT,
blank=True,
null=True,
)
amount_exact = models.PositiveIntegerField(
verbose_name="Montant exact du besoin", help_text=ADMIN_FIELD_HELP_TEXT, blank=True, null=True
Expand Down
1 change: 1 addition & 0 deletions lemarche/utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
EMPTY_CHOICE = (("", ""),)

ADMIN_FIELD_HELP_TEXT = "Champ renseigné par un ADMIN"
AUTO_FIELD_HELP_TEXT = "Champ mis à jour automatiquement"
RECALCULATED_FIELD_HELP_TEXT = "Champ recalculé à intervalles réguliers"

MARCHE_BENEFIT_TIME = "TIME"
Expand Down
16 changes: 15 additions & 1 deletion lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1789,13 +1789,18 @@ def test_only_tender_author_with_sesame_token_can_call_tender_survey_transaction
def test_update_tender_stats_on_tender_survey_transactioned_answer_true(self):
self.assertIsNone(Tender.objects.get(id=self.tender.id).survey_transactioned_answer)
self.assertIsNone(Tender.objects.get(id=self.tender.id).siae_transactioned)
self.assertIsNone(Tender.objects.get(id=self.tender.id).siae_transactioned_source)
self.assertIsNone(Tender.objects.get(id=self.tender.id).siae_transactioned_last_updated)
# load with answer 'True': partial form
url = self.url + self.user_buyer_1_sesame_query_string + "&answer=True"
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)
self.assertTrue(Tender.objects.get(id=self.tender.id).survey_transactioned_answer)
self.assertTrue(Tender.objects.get(id=self.tender.id).siae_transactioned)
self.assertEqual(
Tender.objects.get(id=self.tender.id).siae_transactioned_source,
tender_constants.TENDER_SIAE_TRANSACTIONED_SOURCE_AUTHOR,
)
self.assertIsNotNone(Tender.objects.get(id=self.tender.id).siae_transactioned_last_updated)
# fill in form
response = self.client.post(
Expand Down Expand Up @@ -1883,11 +1888,20 @@ def test_only_tender_author_with_sesame_token_can_call_tender_siae_survey_transa
# full form displayed (but should never happen)

def test_update_tender_stats_on_tender_siae_survey_transactioned_answer_true(self):
ts = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertIsNone(ts.survey_transactioned_answer)
self.assertIsNone(ts.tender.siae_transactioned)
self.assertIsNone(ts.tender.siae_transactioned_source)
self.assertIsNone(ts.tender.siae_transactioned_last_updated)
# load with answer 'True': partial form
url = self.url + self.user_siae_1_sesame_query_string + "&answer=True"
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200)
self.assertTrue(TenderSiae.objects.get(tender=self.tender, siae=self.siae).survey_transactioned_answer)
ts = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertTrue(ts.survey_transactioned_answer)
self.assertTrue(ts.tender.siae_transactioned)
self.assertEqual(ts.tender.siae_transactioned_source, tender_constants.TENDER_SIAE_TRANSACTIONED_SOURCE_SIAE)
self.assertIsNotNone(ts.tender.siae_transactioned_last_updated)
# fill in form
response = self.client.post(
url, data={"survey_transactioned_amount": 1000, "survey_transactioned_feedback": "Feedback"}, follow=True
Expand Down
13 changes: 11 additions & 2 deletions lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,9 @@ def get(self, request, *args, **kwargs):
# update tender
self.object.survey_transactioned_answer = survey_transactioned_answer
self.object.survey_transactioned_answer_date = timezone.now()
self.object.siae_transactioned = survey_transactioned_answer
if self.object.siae_transactioned is None:
self.object.siae_transactioned = survey_transactioned_answer
self.object.siae_transactioned_source = tender_constants.TENDER_SIAE_TRANSACTIONED_SOURCE_AUTHOR
self.object.save()
else:
pass
Expand Down Expand Up @@ -685,10 +687,17 @@ def get(self, request, *args, **kwargs):
if survey_transactioned_answer in ["True", "False"]:
# transform survey_transactioned_answer into bool
survey_transactioned_answer = survey_transactioned_answer == "True"
# update tender
# update tendersiae
self.object.survey_transactioned_answer = survey_transactioned_answer
self.object.survey_transactioned_answer_date = timezone.now()
self.object.save()
# update tender
if self.object.tender.siae_transactioned is None:
self.object.tender.siae_transactioned = survey_transactioned_answer
self.object.tender.siae_transactioned_source = (
tender_constants.TENDER_SIAE_TRANSACTIONED_SOURCE_SIAE
)
self.object.tender.save()
else:
pass
# TODO or not? "answer" should always be passed
Expand Down
Loading