Add total profit/loss to budget display
This commit is contained in:
parent
d4419792b2
commit
43fd262430
@ -113,6 +113,10 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Total Profit (Loss)</td>
|
||||
<td style="text-align: right; font-weight: bold; padding-right: 2.3em;">{{ '${:.2f}'.format(revision.get_revenue_total() - revision.get_expense_total()) if revision.get_revenue_total() >= revision.get_expense_total() else '(${:.2f})'.format(revision.get_expense_total() - revision.get_revenue_total()) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
@ -149,6 +149,10 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Total Profit (Loss)</td>
|
||||
<td style="text-align: right; font-weight: bold; padding-right: 2.3em;">{{ '${:.2f}'.format(revision.get_revenue_total() - revision.get_expense_total()) if revision.get_revenue_total() >= revision.get_expense_total() else '(${:.2f})'.format(revision.get_expense_total() - revision.get_revenue_total()) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
@ -96,6 +96,22 @@ class BudgetRevision(models.Model):
|
||||
self.action = BudgetAction.UPDATE_STATE.value
|
||||
self.save()
|
||||
|
||||
def get_revenue_total(self):
|
||||
total = Decimal(0)
|
||||
for item in self.revenue:
|
||||
total += Decimal(item['Unit price']) * item['Units']
|
||||
if item['IWT']:
|
||||
total -= (Decimal(item['Unit price']) - (Decimal(item['Unit price']) - Decimal('0.8')) / Decimal('1.019')) * item['Units']
|
||||
return total
|
||||
|
||||
def get_expense_total(self):
|
||||
total = Decimal(0)
|
||||
for item in self.expense:
|
||||
total += Decimal(item['Unit price']) * item['Units']
|
||||
if not self.expense_no_emergency_fund:
|
||||
total *= Decimal('1.05')
|
||||
return total
|
||||
|
||||
# Access control
|
||||
|
||||
def can_view(self, user):
|
||||
|
Loading…
Reference in New Issue
Block a user