Skip to content

Commit 1818265

Browse files
authored
Merge pull request #554 from iMMAP/iMMAP/cash_inkind_information
Immap/cash inkind information
2 parents 145453d + f2b45fe commit 1818265

7 files changed

+418
-42
lines changed

src/rh/forms.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,21 @@ class Meta:
328328
}
329329

330330
def __init__(self, *args, **kwargs):
331+
indicator = kwargs.pop("indicator", None)
331332
super().__init__(*args, **kwargs)
332333

333-
self.fields["implement_modality_type"].queryset = ImplementationModalityType.objects.none()
334+
if indicator and indicator.implement_category:
335+
self.fields["implement_modality_type"].queryset = ImplementationModalityType.objects.filter(
336+
type=indicator.implement_category.type
337+
)
338+
else:
339+
self.fields["implement_modality_type"].queryset = ImplementationModalityType.objects.all()
340+
334341
self.fields["unit_type"].queryset = UnitType.objects.none()
335342
self.fields["transfer_mechanism_type"].queryset = TransferMechanismType.objects.none()
336343
self.fields["package_type"].queryset = PackageType.objects.all()
337344
self.fields["ration_type"].queryset = RationType.objects.all()
338345
self.fields["ration_size"].queryset = RationSize.objects.all()
339-
340-
# Ensure `self.instance` is valid and linked to an ActivityPlan
341346
if self.data:
342347
try:
343348
# Creating
@@ -348,16 +353,18 @@ def __init__(self, *args, **kwargs):
348353
)
349354
self.fields["unit_type"].queryset = UnitType.objects.filter(modality=implement_modality_type)
350355
except Exception:
351-
self.add_error(None, "Do not mess with the form!")
356+
pass
352357
elif self.instance.pk:
353-
self.fields["implement_modality_type"].queryset = ImplementationModalityType.objects.all()
358+
if indicator and indicator.implement_category:
359+
self.fields["implement_modality_type"].queryset = ImplementationModalityType.objects.filter(
360+
type=indicator.implement_category.type
361+
)
362+
else:
363+
self.fields["implement_modality_type"].queryset = ImplementationModalityType.objects.all()
354364
self.fields["transfer_mechanism_type"].queryset = TransferMechanismType.objects.filter(
355365
modality=self.instance.implement_modality_type
356366
)
357367
self.fields["unit_type"].queryset = UnitType.objects.filter(modality=self.instance.implement_modality_type)
358-
# else:
359-
# self.fields["transfer_mechanism_type"].queryset = TransferMechanismType.objects.none()
360-
# self.fields["unit_type"].queryset = UnitType.objects.none()
361368

362369

363370
class BaseCashInKindDetailFormSet(BaseInlineFormSet):

src/rh/templates/rh/activity_plans/activity_plan_form.html

