Skip to content

Commit

Permalink
Merge pull request #251 from softwaresaved/242
Browse files Browse the repository at this point in the history
Add invoice option to claim submission and invoice reference
  • Loading branch information
rgaiacs authored Mar 1, 2017
2 parents 7cecebe + af610d8 commit 29f3af9
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lowfat/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ class Meta:
'claim',
'amount_claimed',
'justification_for_extra',
'invoice',
'final',
'recipient_fullname',
'recipient_email',
Expand All @@ -401,6 +402,7 @@ class Meta:
'fund': 'Choose approved funding request',
'claim': 'PDF copy of claim and receipt(s)',
'justification_for_extra': "If the claim is greater than 20% of the amount requested please provide justification",
'invoice': "Do you need to claim this expense over a invoice?",
'final': "Is this the final expense claim associated with this funding request?",
'recipient_fullname': "Full name",
'recipient_email': "E-mail",
Expand Down Expand Up @@ -431,6 +433,7 @@ def __init__(self, *args, **kwargs):
),
HTML("{% if fund %}<p class='text-warning'>Note that you only have <strong>£{{ fund.expenses_claimed_left }}</strong> left.</p>{% endif %}"),
'justification_for_extra',
'invoice',
'final',
HTML("<h2>Recipient</h2><p>Only fill this part if you are claiming this expense on behalf of someone.</p>"),
'recipient_fullname',
Expand Down
35 changes: 35 additions & 0 deletions lowfat/migrations/0089_auto_20170301_2349.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-01 23:49
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lowfat', '0088_auto_20170301_1411'),
]

operations = [
migrations.AddField(
model_name='expense',
name='invoice',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='expense',
name='invoice_reference',
field=models.TextField(blank=True, max_length=8, null=True),
),
migrations.AddField(
model_name='historicalexpense',
name='invoice',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='historicalexpense',
name='invoice_reference',
field=models.TextField(blank=True, max_length=8, null=True),
),
]
9 changes: 9 additions & 0 deletions lowfat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .jacs import JACS_LEVEL_2

MAX_CHAR_LENGTH = 120
MAX_INVOICE_REFERENCE_LENGTH = 8 # e.g. SSIFxxxx
MAX_PHONE_LENGTH = 14
MAX_DIGITS = 10

Expand Down Expand Up @@ -475,6 +476,11 @@ class Meta:
null=False,
blank=False
)
invoice_reference = models.TextField(
max_length=MAX_INVOICE_REFERENCE_LENGTH,
null=True,
blank=True
)

# Form
fund = models.ForeignKey('Fund')
Expand All @@ -492,6 +498,9 @@ class Meta:
max_length=MAX_CHAR_LENGTH,
blank=True
)
invoice = models.BooleanField(
default=False
)
final = models.BooleanField(
default=False
)
Expand Down
6 changes: 6 additions & 0 deletions lowfat/templates/lowfat/expense_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ <h1>Expense Detail
<th>Amount authorized for payment</th>
<td>{{ expense.amount_authorized_for_payment }}</td>
</tr>
{% if expense.invoice %}
<tr>
<th>Invoice reference</th>
<td>{{ expense.invoice_reference }}</td>
</tr>
{% endif %}
<tr>
<th>Status</th>
<td>{{ expense.get_status_display }}</td>
Expand Down
12 changes: 12 additions & 0 deletions lowfat/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
from hashlib import blake2b # pylint: disable=no-name-in-module

import django.utils
from django.contrib import messages
Expand All @@ -20,6 +21,8 @@
from .forms import *
from .mail import *

INVOICE_HASH = blake2b(digest_size=2) # to produce len(h.digest()) == 4

def index(request):
context = {
'claimants': Claimant.objects.exclude(selected=False).order_by('application_year').reverse(),
Expand Down Expand Up @@ -406,6 +409,15 @@ def expense_form(request):

if formset.is_valid():
expense = formset.save()
if expense.invoice:
INVOICE_HASH.update(bytes("{} - {} #{}".format(
expense.fund.claimant.fullname,
expense.fund.name,
expense.relative_number
), 'utf-8'))
expense.invoice_reference = "SSIF{}".format(
INVOICE_HASH.hexdigest())
expense.save()
messages.success(request, 'Expense saved on our database.')
if formset.fields["send_email_field"]:
new_expense_notification(expense)
Expand Down

0 comments on commit 29f3af9

Please sign in to comment.