From 1d88659fe8258c3e6fb4258c80226ac3818e0bc7 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Sat, 22 Aug 2015 14:50:08 +0200
Subject: [PATCH] Fix some bugs with referentials and enhancements

---
 src/cutecoin/core/money/quant_zerosum.py    | 18 ++++++++-----
 src/cutecoin/core/money/quantitative.py     | 28 ++++++++++++-------
 src/cutecoin/core/money/relative.py         | 30 ++++++++++++++-------
 src/cutecoin/core/money/relative_zerosum.py | 30 ++++++++++++++-------
 src/cutecoin/gui/wallets_tab.py             |  6 ++---
 5 files changed, 72 insertions(+), 40 deletions(-)

diff --git a/src/cutecoin/core/money/quant_zerosum.py b/src/cutecoin/core/money/quant_zerosum.py
index 340c350a..17a8dbc3 100644
--- a/src/cutecoin/core/money/quant_zerosum.py
+++ b/src/cutecoin/core/money/quant_zerosum.py
@@ -42,16 +42,20 @@ class QuantitativeZSum:
     def differential(self):
         return Quantitative(self.amount, self.community, self.app).compute()
 
-    def localized(self, pretty_print=False):
+    def localized(self, units=False, international_system=False):
         value = self.value()
-        if pretty_print:
+        if international_system:
             pass
         else:
-            strvalue = QLocale().toString(float(value), 'f', 0)
+            localized_value = QLocale().toString(float(value), 'f', 0)
+
+        if units:
             return QCoreApplication.translate("QuantitativeZSum",
                                               QuantitativeZSum._REF_STR_) \
-                .format(strvalue,
-                        self.community.short_currency)
+                .format(localized_value,
+                        self.community.short_currency if units else "")
+        else:
+            return localized_value
 
-    def diff_localized(self, pretty_print=False):
-        return Quantitative(self.amount, self.community, self.app).localized(pretty_print)
\ No newline at end of file
+    def diff_localized(self, units=False, international_system=False):
+        return Quantitative(self.amount, self.community, self.app).localized(units, international_system)
\ No newline at end of file
diff --git a/src/cutecoin/core/money/quantitative.py b/src/cutecoin/core/money/quantitative.py
index aae90749..03bc237a 100644
--- a/src/cutecoin/core/money/quantitative.py
+++ b/src/cutecoin/core/money/quantitative.py
@@ -36,24 +36,32 @@ class Quantitative():
     def differential(self):
         return self.value()
 
-    def localized(self, pretty_print=False):
+    def localized(self, units=False, international_system=False):
         value = self.value()
-        if pretty_print:
+        if international_system:
             pass
         else:
-            strvalue = QLocale().toString(float(value), 'f', 0)
+            localized_value = QLocale().toString(float(value), 'f', 0)
+
+        if units:
             return QCoreApplication.translate("Quantitative",
                                               Quantitative._REF_STR_) \
-                .format(strvalue,
-                        self.community.short_currency)
+                .format(localized_value,
+                        self.community.short_currency if units else "")
+        else:
+            return localized_value
 
-    def diff_localized(self, pretty_print=False):
+    def diff_localized(self, units=False, international_system=False):
         value = self.differential()
-        if pretty_print:
+        if international_system:
             pass
         else:
-            strvalue = QLocale().toString(float(value), 'f', 0)
+            localized_value = QLocale().toString(float(value), 'f', 0)
+
+        if units:
             return QCoreApplication.translate("Quantitative",
                                               Quantitative._REF_STR_) \
-                .format(strvalue,
-                        self.community.short_currency)
+                .format(localized_value,
+                        self.community.short_currency if units else "")
+        else:
+            return localized_value
diff --git a/src/cutecoin/core/money/relative.py b/src/cutecoin/core/money/relative.py
index bcc29ffe..fa780d65 100644
--- a/src/cutecoin/core/money/relative.py
+++ b/src/cutecoin/core/money/relative.py
@@ -39,20 +39,30 @@ class Relative():
     def differential(self):
         return self.value()
 
-    def localized(self, pretty_print=False):
+    def localized(self, units=False, international_system=False):
         value = self.value()
-        if pretty_print:
+        if international_system:
             pass
         else:
-            strvalue = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
-            return QCoreApplication.translate("Relative", Relative._REF_STR_).format(strvalue,
-                                                                                        self.community.short_currency)
+            localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
 
-    def diff_localized(self, pretty_print=False):
+        if units:
+            return QCoreApplication.translate("Relative", Relative._REF_STR_) \
+                .format(localized_value,
+                        self.community.short_currency if units else "")
+        else:
+            return localized_value
+
+    def diff_localized(self, units=False, international_system=False):
         value = self.differential()
-        if pretty_print:
+        if international_system:
             pass
         else:
-            strvalue = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
-            return QCoreApplication.translate("Relative", Relative._REF_STR_).format(strvalue,
-                                                                                        self.community.short_currency)
+            localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
+
+        if units:
+            return QCoreApplication.translate("Relative", Relative._REF_STR_)\
+            .format(localized_value,
+                    self.community.short_currency if units else "")
+        else:
+            return localized_value
diff --git a/src/cutecoin/core/money/relative_zerosum.py b/src/cutecoin/core/money/relative_zerosum.py
index b4148304..788772ac 100644
--- a/src/cutecoin/core/money/relative_zerosum.py
+++ b/src/cutecoin/core/money/relative_zerosum.py
@@ -44,20 +44,30 @@ class RelativeZSum:
     def differential(self):
         return Relative(self.amount, self.community, self.app).value()
 
-    def localized(self, pretty_print=False):
+    def localized(self, units=False, international_system=False):
         value = self.value()
-        if pretty_print:
+        if international_system:
             pass
         else:
-            strvalue = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
-            return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_).format(strvalue,
-                                                                                         self.community.short_currency)
+            localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
 
-    def diff_localized(self, pretty_print=False):
+        if units:
+            return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_)\
+                .format(localized_value,
+                        self.community.short_currency if units else "")
+        else:
+            return localized_value
+
+    def diff_localized(self, units=False, international_system=False):
         value = self.differential()
-        if pretty_print:
+
+        if international_system:
             pass
         else:
-            strvalue = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
-            return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_).format(strvalue,
-                                                                                         self.community.short_currency)
+            localized_value = QLocale().toString(float(value), 'f', self.app.preferences['digits_after_comma'])
+
+        if units:
+            return QCoreApplication.translate("RelativeZSum", RelativeZSum._REF_STR_)\
+                .format(localized_value, self.community.short_currency if units else "")
+        else:
+            return localized_value
diff --git a/src/cutecoin/gui/wallets_tab.py b/src/cutecoin/gui/wallets_tab.py
index 06fae7b6..32e601f3 100644
--- a/src/cutecoin/gui/wallets_tab.py
+++ b/src/cutecoin/gui/wallets_tab.py
@@ -141,9 +141,9 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab):
         maximum = self.community.monetary_mass
         # if referential type is quantitative...
             # display int values
-        localized_amount = self.account.current_ref(amount, self.community, self.app).localized()
-        localized_minimum = self.account.current_ref(maximum, self.community, self.app).localized()
-        localized_maximum = self.account.current_ref(0, self.community, self.app).localized()
+        localized_amount = self.account.current_ref(amount, self.community, self.app).localized(units=True)
+        localized_minimum = self.account.current_ref(0, self.community, self.app).localized(units=True)
+        localized_maximum = self.account.current_ref(maximum, self.community, self.app).localized(units=True)
 
         # set infos in label
         self.label_balance.setText(
-- 
GitLab