+26-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
<div class="sign-up-field-error">{{ form.activity_domain.errors }}</div>
9898
</div>
9999
</div>
100-
100+
101101
<div class="field-col">
102102
<div class="select-field is-required">
103103
<label for="{{ form.activity_type.id_for_label }}">Activity Type</label>
@@ -131,13 +131,17 @@
131131
name="{{ form.indicator.name }}"
132132
id="{{ form.indicator.id_for_label }}"
133133
class="form-control indicator-details"
134+
hx-post="{% url 'hx-show-indicator-details' %}"
135+
hx-trigger="change"
136+
hx-target="#cashinkind-details-info"
137+
hx-swap="innerHTML"
134138
hx-indicator=".progress">
135139
{% for type in form.indicator %}{{ type }}{% endfor %}
136140
</select>
137141
<div class="sign-up-field-error">{{ form.indicator.errors }}</div>
138142
</div>
139143
</div>
140-
144+
141145
<div class="field-col w-full">
142146
<div class="select-field">
143147
<label for="{{ form.hrp_beneficiary.id_for_label }}">HRP Beneficiary</label>
@@ -146,7 +150,7 @@
146150
<div class="sign-up-field-error">{{ form.hrp_beneficiary.errors }}</div>
147151
</div>
148152
</div>
149-
153+
150154
</div>
151155
</div>
152156
</div>
@@ -155,14 +159,32 @@
155159
<div class="input-holder">{{ form.description }}</div>
156160
<div class="sign-up-field-error">{{ form.description.errors }}</div>
157161
</div>
158-
162+
159163
<div class="input-field">
160164
<label for="{{ form.instance.state.id_for_label }}">State</label>
161165
<div class="input-holder">
162166
<span class="{{form.instance.state}}">{{ form.instance.state}}</span>
163167
</div>
164168
</div>
169+
170+
171+
<!-- *********************Activity plan Cash In-Kind Details*************** -->
172+
<div id="cashinkind-details-info" class="indicator-details-toggle border border-gray-d1 p-6 rounded-lg my-6">
173+
{% if cashinkind_form %}
174+
{% if form.instance.indicator.implement_category and form.instance.indicator.implement_category|stringformat:"s" == "Cash" %}
175+
{% include "rh/activity_plans/partials/_cash_in_kind_form_with_cash_sections.html" with cashinkind_form=cashinkind_form %}
176+
{% elif form.instance.indicator.implement_category and form.instance.indicator.implement_category|stringformat:"s" == "In Kind" and form.instance.indicator.food %}
177+
{% include "rh/activity_plans/partials/_cash_in_kind_form_with_food_sections.html" with cashinkind_form=cashinkind_form %}
178+
{% elif form.instance.indicator.package %}
179+
{% include "rh/activity_plans/partials/_cash_in_kind_form_with_package_sections.html" with cashinkind_form=cashinkind_form %}
180+
{% else %}
181+
<p>No additional details required for this indicator.</p>
182+
{% endif %}
183+
{% endif %}
165184
</div>
185+
186+
<!-- *********************Activity plan cash in-kind Detail end******************************** -->
187+
166188
<div class="plan-submit-holder">
167189
{% if form.initial %}
168190
<a id="delete-btn"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<div class="row">
2+
<div class="multiple-fields-row three-items">
3+
<div class="field-col">
4+
<div class="select-field is-required">
5+
<label for="{{ cashinkind_form.implement_modality_type.id_for_label }}">Implement Modality</label>
6+
<p class="help-text">{{ cashinkind_form.implement_modality_type.help_text }}</p>
7+
<select
8+
name="{{ cashinkind_form.implement_modality_type.name }}"
9+
id="{{ cashinkind_form.implement_modality_type.id_for_label }}"
10+
hx-get="{% url 'get-transfer-mechanism-types' %}"
11+
hx-trigger="change"
12+
hx-target="#{{ cashinkind_form.transfer_mechanism_type.id_for_label }}"
13+
hx-swap="innerHTML"
14+
>
15+
{% for type in cashinkind_form.implement_modality_type %}{{ type }}{% endfor %}
16+
</select>
17+
<div class="sign-up-field-error">{{ cashinkind_form.implement_modality_type.errors }}</div>
18+
</div>
19+
</div>
20+
<div class="field-col">
21+
<div class="select-field is-required">
22+
<label for="{{ cashinkind_form.transfer_mechanism_type.id_for_label }}">Transfer Mechanism</label>
23+
<p class="help-text">{{ cashinkind_form.transfer_mechanism_type.help_text }}</p>
24+
<select
25+
name="{{ cashinkind_form.transfer_mechanism_type.name }}"
26+
id="{{ cashinkind_form.transfer_mechanism_type.id_for_label }}"
27+
hx-get="{% url 'get-unit-types' %}"
28+
hx-trigger="change"
29+
hx-target="#{{ cashinkind_form.unit_type.id_for_label }}"
30+
hx-swap="innerHTML"
31+
>
32+
{% for type in cashinkind_form.transfer_mechanism_type %}{{ type }}{% endfor %}
33+
</select>
34+
<div class="sign-up-field-error">{{ cashinkind_form.transfer_mechanism_type.errors }}</div>
35+
</div>
36+
</div>
37+
<div class="field-col cash-package-section">
38+
<div class="select-field is-required">
39+
<label for="{{cashinkind_form.unit_type.id_for_label}}">Unit Type</label>
40+
<p class="help-text" id="unit_type_help_text"></p>
41+
<select
42+
name="{{ cashinkind_form.unit_type.name }}"
43+
id="{{ cashinkind_form.unit_type.id_for_label }}"
44+
hx-trigger="change"
45+
hx-target="#{{ cashinkind_form.package_type.id_for_label }}"
46+
hx-swap="innerHTML"
47+
>
48+
{% for type in cashinkind_form.unit_type %}{{ type }}{% endfor %}
49+
</select>
50+
<small class="sign-up-field-error">{{ cashinkind_form.unit_type.errors }}</small>
51+
</div>
52+
</div>
53+
<div class="field-col">
54+
<div class="select-field">
55+
<label for="{{ cashinkind_form.package_type.id_for_label }}">Package Type</label>
56+
<p class="help-text">{{ cashinkind_form.package_type.help_text }}</p>
57+
<select
58+
name="package_type"
59+
id="{{ cashinkind_form.package_type.id_for_label }}">
60+
{% for type in cashinkind_form.package_type %}{{ type }}{% endfor %}
61+
</select>
62+
<small class="sign-up-field-error">{{ cashinkind_form.package_type.errors }}</small>
63+
</div>
64+
</div>
65+
<div class="field-col food-section">
66+
<div class="select-field is-required">
67+
<label for="{{ cashinkind_form.transfer_category.id_for_label }}">
68+
{{cashinkind_form.transfer_category.label }}
69+
</label>
70+
<p class="help-text">{{ cashinkind_form.transfer_category.help_text }}</p>
71+
<select name="{{cashinkind_form.transfer_category.name}}"
72+
id="{{cashinkind_form.transfer_category.id_for_label}}"
73+
>
74+
{% for type in cashinkind_form.transfer_category %}{{ type }}{% endfor %}
75+
</select>
76+
<small class="sign-up-field-error">{{ cashinkind_form.transfer_category.errors }}</small>
77+
</div>
78+
</div>
79+
<div class="field-col">
80+
<div class="select-field">
81+
<label>{{ cashinkind_form.no_of_transfers.label }}</label>
82+
<p class="help-text">{{ cashinkind_form.no_of_transfers.help_text }}</p>
83+
{{ cashinkind_form.no_of_transfers }}
84+
<small class="sign-up-field-error">{{ cashinkind_form.no_of_transfers.errors }}</small>
85+
</div>
86+
</div>
87+
<div class="field-col">
88+
<div class="select-field">
89+
<label>{{ cashinkind_form.units.label }} / Transfer Value</label>
90+
<p class="help-text">{{ cashinkind_form.units.help_text }}</p>
91+
{{ cashinkind_form.units }}
92+
<small class="sign-up-field-error">{{ cashinkind_form.units.errors }}</small>
93+
</div>
94+
</div>
95+
<div class="field-col grant-type-section">
96+
<div class="select-field is-required">
97+
<label for="{{ cashinkind_form.grant_type.id_for_label }}">{{ cashinkind_form.grant_type.label }} /
98+
Assistance Type</label>
99+
<p class="help-text">{{ cashinkind_form.grant_type.help_text }}</p>
100+
<select name="{{ cashinkind_form.grant_type.name }}"
101+
id="{{ cashinkind_form.grant_type.id_for_label }}">
102+
{% for type in cashinkind_form.grant_type %}{{ type }}{% endfor %}
103+
</select>
104+
<small class="sign-up-field-error">{{ cashinkind_form.grant_type.errors }}</small>
105+
</div>
106+
</div>
107+
</div>
108+
</div>
109+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<div class="row">
2+
<div class="multiple-fields-row three-items">
3+
<div class="field-col">
4+
<div class="select-field is-required">
5+
<label for="{{ cashinkind_form.implement_modality_type.id_for_label }}">Implement Modality</label>
6+
<p class="help-text">{{ cashinkind_form.implement_modality_type.help_text }}</p>
7+
<select
8+
name="{{ cashinkind_form.implement_modality_type.name }}"
9+
id="{{ cashinkind_form.implement_modality_type.id_for_label }}"
10+
hx-get="{% url 'get-transfer-mechanism-types' %}"
11+
hx-trigger="change"
12+
hx-target="#{{ cashinkind_form.transfer_mechanism_type.id_for_label }}"
13+
hx-swap="innerHTML"
14+
>
15+
{% for type in cashinkind_form.implement_modality_type %}{{ type }}{% endfor %}
16+
</select>
17+
<div class="sign-up-field-error">{{ cashinkind_form.implement_modality_type.errors }}</div>
18+
</div>
19+
</div>
20+
<div class="field-col">
21+
<div class="select-field is-required">
22+
<label for="{{ cashinkind_form.transfer_mechanism_type.id_for_label }}">Transfer Mechanism</label>
23+
<p class="help-text">{{ cashinkind_form.transfer_mechanism_type.help_text }}</p>
24+
<select
25+
name="{{ cashinkind_form.transfer_mechanism_type.name }}"
26+
id="{{ cashinkind_form.transfer_mechanism_type.id_for_label }}"
27+
hx-get="{% url 'get-unit-types' %}"
28+
hx-trigger="change"
29+
hx-target="#{{ cashinkind_form.unit_type.id_for_label }}"
30+
hx-swap="innerHTML"
31+
>
32+
{% for type in cashinkind_form.transfer_mechanism_type %}{{ type }}{% endfor %}
33+
</select>
34+
<div class="sign-up-field-error">{{ cashinkind_form.transfer_mechanism_type.errors }}</div>
35+
</div>
36+
</div>
37+
<div class="field-col">
38+
<div class="select-field">
39+
<label for="{{ cashinkind_form.package_type.id_for_label }}">Package Type</label>
40+
<p class="help-text">{{ cashinkind_form.package_type.help_text }}</p>
41+
<select
42+
name="package_type"
43+
id="{{ cashinkind_form.package_type.id_for_label }}">
44+
{% for type in cashinkind_form.package_type %}{{ type }}{% endfor %}
45+
</select>
46+
<small class="sign-up-field-error">{{ cashinkind_form.package_type.errors }}</small>
47+
</div>
48+
</div>
49+
<div class="field-col food-section">
50+
<div class="select-field">
51+
<label for="{{cashinkind_form.ration_type.id_for_label}}">Ration Type</label>
52+
<p class="help-text">{{cashinkind_form.ration_type.help_text}}</p>
53+
<select name="{{cashinkind_form.ration_type.name}}"
54+
id="{{cashinkind_form.ration_size.id_for_label}}">
55+
{% for type in cashinkind_form.ration_type %}{{ type }}{% endfor %}
56+
</select>
57+
<small class="sign-up-field-error">{{cashinkind_form.ration_type.errors}}</small>
58+
</div>
59+
</div>
60+
<div class="field-col food-section">
61+
<div class="select-field">
62+
<label for="{{cashinkind_form.ration_size.id_for_label}}">Ration Size</label>
63+
<p class="help-text">{{cashinkind_form.ration_size.help_text}}</p>
64+
{{cashinkind_form.ration_size}}
65+
<small class="sign-up-field-error">{{cashinkind_form.ration_size.errors}}</small>
66+
</div>
67+
</div>
68+
<div class="field-col food-section">
69+
<div class="select-field is-required">
70+
<label for="{{ cashinkind_form.transfer_category.id_for_label }}">
71+
{{cashinkind_form.transfer_category.label }}
72+
</label>
73+
<p class="help-text">{{ cashinkind_form.transfer_category.help_text }}</p>
74+
<select name="{{cashinkind_form.transfer_category.name}}"
75+
id="{{cashinkind_form.transfer_category.id_for_label}}"
76+
>
77+
{% for type in cashinkind_form.transfer_category %}{{ type }}{% endfor %}
78+
</select>
79+
<small class="sign-up-field-error">{{ cashinkind_form.transfer_category.errors }}</small>
80+
</div>
81+
</div>
82+
<div class="field-col">
83+
<div class="select-field">
84+
<label>{{ cashinkind_form.no_of_transfers.label }}</label>
85+
<p class="help-text">{{ cashinkind_form.no_of_transfers.help_text }}</p>
86+
{{ cashinkind_form.no_of_transfers }}
87+
<small class="sign-up-field-error">{{ cashinkind_form.no_of_transfers.errors }}</small>
88+
</div>
89+
</div>
90+
<div class="field-col">
91+
<div class="select-field">
92+
<label>{{ cashinkind_form.units.label }} / Transfer Value</label>
93+
<p class="help-text">{{ cashinkind_form.units.help_text }}</p>
94+
{{ cashinkind_form.units }}
95+
<small class="sign-up-field-error">{{ cashinkind_form.units.errors }}</small>
96+
</div>
97+
</div>
98+
</div>
99+
</div>
100+

0 commit comments

Comments
 (0)