On transaction detail by commodity page, show total by commodity

This commit is contained in:
RunasSudo 2020-05-11 00:20:54 +10:00
parent f470182e49
commit b729b53ceb
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 18 additions and 2 deletions

View File

@ -100,6 +100,18 @@
</tr>
{% endfor %}
{% for amount in closing_balance.strip_prices().amounts %}
<tr class="total explicit-rules{% if loop.first %} trn-first{% endif %}{% if loop.last %} trn-last{% endif %}" style="{% if loop.first %}border-top: 1pt solid black;{% endif %}{% if loop.last %}border-bottom: 1pt solid black;{% endif %}">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
{{ amount|abs|bt(True) }}
<td>{% if amount >= 0 %}Dr{% else %}Cr{% endif %}</td>
</tr>
{% endfor %}
<tr class="total trn-first trn-last">
<td></td>
<td></td>

View File

@ -271,10 +271,14 @@ class Balance:
def __init__(self, amounts=None):
self.amounts = amounts or []
def tidy(self):
def strip_prices(self):
new_amounts = []
for amount in self.amounts:
new_amount = next((a for a in new_amounts if a.commodity == amount.commodity), None)
new_amount = next((a for a in new_amounts if a.commodity.name == amount.commodity.name), None)
if new_amount is None:
new_amounts.append(Amount(amount.amount, amount.commodity.strip_price()))
else:
new_amount.amount += amount.amount
return Balance(new_amounts)
def clean(self):