From e16506a4b88f6298517ddb4928a61d502adfc2b8 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Mon, 11 Mar 2024 16:57:15 +0100 Subject: [PATCH] Set this value automatically in the views --- lemarche/www/tenders/tests.py | 16 +++++++++++++++- lemarche/www/tenders/views.py | 13 +++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py index 8fcf7a4ee..d6f702c72 100644 --- a/lemarche/www/tenders/tests.py +++ b/lemarche/www/tenders/tests.py @@ -1789,6 +1789,7 @@ 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" @@ -1796,6 +1797,10 @@ def test_update_tender_stats_on_tender_survey_transactioned_answer_true(self): 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( @@ -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 diff --git a/lemarche/www/tenders/views.py b/lemarche/www/tenders/views.py index 0fad60fb9..3c8f9ce23 100644 --- a/lemarche/www/tenders/views.py +++ b/lemarche/www/tenders/views.py @@ -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 @@ -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