-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add proposal template sections * feat: add factories and seeding for templates * feat: add template sections to admin * feat: api endpoint for proposal templates * feat: add decision text, xml attachment types * feat: generate decision text xml files * feat: generate decision text payload * feat: send decision proposal payload to Ahjo * feat: utilities for manual testing * feat: allow decision callback to succeed * chore: style fix * chore: tests
- Loading branch information
Showing
20 changed files
with
913 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
backend/benefit/applications/api/v1/ahjo_decision_views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from drf_spectacular.types import OpenApiTypes | ||
from drf_spectacular.utils import extend_schema, OpenApiParameter | ||
from rest_framework import status | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
from applications.api.v1.serializers.decision_proposal_template import ( | ||
DecisionProposalTemplateSectionSerializer, | ||
) | ||
from applications.enums import ApplicationStatus | ||
from applications.models import Application, DecisionProposalTemplateSection | ||
from applications.services.ahjo_decision_service import process_template_sections | ||
from common.permissions import BFIsHandler | ||
|
||
|
||
class DecisionProposalTemplateSectionList(APIView): | ||
""" | ||
View to list the decision proposal templates with placeholders replaced by actual application data. | ||
* Only handlers are able to access this view. | ||
""" | ||
|
||
permission_classes = [BFIsHandler] | ||
|
||
@extend_schema( | ||
parameters=[ | ||
OpenApiParameter( | ||
name="uuid", | ||
description="UUID of the application", | ||
required=True, | ||
type=OpenApiTypes.UUID, | ||
location=OpenApiParameter.PATH, | ||
), | ||
], | ||
description=("API for querying decision proposal templates"), | ||
request=DecisionProposalTemplateSectionSerializer, | ||
) | ||
def get(self, request, format=None) -> Response: | ||
application_id = self.request.query_params.get("application_id") | ||
try: | ||
application = ( | ||
Application.objects.filter( | ||
pk=application_id, status=ApplicationStatus.ACCEPTED | ||
) | ||
.prefetch_related("calculation", "company") | ||
.first() | ||
) | ||
except Application.DoesNotExist: | ||
return Response( | ||
{"message": "Application not found"}, status=status.HTTP_404_NOT_FOUND | ||
) | ||
|
||
decision_types = self.request.query_params.getlist("decision_type") | ||
|
||
section_types = self.request.query_params.getlist("section_type") | ||
template_sections = DecisionProposalTemplateSection.objects.filter( | ||
section_type__in=section_types, decision_type__in=decision_types | ||
) | ||
|
||
replaced_template_sections = process_template_sections( | ||
template_sections, application | ||
) | ||
|
||
serializer = DecisionProposalTemplateSectionSerializer( | ||
replaced_template_sections, many=True | ||
) | ||
|
||
return Response(serializer.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
backend/benefit/applications/api/v1/serializers/decision_proposal_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from rest_framework import serializers | ||
|
||
from applications.models import DecisionProposalTemplateSection | ||
|
||
|
||
class DecisionProposalTemplateSectionSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = DecisionProposalTemplateSection | ||
fields = ["id", "name", "section_type", "template_text"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
backend/benefit/applications/migrations/0056_decisionproposaltemplatesection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 3.2.23 on 2024-02-14 08:57 | ||
|
||
from django.db import migrations, models | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('applications', '0055_add_attachment_version_id_and_hash_20240131_1620'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='DecisionProposalTemplateSection', | ||
fields=[ | ||
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='time created')), | ||
('modified_at', models.DateTimeField(auto_now=True, verbose_name='time modified')), | ||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('section_type', models.CharField(choices=[('decision_section', 'Template part for the decision section of a application decision proposal'), ('justification_section', 'Template part for the decision justification section of a decision proposal')], default='decision_section', max_length=64, verbose_name='type of the decision proposal template section')), | ||
('decision_type', models.CharField(choices=[('accepted_decision', 'An accepted decision'), ('denied_decision', 'A denied decision')], default='accepted_decision', max_length=64, verbose_name='type of the decision')), | ||
('language', models.CharField(choices=[('fi', 'suomi'), ('sv', 'svenska'), ('en', 'english')], default='fi', max_length=2)), | ||
('template_text', models.TextField(verbose_name='decision proposal section text content')), | ||
('name', models.CharField(max_length=256, verbose_name='name of the decision proposal template section')), | ||
], | ||
options={ | ||
'verbose_name': 'decision proposal template section', | ||
'verbose_name_plural': 'decision proposal template sections', | ||
'db_table': 'bf_applications_decision_proposal_template_section', | ||
}, | ||
), | ||
] |
42 changes: 42 additions & 0 deletions
42
backend/benefit/applications/migrations/0057_attachment_type_decision_text.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated by Django 3.2.23 on 2024-02-14 10:34 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('applications', '0056_decisionproposaltemplatesection'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='attachment', | ||
name='attachment_type', | ||
field=models.CharField(choices=[('employment_contract', 'employment contract'), ('pay_subsidy_decision', 'pay subsidy decision'), ('commission_contract', 'commission contract'), ('education_contract', 'education contract of the apprenticeship office'), ('helsinki_benefit_voucher', 'helsinki benefit voucher'), ('employee_consent', 'employee consent'), ('full_application', 'full application'), ('other_attachment', 'other attachment'), ('pdf_summary', 'pdf summary'), ('decision_text_xml', 'public decision text xml attachment'), ('decision_text_secret_xml', 'non-public decision text xml attachment')], max_length=64, verbose_name='attachment type in business rules'), | ||
), | ||
migrations.AlterField( | ||
model_name='historicalattachment', | ||
name='attachment_type', | ||
field=models.CharField(choices=[('employment_contract', 'employment contract'), ('pay_subsidy_decision', 'pay subsidy decision'), ('commission_contract', 'commission contract'), ('education_contract', 'education contract of the apprenticeship office'), ('helsinki_benefit_voucher', 'helsinki benefit voucher'), ('employee_consent', 'employee consent'), ('full_application', 'full application'), ('other_attachment', 'other attachment'), ('pdf_summary', 'pdf summary'), ('decision_text_xml', 'public decision text xml attachment'), ('decision_text_secret_xml', 'non-public decision text xml attachment')], max_length=64, verbose_name='attachment type in business rules'), | ||
), | ||
migrations.CreateModel( | ||
name='AhjoDecisionText', | ||
fields=[ | ||
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='time created')), | ||
('modified_at', models.DateTimeField(auto_now=True, verbose_name='time modified')), | ||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('decision_type', models.CharField(choices=[('accepted_decision', 'An accepted decision'), ('denied_decision', 'A denied decision')], default='accepted_decision', max_length=64, verbose_name='type of the decision')), | ||
('language', models.CharField(choices=[('fi', 'suomi'), ('sv', 'svenska'), ('en', 'english')], default='fi', max_length=2)), | ||
('decision_text', models.TextField(verbose_name='decision text content')), | ||
('application', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='applications.application', verbose_name='application')), | ||
], | ||
options={ | ||
'verbose_name': 'ahjo decision text', | ||
'verbose_name_plural': 'ahjo decision texts', | ||
'db_table': 'bf_applications_ahjo_decision_text', | ||
}, | ||
), | ||
] |
Oops, something went wrong.