Skip to content

Commit

Permalink
SPWS01-72
Browse files Browse the repository at this point in the history
  • Loading branch information
neerajdarwin committed Jul 8, 2024
1 parent a24ce44 commit 7cfcb4a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 22 deletions.
20 changes: 10 additions & 10 deletions ProjectApplication/project_core/forms/budget_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ def clean(self):
# amount is removed from the form.cleaned_data
return

for budget_item_form in self.forms:
amount = budget_item_form.cleaned_data['amount'] or 0

budget_amount += amount

if budget_amount > maximum_budget:
raise forms.ValidationError(
'Maximum allowed budget for this call is {} CHF. Your total proposed budget is {} CHF'.format(
thousands_separator(maximum_budget),
thousands_separator(budget_amount)))
# for budget_item_form in self.forms:
# amount = budget_item_form.cleaned_data['amount'] or 0
#
# budget_amount += amount
#
# if budget_amount > maximum_budget:
# raise forms.ValidationError(
# 'Maximum allowed budget for this call is {} CHF. Your total proposed budget is {} CHF'.format(
# thousands_separator(maximum_budget),
# thousands_separator(budget_amount)))

def save_budgets(self, proposal):
for form in self.forms:
Expand Down
12 changes: 6 additions & 6 deletions ProjectApplication/project_core/forms/proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ def clean(self):

errors = {}

if 'overall_budget' in cleaned_data and cleaned_data['overall_budget'] is not None:
if cleaned_data['overall_budget'] < 0:
errors['overall_budget'] = 'Budget needs to be greater than 0'
elif cleaned_data['overall_budget'] > self._call.budget_maximum:
errors['overall_budget'] = f'Budget is greater than the maximum budget for this call: ' \
f'{thousands_separator(self._call.budget_maximum)} CHF'
# if 'overall_budget' in cleaned_data and cleaned_data['overall_budget'] is not None:
# if cleaned_data['overall_budget'] < 0:
# errors['overall_budget'] = 'Budget needs to be greater than 0'
# elif cleaned_data['overall_budget'] > self._call.budget_maximum:
# errors['overall_budget'] = f'Budget is greater than the maximum budget for this call: ' \
# f'{thousands_separator(self._call.budget_maximum)} CHF'

if self._call.keywords_in_general_information_question:
keywords_validation(errors, cleaned_data, 'keywords')
Expand Down
8 changes: 4 additions & 4 deletions ProjectApplication/project_core/static/css/css.css
Original file line number Diff line number Diff line change
Expand Up @@ -392,20 +392,20 @@ is from: https://github.com/yourlabs/django-autocomplete-light/issues/1149
color: #000000;
}

.progressbar .step.valid {
.progressbar .step.valid,.progressbar .step.budgetvalid {
color: #3EC27B;
}

.progressbar .step.valid .bullet::before {
.progressbar .step.valid .bullet::before,.progressbar .step.budgetvalid .bullet::before {
content: "\2713";
color: #3EC27B;
}

.progressbar .step.invalid {
.progressbar .step.invalid, .progressbar .step.budgetinvalid {
color: #ff0000;
}

.progressbar .step.invalid .bullet::before {
.progressbar .step.invalid .bullet::before,.progressbar .step.budgetinvalid .bullet::before {
content: "\292C";
color: #ff0000;
}
Expand Down
58 changes: 57 additions & 1 deletion ProjectApplication/project_core/static/js/wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,61 @@ $(document).ready(function () {
var errorMessages = [];
$('#id_data_collection_form-privacy_policy').removeAttr('required');

function validateBudgetItems() {
var totalSum = 0;
errorMessages = []; // Clear existing error messages for this validation
var max_budget = $('#total_budget').val();
$('.budget-item').each(function () {
var detailsField = $(this).find('textarea[name$="-details"]');
var amountField = $(this).find('input[name$="-amount"]');
var detailsValue = detailsField.val().trim();
var amountValue = amountField.val().trim();
var formGroupDetails = detailsField.closest('.form-group');
var formGroupAmount = amountField.closest('.form-group');

// Clear previous error messages
formGroupDetails.find('.error-message').remove();
formGroupAmount.find('.error-message').remove();
formGroupDetails.removeClass("has-error");
formGroupAmount.removeClass("has-error");

var errorMessage = 'Both Details and Total (CHF) fields are required.';
var amountErrorMessage = 'Total (CHF) must be a number.';

if ((detailsValue && !amountValue) || (!detailsValue && amountValue)) {
if (!detailsValue) {
formGroupDetails.addClass("has-error");
formGroupDetails.append('<span class="error-message is-invalid">' + errorMessage + '</span>');
errorMessages.push(errorMessage);
}
if (!amountValue) {
formGroupAmount.addClass("has-error");
formGroupAmount.append('<span class="error-message is-invalid">' + errorMessage + '</span>');
errorMessages.push(errorMessage);
}
}

if (amountValue) {
var amount = parseFloat(amountValue);
if (isNaN(amount) || amount < 0) {
formGroupAmount.addClass("has-error");
formGroupAmount.append('<span class="error-message is-invalid">' + amountErrorMessage + '</span>');
errorMessages.push(amountErrorMessage);
}else{
totalSum += parseFloat(amountValue);
}
}
});
if (totalSum > max_budget) {
alert('Budget is greater than the maximum budget for this call.');
var budget_step_class = $('.budget-table').closest('fieldset').attr('data-step');
$("." + budget_step_class).addClass("budgetinvalid").removeClass("budgetvalid");
}else{
var budget_step_class = $('.budget-table').closest('fieldset').attr('data-step');
$("." + budget_step_class).addClass("budgetvalid").removeClass("budgetinvalid");
}
}

function checkDuplicateProposal(proposalTitle, callId, callback) {
$.ajax({
url: '/check_duplicate_proposal/', // URL to check for duplicates
Expand Down Expand Up @@ -51,7 +106,7 @@ $(document).ready(function () {

var input = $(this);
if (input.hasClass('modelselect2multiple')) {
return true;
return true;
}
var value;

Expand Down Expand Up @@ -88,6 +143,7 @@ $(document).ready(function () {
}
});

validateBudgetItems();

var keywordsInput = $("select[name='proposal_application_form-keywords']");
if (keywordsInput.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% load thousands_separator %}

Maximum budget: {{ maximum_budget|thousands_separator }} CHF
<input type="hidden" id="total_budget" value="{{ maximum_budget}}">
<p>
For each cost category, please give details of all items and related costs.<br>
For details on eligible costs and budget structure, please refer to the call text.
Expand All @@ -20,7 +21,7 @@ Maximum budget: {{ maximum_budget|thousands_separator }} CHF
{% endfor %}
{% endfor %}

<table class="table table-striped table-sm">
<table class="table table-striped table-sm budget-table">
<thead>
<tr>
{% for field in budget_application_form.forms.0.visible_fields %}
Expand Down

0 comments on commit 7cfcb4a

Please sign in to comment.