Skip to content

Commit

Permalink
Merge pull request #495 from Esmat-Farjad/fix/projects_and_financial
Browse files Browse the repository at this point in the history
Fix/projects and financial
  • Loading branch information
shtayeb authored Dec 12, 2024
2 parents cd5085b + a1616d9 commit d549693
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 37 deletions.
6 changes: 5 additions & 1 deletion src/project_reports/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class Meta:
model = TargetLocationReport
fields = "__all__"
exclude = ("activity_plan_report",)
help_texts = {
"prev_assisted_by": "Select whether these people were previously assisted by another activity in the selected target location.",
"seasonal_retargeting": "Select if the beneficiaries re-assisted due to seasonal factors, such as significant weather changes.",
}
widgets = {
"beneficiary_status": forms.Select(attrs={"class": "custom-select"}),
"seasonal_retargeting": forms.CheckboxInput(),
Expand All @@ -98,7 +102,7 @@ def __init__(self, *args, **kwargs):
activity_plan=plan_report.activity_plan, state="in-progress"
)

self.fields["prev_targeted_by"].queryset = Indicator.objects.filter(
self.fields["prev_assisted_by"].queryset = Indicator.objects.filter(
activity_types__activityplan__project=plan_report.monthly_report.project
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1 on 2024-12-12 06:59

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('project_reports', '0022_remove_activityplanreport_beneficiary_status_and_more'),
]

operations = [
migrations.RenameField(
model_name='targetlocationreport',
old_name='prev_targeted_by',
new_name='prev_assisted_by',
),
]
2 changes: 1 addition & 1 deletion src/project_reports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class TargetLocationReport(models.Model):
target_location = models.ForeignKey(TargetLocation, on_delete=models.CASCADE)
location_type = models.ForeignKey(LocationType, on_delete=models.SET_NULL, null=True, blank=True)

prev_targeted_by = models.ForeignKey(Indicator, null=True, blank=True, on_delete=models.SET_NULL)
prev_assisted_by = models.ForeignKey(Indicator, null=True, blank=True, on_delete=models.SET_NULL)
seasonal_retargeting = models.BooleanField(blank=True, null=True)
beneficiary_status = models.CharField(
max_length=25,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,21 @@
<div class="row">
<div class="col col-lg">
<div class="multiple-fields-row two-items">
<div class="field-col {% if not location_report_form.prev_targeted_by.value %}hidden{% endif %}" id="{{ location_report_form.prev_targeted_by.id_for_label }}-field">
<div class="field-col {% if not location_report_form.prev_assisted_by.value %}hidden{% endif %}" id="{{ location_report_form.prev_assisted_by.id_for_label }}-field">
<div class="select-field">
<label for="{{ location_report_form.prev_targeted_by.id_for_label }}">Previously Targeted By</label>
{{location_report_form.prev_targeted_by}}
<p class="sign-up-field-error">{{ location_report_form.prev_targeted_by.errors }}</p>
<label for="{{ location_report_form.prev_assisted_by.id_for_label }}">Previously Assisted By</label>
<p class="help-text">{{ location_report_form.prev_assisted_by.help_text }}</p>
{{location_report_form.prev_assisted_by}}
<p class="sign-up-field-error">{{ location_report_form.prev_assisted_by.errors }}</p>
</div>
</div>
<div class="field-col">
<div class="input-check-holder">
{{ location_report_form.seasonal_retargeting }}
<label for="{{ location_report_form.seasonal_retargeting.id_for_label }}">
<span class="text">Beneficiaries Retargeted due to seasonality</span>
<span class="text">Beneficiaries Re-Assisted Due To Seasonality</span>
</label>
<p class="help-text">{{ location_report_form.seasonal_retargeting.help_text }}</p>
</div>
</div>
</div>
Expand Down Expand Up @@ -210,17 +212,17 @@
});

benefStatusChoice.passedElement.element.addEventListener("change",(e)=>{
const prevTargetedBySelect = document.querySelector("#{{location_report_form.prev_targeted_by.id_for_label}}-field")
const prevTargetedBySelect = document.querySelector("#{{location_report_form.prev_assisted_by.id_for_label}}-field")

if(e.target.value === "new_beneficiary"){
// display the prev_targeted_by indicator select dropdown
// display the prev_assisted_by indicator select dropdown
prevTargetedBySelect.classList.remove("hidden")
return
}

prevTargetedBySelect.classList.add("hidden")

const selectField = document.querySelector("#{{location_report_form.prev_targeted_by.id_for_label}}")
const selectField = document.querySelector("#{{location_report_form.prev_assisted_by.id_for_label}}")
selectField.value= ""
});
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/rh/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, *args, **kwargs):
user = kwargs.pop("user", None)
super().__init__(*args, **kwargs)

if self.instance.pk:
if self.instance.pk and self.instance.user:
user = self.instance.user

