Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion backend/accounts/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from rest_framework.pagination import PageNumberPagination
from rest_framework import viewsets, status, filters
from django.db.models import Q
from django.core.exceptions import ValidationError
from rest_framework.response import Response

from django.contrib.auth.models import User
Expand Down Expand Up @@ -270,7 +271,7 @@ def create(self, request):

def update(self, request, pk):
return update_entry(self, request, pk)

class AccountLedgerViewSet(viewsets.ModelViewSet):
serializer_class = AccountLedgerSerializer
queryset = AccountLedger.objects.all()
Expand Down Expand Up @@ -325,6 +326,12 @@ def create(self, request):
data_set['created_by'] = self.request.user.id
data_set['modified_by'] = self.request.user.id

sewer_equal = data_set['sewer_credits'] == data_set['sewer_cap'] + data_set['sewer_trans']
non_sewer_equal = data_set['non_sewer_credits'] == data_set['roads'] + data_set['parks'] + data_set['open_space'] + data_set['storm']

if not (sewer_equal and non_sewer_equal):
raise ValidationError('Ensure sums for both sewer and non-sewer equal the sum of each of their parts.')

if 'lot' in self.request.data:
serializer = AccountLedgerSerializer(data=data_set)
if serializer.is_valid(raise_exception=True):
Expand Down
35 changes: 24 additions & 11 deletions frontend/js/components/AccountLedgerForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class AccountLedgerForm extends React.Component {
);
})(agreements.agreements));

const sewerEqual = activeForm.sewer_credits == activeForm.sewer_cap + activeForm.sewer_trans;
const nonSewerEqual = activeForm.non_sewer_credits == activeForm.parks + activeForm.storm + activeForm.roads + activeForm.open_space;

const submitEnabled =
!!accounts.accountFrom && !!accounts.accountFrom.id &&
!!accounts.accountTo && !!accounts.accountTo.id &&
Expand All @@ -118,7 +121,9 @@ class AccountLedgerForm extends React.Component {
activeForm.open_space &&
activeForm.sewer_cap &&
activeForm.sewer_trans &&
activeForm.entry_date;
activeForm.entry_date &&
sewerEqual &&
nonSewerEqual;

const currentPlat = !!plats && !!plats.currentPlat && plats.currentPlat;
const currentAccountBalance = !!accounts.accountFrom && accounts.accountFrom.current_account_balance;
Expand Down Expand Up @@ -397,11 +402,11 @@ class AccountLedgerForm extends React.Component {
</div>
<div className="row">
<div className="col-sm-6">
<FormGroup label="* Storm water" id="storm">
<FormGroup label="* Storm Water" id="storm">
<input
type="number"
className="form-control"
placeholder="Storm water"
placeholder="Storm Water"
disabled={!activeForm.entry_type}
step="0.01"
required
Expand Down Expand Up @@ -452,20 +457,22 @@ class AccountLedgerForm extends React.Component {
<button disabled={!submitEnabled} className="btn btn-lex" onClick={() => onSubmit(activeForm.plat_lot)} >
{currentUser.is_superuser || (currentUser.profile && currentUser.profile.is_supervisor) ? <div>Submit / Approve</div> : <div>Submit</div>}
</button>
{!submitEnabled ? (
<div>
<div className="clearfix" />
<span> * All required fields must be filled.</span>
</div>
) : null
}
</div>
<div className="col-xs-4">
<DeclineDelete
currentForm="/ledger/"
selectedEntry={selectedAccountLedger}
parentRoute="credit-transfer"
/>
/>
</div>
<div className="clearfix" />
<div>
<div className="clearfix" />
<span> * All required fields must be filled.</span>
<div className="clearfix" />
<span> * Ensure Sewer Capacity and Sewer Transmission equal Sewer Credits.</span>
<div className="clearfix" />
<span> * Ensure Roads, Parks, Open Spaces, and Storm Water equal Non-Sewer Credits.</span>
</div>
</form>
<div className="clearfix" />
Expand Down Expand Up @@ -708,13 +715,19 @@ function mapDispatchToProps(dispatch, params) {
if (selectedAccountLedger) {
dispatch(putAccountLedger(selectedAccountLedger))
.then((data) => {
if (!!data.error) {
dispatch(flashMessageSet(`Error: ${data.error}`, 'danger'));
}
if (data.response) {
hashHistory.push(`credit-transfer/summary/${selectedAccountLedger}`);
}
});
} else {
dispatch(postAccountLedger())
.then((data_post) => {
if (!!data_post.error) {
dispatch(flashMessageSet(`Error: ${data_post.message}`, 'danger'));
}
if (data_post.response && data_post.response.id) {
if (event === 'plat') {
hashHistory.push('credit-transfer');
Expand Down
2 changes: 1 addition & 1 deletion frontend/js/components/ReportsAdditional.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ReportsAdditional extends React.Component {
>Transaction CSV</a>
</div>
</form>
<br/>
<div className="clearfix" />
<div>
<p>Credit transfer differences between manually entered and calculated totals</p>
<a
Expand Down
5 changes: 5 additions & 0 deletions frontend/js/middlewares/apiMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default function api({ getState, dispatch }) {
});
})
.catch((error) => {
let errorMessage = 'API Call Error';
console.log('API Middleware Error: ', error); // eslint-disable-line no-console
if (error.response.status !== 500) {
const error_obj = error.response.data;
Expand All @@ -129,8 +130,12 @@ export default function api({ getState, dispatch }) {

dispatch(errorMessageSet(error_message));
}
if (error.response) {
errorMessage = error.response.data;
}
return dispatch({
type: API_CALL_ERROR,
message: errorMessage,
error,
});
});
Expand Down