Skip to content

Commit

Permalink
Include support for partial transfers for guardians
Browse files Browse the repository at this point in the history
  • Loading branch information
muhsin7 committed Dec 8, 2022
1 parent 14b3341 commit 1143287
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
40 changes: 39 additions & 1 deletion lessons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def unpaid_invoices(self):
@property
def underpaid_invoices(self):
transfer_list = self.transfers
# invoice_list = self.invoices.filter(id__in=transfer_list.values('invoice_id'))

underpaid_invoices = {}
for transfer in transfer_list:
if transfer.amount_received < transfer.invoice.price:
Expand Down Expand Up @@ -125,6 +125,40 @@ class Guardian(User):
class Meta:
proxy = True

@property
def invoices(self):
return Invoice.objects.filter(student=self)

@property
def transfers(self):
# Make sure incomplete transfers aren't repeated when displayed separately
return Transfer.objects.filter(invoice__student=self)

@property
def unpaid_invoices(self):
transfer_list = self.transfers
invoice_list = self.invoices.exclude(id__in=transfer_list.values('invoice_id'))
return invoice_list

@property
def underpaid_invoices(self):
transfer_list = self.transfers

underpaid_invoices = {}
for transfer in transfer_list:
if transfer.amount_received < transfer.invoice.price:
if(underpaid_invoices.get(transfer.invoice)):
underpaid_invoices[transfer.invoice] += transfer.amount_received
if(underpaid_invoices[transfer.invoice] >= transfer.invoice.price):
# Removes invoice from the list of underpaid invoices if the invoice is paid fully or overpaid
del underpaid_invoices[transfer.invoice]
else:
underpaid_invoices[transfer.invoice] = transfer.amount_received



return underpaid_invoices

'''Admin users'''
# manages all Admins
class AdminManager(BaseUserManager):
Expand Down Expand Up @@ -271,6 +305,10 @@ def amount_paid(self):
amount += transfer.amount_received

return amount

@property
def amount_pending(self):
return self.price - self.amount_paid


def present_or_past_date(value):
Expand Down
2 changes: 1 addition & 1 deletion lessons/templates/balance.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h6><i class="bi bi-bookmark-fill"></i> <b>Unique Reference Number</b></h6>
<div>
<h6><i class="bi bi-cash"></i> <b>Price</b></h6>
{% for invoice in invoices %}
<p>£ {{ invoice.price }}</p>
<p>£ {{ invoice.amount_pending }}</p>
{% endfor %}
</div>
</div>
Expand Down

0 comments on commit 1143287

Please sign in to comment.