self.fields["budget_currency"].queryset = Currency.objects.order_by("name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
</div>
</div>
<div class="col">
<div class="input-field is-required">
<div class="input-field">
<label for="prDecs">Notes</label>
<div class="input-holder">{{ form.description }}</div>

Expand Down
7 changes: 5 additions & 2 deletions src/rh/templates/rh/projects/views/_projects_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,16 @@
{% endfor %}
</td>
<td>
{% if project.user %}
<a href="{% url 'profiles-show' project.user.username %}">
{{ project.user.username }}
{{ project.user.username }}
<svg fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-2">
<path stroke-linecap="round" stroke-linejoin="round" d="M13.5 6H5.25A2.25 2.25 0 0 0 3 8.25v10.5A2.25 2.25 0 0 0 5.25 21h10.5A2.25 2.25 0 0 0 18 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25" />
</svg>
</a>
{% else %}
<span style="color: lightgray;">Missing</span>
{% endif %}
</td>
<td>{{ project.end_date|date:"F Y" }}</td>
<td>
Expand Down Expand Up @@ -190,7 +194,6 @@ <h4>No projects found. Let's create one!</h4>
</div>
</div>
{% endif %}

{% comment %} Pagination {% endcomment %}
{% include "components/_pagination.html" with object_list=projects %}
</div>
Expand Down
13 changes: 13 additions & 0 deletions src/rh/templates/rh/projects/views/project_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,22 @@
<li class="{% if project_view %}active{% endif %}">
<a href="{% url 'projects-update' project.pk %}">Project planning</a>
</li>
{% if project.donors.all and project.budget and project.budget_currency %}
<li class="{% if financial_view %}active{% endif %}">
<a href="{% if project %}{% url 'create_project_budget_progress' project.pk %}{% else %}#{% endif %}">Financial Reports</a>
</li>
{% else %}
<li>
<a href="#" class="tooltip-red">
<span class="text-gray-7d">Financial Reports</span>
<span class="tooltip-text-red">
The project is missing {% if not project.donors.all %} Donors, {% endif %}
{% if not project.budget %} Budget, {% endif %}
{% if not project.budget_currency %} Budget Currency, {% endif %}
</span>
</a>
</li>
{% endif %}
<li class="{% if reports_view %}active{% endif %}">
<a href="{% if project %}{% url 'project_reports_home' project.pk %}{% else %}#{% endif %}">Project Reports</a>
</li>
Expand Down
43 changes: 20 additions & 23 deletions src/rh/views/budget_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
def create_project_budget_progress_view(request, project):
project = get_object_or_404(Project, pk=project)
financial_report = project.budgetprogress_set.all()

if request.method == "POST":
form = BudgetProgressForm(request.POST, project=project)
country = request.POST.get("country")
Expand Down Expand Up @@ -58,24 +58,25 @@ def create_project_budget_progress_view(request, project):
activity_names = []
donor_names_funds = {}
activity_names_funds = {}
for data in financial_report:
if data.donor.name not in donor_names_funds.keys():
donor_names_funds[data.donor.name] = data.amount_recieved
else:
donor_names_funds[data.donor.name] += data.amount_recieved

activities = " | ".join([str(ad) for ad in data.activity_domains.all()])

if activities not in activity_names_funds.keys():
activity_names_funds[activities] = data.amount_recieved
else:
activity_names_funds[activities] += data.amount_recieved
for names, funds in activity_names_funds.items():
activity_funds.append(funds)
activity_names.append(names)
for donor, fund in donor_names_funds.items():
donor_names.append(donor)
donor_funds.append(fund)
if financial_report.exists():
for data in financial_report:
if data.donor.name not in donor_names_funds.keys():
donor_names_funds[data.donor.name] = data.amount_recieved
else:
donor_names_funds[data.donor.name] += data.amount_recieved

activities = " | ".join([str(ad) for ad in data.activity_domains.all()])

if activities not in activity_names_funds.keys():
activity_names_funds[activities] = data.amount_recieved
else:
activity_names_funds[activities] += data.amount_recieved
for names, funds in activity_names_funds.items():
activity_funds.append(funds)
activity_names.append(names)
for donor, fund in donor_names_funds.items():
donor_names.append(donor)
donor_funds.append(fund)

context = {
"project": project,
Expand All @@ -86,9 +87,6 @@ def create_project_budget_progress_view(request, project):
"donor_funds": list(donor_funds),
"activity_names": list(activity_names),
"activity_funds": list(activity_funds),
"project_view": False,
"financial_view": True,
"reports_view": False,
# "progress":progress
}
return render(request, "rh/financial_reports/project_budget_progress.html", context)
Expand Down Expand Up @@ -149,7 +147,6 @@ def update_budget_progress(request, project, pk):
def delete_budget_progress(request, pk):
budget_progress = get_object_or_404(BudgetProgress, pk=pk)
if budget_progress:
print(budget_progress)
budget_progress.delete()
messages.success(request, f"{budget_progress.donor} financial report has been deleted.")
return HttpResponse(status=200)
34 changes: 34 additions & 0 deletions src/static/styles/layout/_common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,40 @@ a.text-decoration-none{
line-height: 1.25rem;
word-break: break-word;
}
.tooltip-red{
position: relative;
}
.tooltip-red .tooltip-text-red{
visibility: hidden;
position: absolute;
top: 160%;
left: -30%;
right: 0%;
background-color: #c2410c;
color: white;
font-size: 12px;
text-transform: none;
text-align: center;
padding: 5px;
width: 200px;
border-radius: 5px;
z-index: 100;

}
.tooltip-red .tooltip-text-red::after{
content: "";
position: absolute;
top: -15%;
right: 50%;
margin-top: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent #c2410c transparent ;

}
.tooltip-red:hover .tooltip-text-red{
visibility: visible;
}
.Reserved{
color: #1d4ed8;
}
Expand Down

0 comments on commit d549693

Please sign in to comment.