feat: convert returns None if Currency convertion has same currency for both or if amount if 0

This commit is contained in:
Herculino Trotta
2024-11-16 23:59:46 -03:00
parent 2b8e8408e3
commit 2623fb3da5
3 changed files with 12 additions and 14 deletions

View File

@@ -43,12 +43,10 @@ def get_exchange_rate(
def convert(amount, from_currency: Currency, to_currency: Currency, date=None):
if from_currency == to_currency:
return (
amount,
to_currency.prefix,
to_currency.suffix,
to_currency.decimal_places,
)
return None, None, None, None
if amount == 0:
return None, None, None, None
if date is None:
date = timezone.localtime(timezone.now())

View File

@@ -37,7 +37,7 @@
</div>
</div>
</div>
{% if currency.exchanged %}
{% if currency.exchanged and currency.exchanged.amount %}
<div>
<c-amount.display
:amount="currency.exchanged.amount"

View File

@@ -15,7 +15,7 @@
:suffix="entry.suffix"
:decimal_places="entry.decimal_places"></c-amount.display>
</div>
{% if entry.exchanged %}
{% if entry.exchanged and entry.exchanged.amount %}
<div>
<c-amount.display
:amount="entry.exchanged.amount"
@@ -44,7 +44,7 @@
:suffix="entry.suffix"
:decimal_places="entry.decimal_places"></c-amount.display>
</div>
{% if entry.exchanged %}
{% if entry.exchanged and entry.exchanged.amount %}
<div>
<c-amount.display
:amount="entry.exchanged.amount"
@@ -74,7 +74,7 @@
:decimal_places="entry.decimal_places"
color="{% if entry.amount > 0 %}green{% elif entry.amount < 0 %}red{% endif %}"></c-amount.display>
</div>
{% if entry.exchanged %}
{% if entry.exchanged and entry.exchanged.amount %}
<div>
<c-amount.display
:amount="entry.exchanged.amount"
@@ -104,7 +104,7 @@
:suffix="entry.suffix"
:decimal_places="entry.decimal_places"></c-amount.display>
</div>
{% if entry.exchanged %}
{% if entry.exchanged and entry.exchanged.amount %}
<div>
<c-amount.display
:amount="entry.exchanged.amount"
@@ -133,7 +133,7 @@
:suffix="entry.suffix"
:decimal_places="entry.decimal_places"></c-amount.display>
</div>
{% if entry.exchanged %}
{% if entry.exchanged and entry.exchanged.amount %}
<div>
<c-amount.display
:amount="entry.exchanged.amount"
@@ -163,7 +163,7 @@
:decimal_places="entry.decimal_places"
color="{% if entry.amount > 0 %}green{% elif entry.amount < 0 %}red{% endif %}"></c-amount.display>
</div>
{% if entry.exchanged %}
{% if entry.exchanged and entry.exchanged.amount %}
<div>
<c-amount.display
:amount="entry.exchanged.amount"
@@ -194,7 +194,7 @@
:decimal_places="entry.decimal_places"
color="{% if entry.amount > 0 %}green{% elif entry.amount < 0 %}red{% endif %}"></c-amount.display>
</div>
{% if entry.exchanged %}
{% if entry.exchanged and entry.exchanged.amount %}
<div>
<c-amount.display
:amount="entry.exchanged.amount"