From 342292ca9f080d2600edf07f28d1798ebe814559 Mon Sep 17 00:00:00 2001
From: zorun
{{ _("When?") }} | {{ _("Who paid?") }} | {{ _("For what?") }} | {{ _("For whom?") }} | {{ _("How much?") }} | {{ _("Actions") }} | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{{ _("When?") }} + | {{ _("Who paid?") }} + | {{ _("For what?") }} + | {{ _("For whom?") }} + | {{ _("How much?") }} + {% if g.project.default_currency != "No Currency" %} + | {{ _("Amount in %(currency)s", currency=g.project.default_currency) }} + {%- else -%} + | {{ _("Amount") }} + {% endif %} + | {{ _("Actions") }} | |||||||||||||
{{ "%0.2f"|format(bill.amount) }} ({{ "%0.2f"|format(bill.pay_each()) }} {{ _("each") }}) | ++ {% if bill.original_currency != "No Currency" %} + {{ "%0.2f"|format(bill.amount) }} {{bill.original_currency}} ({{ "%0.2f"|format(bill.pay_each_default(bill.amount)) }} {{bill.original_currency}} {{ _(" each") }}) + {%- else -%} + {{ "%0.2f"|format(bill.amount) }} ({{ "%0.2f"|format(bill.pay_each_default(bill.amount)) }} {{ _(" each") }}) + {% endif %} + | +{{ "%0.2f"|format(bill.converted_amount) }} |
{{ _('edit') }}
{{ _('delete') }}
diff --git a/ihatemoney/tests/tests.py b/ihatemoney/tests/tests.py
index 62cb0485..fb314bfc 100644
--- a/ihatemoney/tests/tests.py
+++ b/ihatemoney/tests/tests.py
@@ -6,7 +6,7 @@ import json
import os
from time import sleep
import unittest
-from unittest.mock import patch
+from unittest.mock import MagicMock, patch
from flask import session
from flask_testing import TestCase
@@ -14,6 +14,7 @@ from sqlalchemy import orm
from werkzeug.security import check_password_hash, generate_password_hash
from ihatemoney import history, models, utils
+from ihatemoney.currency_convertor import CurrencyConverter
from ihatemoney.manage import DeleteProject, GenerateConfig, GeneratePasswordHash
from ihatemoney.run import create_app, db, load_configuration
from ihatemoney.versioning import LoggingMode
@@ -59,6 +60,7 @@ class BaseTestCase(TestCase):
"id": name,
"password": name,
"contact_email": f"{name}@notmyidea.org",
+ "default_currency": "USD",
},
)
@@ -68,6 +70,7 @@ class BaseTestCase(TestCase):
name=str(name),
password=generate_password_hash(name),
contact_email=f"{name}@notmyidea.org",
+ default_currency="USD",
)
models.db.session.add(project)
models.db.session.commit()
@@ -254,6 +257,7 @@ class BudgetTestCase(IhatemoneyTestCase):
"id": "raclette",
"password": "party",
"contact_email": "raclette@notmyidea.org",
+ "default_currency": "USD",
},
)
@@ -273,6 +277,7 @@ class BudgetTestCase(IhatemoneyTestCase):
"id": "raclette", # already used !
"password": "party",
"contact_email": "raclette@notmyidea.org",
+ "default_currency": "USD",
},
)
@@ -290,6 +295,7 @@ class BudgetTestCase(IhatemoneyTestCase):
"id": "raclette",
"password": "party",
"contact_email": "raclette@notmyidea.org",
+ "default_currency": "USD",
},
)
@@ -310,6 +316,7 @@ class BudgetTestCase(IhatemoneyTestCase):
"id": "raclette",
"password": "party",
"contact_email": "raclette@notmyidea.org",
+ "default_currency": "USD",
},
)
@@ -329,6 +336,7 @@ class BudgetTestCase(IhatemoneyTestCase):
"id": "raclette",
"password": "party",
"contact_email": "raclette@notmyidea.org",
+ "default_currency": "USD",
},
)
@@ -841,6 +849,7 @@ class BudgetTestCase(IhatemoneyTestCase):
"contact_email": "alexis@notmyidea.org",
"password": "didoudida",
"logging_preference": LoggingMode.ENABLED.value,
+ "default_currency": "USD",
}
resp = self.client.post("/raclette/edit", data=new_data, follow_redirects=True)
@@ -849,6 +858,7 @@ class BudgetTestCase(IhatemoneyTestCase):
self.assertEqual(project.name, new_data["name"])
self.assertEqual(project.contact_email, new_data["contact_email"])
+ self.assertEqual(project.default_currency, new_data["default_currency"])
self.assertTrue(check_password_hash(project.password, new_data["password"]))
# Editing a project with a wrong email address should fail
@@ -1099,6 +1109,7 @@ class BudgetTestCase(IhatemoneyTestCase):
"payer": 1,
"payed_for": [1, 2, 3, 4],
"amount": "10.0",
+ "original_currency": "USD",
},
)
@@ -1110,6 +1121,7 @@ class BudgetTestCase(IhatemoneyTestCase):
"payer": 2,
"payed_for": [1, 3],
"amount": "200",
+ "original_currency": "USD",
},
)
@@ -1121,6 +1133,7 @@ class BudgetTestCase(IhatemoneyTestCase):
"payer": 3,
"payed_for": [2],
"amount": "13.33",
+ "original_currency": "USD",
},
)
@@ -1425,6 +1438,7 @@ class APITestCase(IhatemoneyTestCase):
"id": id,
"password": password,
"contact_email": contact,
+ "default_currency": "USD",
},
)
@@ -1486,6 +1500,7 @@ class APITestCase(IhatemoneyTestCase):
"id": "raclette",
"password": "raclette",
"contact_email": "not-an-email",
+ "default_currency": "USD",
},
)
@@ -1514,6 +1529,7 @@ class APITestCase(IhatemoneyTestCase):
"members": [],
"name": "raclette",
"contact_email": "raclette@notmyidea.org",
+ "default_currency": "USD",
"id": "raclette",
"logging_preference": 1,
}
@@ -1525,6 +1541,7 @@ class APITestCase(IhatemoneyTestCase):
"/api/projects/raclette",
data={
"contact_email": "yeah@notmyidea.org",
+ "default_currency": "USD",
"password": "raclette",
"name": "The raclette party",
"project_history": "y",
@@ -1542,6 +1559,7 @@ class APITestCase(IhatemoneyTestCase):
expected = {
"name": "The raclette party",
"contact_email": "yeah@notmyidea.org",
+ "default_currency": "USD",
"members": [],
"id": "raclette",
"logging_preference": 1,
@@ -1554,6 +1572,7 @@ class APITestCase(IhatemoneyTestCase):
"/api/projects/raclette",
data={
"contact_email": "yeah@notmyidea.org",
+ "default_currency": "USD",
"password": "tartiflette",
"name": "The raclette party",
},
@@ -1776,6 +1795,8 @@ class APITestCase(IhatemoneyTestCase):
"amount": 25.0,
"date": "2011-08-10",
"id": 1,
+ "converted_amount": 25.0,
+ "original_currency": "USD",
"external_link": "https://raclette.fr",
}
@@ -1845,6 +1866,8 @@ class APITestCase(IhatemoneyTestCase):
"amount": 25.0,
"date": "2011-09-10",
"external_link": "https://raclette.fr",
+ "converted_amount": 25.0,
+ "original_currency": "USD",
"id": 1,
}
@@ -1922,6 +1945,8 @@ class APITestCase(IhatemoneyTestCase):
"date": "2011-08-10",
"id": id,
"external_link": "",
+ "original_currency": "USD",
+ "converted_amount": expected_amount,
}
got = json.loads(req.data.decode("utf-8"))
@@ -2064,6 +2089,8 @@ class APITestCase(IhatemoneyTestCase):
"date": "2011-08-10",
"id": 1,
"external_link": "",
+ "converted_amount": 25.0,
+ "original_currency": "USD",
}
got = json.loads(req.data.decode("utf-8"))
self.assertEqual(
@@ -2106,6 +2133,7 @@ class APITestCase(IhatemoneyTestCase):
"id": "raclette",
"name": "raclette",
"logging_preference": 1,
+ "default_currency": "USD",
}
self.assertStatus(200, req)
@@ -2273,6 +2301,7 @@ class HistoryTestCase(IhatemoneyTestCase):
"name": "demo",
"contact_email": "demo@notmyidea.org",
"password": "demo",
+ "default_currency": "USD",
}
if logging_preference != LoggingMode.DISABLED:
@@ -2327,6 +2356,7 @@ class HistoryTestCase(IhatemoneyTestCase):
"contact_email": "demo2@notmyidea.org",
"password": "123456",
"project_history": "y",
+ "default_currency": "USD",
}
resp = self.client.post("/demo/edit", data=new_data, follow_redirects=True)
@@ -2422,6 +2452,7 @@ class HistoryTestCase(IhatemoneyTestCase):
"name": "demo2",
"contact_email": "demo2@notmyidea.org",
"password": "123456",
+ "default_currency": "USD",
}
# Keep privacy settings where they were
@@ -2850,5 +2881,23 @@ class HistoryTestCase(IhatemoneyTestCase):
self.assertEqual(len(history_list), 6)
+class TestCurrencyConverter(unittest.TestCase):
+ converter = CurrencyConverter()
+ mock_data = {"USD": 1, "EUR": 0.8115}
+ converter.get_rates = MagicMock(return_value=mock_data)
+
+ def test_only_one_instance(self):
+ one = id(CurrencyConverter())
+ two = id(CurrencyConverter())
+ self.assertEqual(one, two)
+
+ def test_get_currencies(self):
+ self.assertCountEqual(self.converter.get_currencies(), ["USD", "EUR"])
+
+ def test_exchange_currency(self):
+ result = self.converter.exchange_currency(100, "USD", "EUR")
+ self.assertEqual(result, 81.15)
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/ihatemoney/web.py b/ihatemoney/web.py
index 18ce0c7a..bbc98c4d 100644
--- a/ihatemoney/web.py
+++ b/ihatemoney/web.py
@@ -37,10 +37,10 @@ from sqlalchemy_continuum import Operation
from werkzeug.exceptions import NotFound
from werkzeug.security import check_password_hash, generate_password_hash
+from ihatemoney.currency_convertor import CurrencyConverter
from ihatemoney.forms import (
AdminAuthenticationForm,
AuthenticationForm,
- EditProjectForm,
InviteForm,
MemberForm,
PasswordReminder,
@@ -48,6 +48,7 @@ from ihatemoney.forms import (
ResetPasswordForm,
UploadForm,
get_billform_for,
+ get_editprojectform_for,
)
from ihatemoney.history import get_history, get_history_queries
from ihatemoney.models import Bill, LoggingMode, Person, Project, db
@@ -376,7 +377,7 @@ def reset_password():
@main.route("/ expenses, easily" msgstr "Gestione sus gastos compartidos fácilmente" @@ -574,7 +596,7 @@ msgid "Statistics" msgstr "Estadísticas" msgid "History" -msgstr "" +msgstr "Historial" msgid "Settings" msgstr "Configuración" @@ -634,10 +656,10 @@ msgid "Add a new bill" msgstr "Añadir una nueva factura" msgid "Newer bills" -msgstr "" +msgstr "Nuevas facturas" msgid "Older bills" -msgstr "" +msgstr "Facturas anteriores" msgid "When?" msgstr "¿Cuando?" @@ -691,7 +713,7 @@ msgstr "" "correos electrónicos." msgid "Return to home page" -msgstr "Regresar a la página principal" +msgstr "Regresar al inicio" msgid "Your projects" msgstr "Sus proyectos" @@ -750,10 +772,10 @@ msgid "Spent" msgstr "Gastado" msgid "Expenses by Month" -msgstr "" +msgstr "Gastos por mes" msgid "Period" -msgstr "" +msgstr "Período" #~ msgid "%(member)s had been added" #~ msgstr "se han añadido %(member)s" From 795efd6b58a0d4eec002eddeb4c9b0b16461a4a0 Mon Sep 17 00:00:00 2001 From: zorun {{ _("Balance") }} |
| ||||||||||||||||
{{ stat.member.name }} |
@@ -27,7 +27,7 @@
|