Skip to content

Commit 10b9c2c

Browse files
include total_grantee_reimbursement_amount in invitation letter template (#4551)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Marco Acierno <marcoacierno@users.noreply.github.com>
1 parent 6616891 commit 10b9c2c

4 files changed

Lines changed: 78 additions & 0 deletions

File tree

backend/visa/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ def grant_approved_type(self) -> str | None:
122122

123123
return "_".join(sorted(categories)) if len(categories) > 1 else categories[0]
124124

125+
@property
126+
def total_grantee_reimbursement_amount(self):
127+
grant = self.user_grant
128+
129+
if not grant:
130+
return None
131+
132+
return grant.total_grantee_reimbursement_amount
133+
125134
@cached_property
126135
def user_grant(self):
127136
return Grant.objects.for_conference(self.conference).of_user(self.user).first()

backend/visa/tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def _render_content(content, invitation_letter_request, config):
151151
"grant_approved_type": invitation_letter_request.grant_approved_type,
152152
"has_accommodation_via_grant": invitation_letter_request.has_accommodation_via_grant(),
153153
"has_travel_via_grant": invitation_letter_request.has_travel_via_grant(),
154+
"total_grantee_reimbursement_amount": invitation_letter_request.total_grantee_reimbursement_amount,
154155
# conference
155156
"conference": invitation_letter_request.conference,
156157
}

backend/visa/tests/test_models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def test_request_on_behalf_of_other():
2626
assert request.user is None
2727
assert request.role == "Attendee"
2828
assert request.has_grant is False
29+
assert request.total_grantee_reimbursement_amount is None
2930

3031
# With matching user, it is found
3132
user = UserFactory(email="example@example.org")
@@ -87,6 +88,13 @@ def test_request_grant_info(
8788
assert request.has_travel_via_grant() == expected_has_travel
8889
# grant_approved_type returns sorted categories joined by underscore
8990
assert request.grant_approved_type == expected_type
91+
# total_grantee_reimbursement_amount excludes ticket
92+
expected_amount = Decimal(0)
93+
if "travel" in categories:
94+
expected_amount += Decimal("500")
95+
if "accommodation" in categories:
96+
expected_amount += Decimal("200")
97+
assert request.total_grantee_reimbursement_amount == expected_amount
9098

9199

92100
def test_role_for_speakers():

backend/visa/tests/test_tasks.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,66 @@ def test_process_invitation_letter_request_accomodation_doc_with_no_accommodatio
187187
assert output.pages[0].extract_text() == "Thisisasampleticket pdf"
188188

189189

190+
@override_settings(PRETIX_API="https://pretix/api/")
191+
def test_process_invitation_letter_request_renders_total_grantee_reimbursement_amount(
192+
mock_ticket_present,
193+
):
194+
config = InvitationLetterConferenceConfigFactory()
195+
InvitationLetterDocumentFactory(
196+
invitation_letter_conference_config=config,
197+
document=None,
198+
dynamic_document={
199+
"header": {"content": "header", "margin": "0", "align": "top-left"},
200+
"footer": {"content": "footer", "margin": "0", "align": "bottom-left"},
201+
"page_layout": {"margin": "0"},
202+
"pages": [
203+
{
204+
"content": "Reimbursement: {{total_grantee_reimbursement_amount}}"
205+
},
206+
],
207+
},
208+
)
209+
210+
request = InvitationLetterRequestFactory(
211+
conference=config.conference, nationality="Italian"
212+
)
213+
mock_ticket_present(request)
214+
215+
grant = GrantFactory(
216+
conference=config.conference,
217+
user=request.requester,
218+
)
219+
GrantReimbursementFactory(
220+
grant=grant,
221+
category__conference=config.conference,
222+
category__ticket=True,
223+
granted_amount=Decimal("100"),
224+
)
225+
GrantReimbursementFactory(
226+
grant=grant,
227+
category__conference=config.conference,
228+
category__travel=True,
229+
granted_amount=Decimal("500"),
230+
)
231+
GrantReimbursementFactory(
232+
grant=grant,
233+
category__conference=config.conference,
234+
category__accommodation=True,
235+
granted_amount=Decimal("200"),
236+
)
237+
238+
process_invitation_letter_request(invitation_letter_request_id=request.id)
239+
240+
request.refresh_from_db()
241+
242+
assert request.status == InvitationLetterRequestStatus.PROCESSED
243+
244+
output = PdfReader(request.invitation_letter.open())
245+
assert output.get_num_pages() == 2
246+
assert output.pages[0].extract_text() == "Reimbursement: 700 \nheader\nfooter"
247+
assert output.pages[1].extract_text() == "Thisisasampleticket pdf"
248+
249+
190250
@override_settings(PRETIX_API="https://pretix/api/")
191251
def test_process_invitation_letter_request_with_doc_only_for_accommodation(
192252
mock_ticket_present,

0 commit comments

Comments
 (0)