Skip to content

Commit 8928f59

Browse files
committed
WIP renewal work
1 parent 7ba7d36 commit 8928f59

File tree

581 files changed

+209663
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

581 files changed

+209663
-4
lines changed

sponsors/forms.py

+2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ class SponsorshipReviewAdminForm(forms.ModelForm):
392392
start_date = forms.DateField(widget=AdminDateWidget(), required=False)
393393
end_date = forms.DateField(widget=AdminDateWidget(), required=False)
394394
overlapped_by = forms.ModelChoiceField(queryset=Sponsorship.objects.select_related("sponsor", "package"), required=False)
395+
renewal = forms.CheckboxInput()
395396

396397
def __init__(self, *args, **kwargs):
397398
force_required = kwargs.pop("force_required", False)
@@ -415,6 +416,7 @@ def clean(self):
415416
cleaned_data = super().clean()
416417
start_date = cleaned_data.get("start_date")
417418
end_date = cleaned_data.get("end_date")
419+
renewal = cleaned_data.get("renewal")
418420

419421
if start_date and end_date and end_date <= start_date:
420422
raise forms.ValidationError("End date must be greater than start date")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.2.24 on 2023-12-16 19:14
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('sponsors', '0096_auto_20231214_2108'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='sponsorship',
15+
name='renewal',
16+
field=models.BooleanField(default=False),
17+
),
18+
]

sponsors/models/sponsorship.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class Meta(OrderedModel.Meta):
135135

136136
class Sponsorship(models.Model):
137137
"""
138-
Represente a sponsorship application by a sponsor.
138+
Represents a sponsorship application by a sponsor.
139139
It's responsible to group the set of selected benefits and
140140
link it to sponsor
141141
"""
@@ -182,6 +182,7 @@ class Sponsorship(models.Model):
182182
package = models.ForeignKey(SponsorshipPackage, null=True, on_delete=models.SET_NULL)
183183
sponsorship_fee = models.PositiveIntegerField(null=True, blank=True)
184184
overlapped_by = models.ForeignKey("self", null=True, on_delete=models.SET_NULL)
185+
renewal = models.BooleanField(default=False)
185186

186187
assets = GenericRelation(GenericAsset)
187188

sponsors/pdf.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def _contract_context(contract, **context):
3232
"sponsorship": contract.sponsorship,
3333
"benefits": _clean_split(contract.benefits_list.raw),
3434
"legal_clauses": _clean_split(contract.legal_clauses.raw),
35+
"renewal": contract.sponsorship.renewal,
3536
})
3637
return context
3738

@@ -49,9 +50,14 @@ def render_contract_to_pdf_file(contract, **context):
4950

5051

5152
def _gen_docx_contract(output, contract, **context):
52-
template = os.path.join(settings.TEMPLATES_DIR, "sponsors", "admin", "contract-template.docx")
53-
doc = DocxTemplate(template)
5453
context = _contract_context(contract, **context)
54+
renewal = context["renewal"]
55+
if renewal:
56+
template = os.path.join(settings.TEMPLATES_DIR, "sponsors", "admin", "renewal-contract-template.docx")
57+
else:
58+
template = os.path.join(settings.TEMPLATES_DIR, "sponsors", "admin", "contract-template.docx")
59+
doc = DocxTemplate(template)
60+
# context = _contract_context(contract, **context)
5561
doc.render(context)
5662
doc.save(output)
5763
return output

sponsors/tests/test_pdf.py

+21
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def setUp(self):
2828
"sponsorship": self.contract.sponsorship,
2929
"benefits": [],
3030
"legal_clauses": [],
31+
"renewal": False,
3132
}
3233
self.template = "sponsors/admin/preview-contract.html"
3334

@@ -71,3 +72,23 @@ def test_render_response_with_docx_attachment(self, MockDocxTemplate):
7172
response.get("Content-Type"),
7273
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
7374
)
75+
76+
@patch("sponsors.pdf.DocxTemplate")
77+
def test_render_response_with_docx_attachment__renewal(self, MockDocxTemplate):
78+
self.context.update({"renewal": True})
79+
template = Path(settings.TEMPLATES_DIR) / "sponsors" / "admin" / "contract-renewal-template.docx"
80+
self.assertTrue(template.exists())
81+
mocked_doc = Mock(DocxTemplate)
82+
MockDocxTemplate.return_value = mocked_doc
83+
84+
request = Mock(HttpRequest)
85+
response = render_contract_to_docx_response(request, self.contract)
86+
87+
MockDocxTemplate.assert_called_once_with(str(template.resolve()))
88+
mocked_doc.render.assert_called_once_with(self.context)
89+
mocked_doc.save.assert_called_once_with(response)
90+
self.assertEqual(response.get("Content-Disposition"), "attachment; filename=contract.docx")
91+
self.assertEqual(
92+
response.get("Content-Type"),
93+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
94+
)

sponsors/tests/test_use_cases.py

+18
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ def test_update_sponsorship_as_approved_and_create_contract(self):
118118
self.assertEqual(self.sponsorship.sponsorship_fee, 100)
119119
self.assertEqual(self.sponsorship.package, self.package)
120120
self.assertEqual(self.sponsorship.level_name, self.package.name)
121+
self.assertEqual(self.sponsorship.renewal, False)
122+
123+
124+
def test_update_renewal_sponsorship_as_approved_and_create_contract(self):
125+
self.data.update({"renewal": True})
126+
self.use_case.execute(self.sponsorship, **self.data)
127+
self.sponsorship.refresh_from_db()
128+
129+
today = timezone.now().date()
130+
self.assertEqual(self.sponsorship.approved_on, today)
131+
self.assertEqual(self.sponsorship.status, Sponsorship.APPROVED)
132+
self.assertTrue(self.sponsorship.contract.pk)
133+
self.assertTrue(self.sponsorship.start_date)
134+
self.assertTrue(self.sponsorship.end_date)
135+
self.assertEqual(self.sponsorship.sponsorship_fee, 100)
136+
self.assertEqual(self.sponsorship.package, self.package)
137+
self.assertEqual(self.sponsorship.level_name, self.package.name)
138+
self.assertEqual(self.sponsorship.renewal, True)
121139

122140
def test_send_notifications_using_sponsorship(self):
123141
self.use_case.execute(self.sponsorship, **self.data)

sponsors/use_cases.py

+3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ def execute(self, sponsorship, start_date, end_date, **kwargs):
5555
sponsorship.approve(start_date, end_date)
5656
package = kwargs.get("package")
5757
fee = kwargs.get("sponsorship_fee")
58+
renewal = kwargs.get("renewal", False)
5859
if package:
5960
sponsorship.package = package
6061
sponsorship.level_name = package.name
6162
if fee:
6263
sponsorship.sponsorship_fee = fee
64+
if renewal:
65+
sponsorship.renewal = renewal
6366

6467
sponsorship.save()
6568
contract = Contract.new(sponsorship)

templates/sponsors/admin/approve_application.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ <h1>Generate Contract for Signing</h1>
3434
{{ form.as_p }}
3535

3636
<input name="confirm" value="yes" style="display:none">
37-
37+
<input type="checkbox" id="renewal" name="renewal" value="renewal">
38+
<label for="renewal">Renewal of a previous sponsorship</label><br>
3839
<div class="submit-row">
3940
<input type="submit" value="Approve" class="default">
4041
</div>
Binary file not shown.

0 commit comments

Comments
 (0)