Add total profit/loss to budget display

This commit is contained in:
Yingtong Li 2020-01-17 21:30:52 +11:00
parent d4419792b2
commit 43fd262430
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 24 additions and 0 deletions

View File

@ -113,6 +113,10 @@
{% endif %} {% endif %}
</td> </td>
</tr> </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> </tbody>
</table> </table>
{% endblock %} {% endblock %}

View File

@ -149,6 +149,10 @@
{% endif %} {% endif %}
</td> </td>
</tr> </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> </tbody>
</table> </table>

View File

@ -96,6 +96,22 @@ class BudgetRevision(models.Model):
self.action = BudgetAction.UPDATE_STATE.value self.action = BudgetAction.UPDATE_STATE.value
self.save() 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 # Access control
def can_view(self, user): def can_view(self, user):