Skip to content
Snippets Groups Projects
Commit abad19a0 authored by Vincent Texier's avatar Vincent Texier
Browse files

Add referential type to detect quantitative or relative type

parent 2c14a842
No related branches found
No related tags found
No related merge requests found
...@@ -90,14 +90,24 @@ class Account(QObject): ...@@ -90,14 +90,24 @@ class Account(QObject):
Each account has only one key, and a key can Each account has only one key, and a key can
be locally referenced by only one account. be locally referenced by only one account.
""" """
# referentials are defined here
# it is a list of tupple, each tupple contains :
# (
# function used to calculate value,
# format string to display value,
# function used to calculate on differential value,
# format string to display differential value,
# translated name of referential,
# type relative "r" or quantitative "q" to help choose precision on display
# )
referentials = ( referentials = (
(quantitative, '{0}', quantitative, '{0}', QT_TRANSLATE_NOOP('Account', 'Units')), (quantitative, '{0}', quantitative, '{0}', QT_TRANSLATE_NOOP('Account', 'Units'), 'q'),
(relative, QT_TRANSLATE_NOOP('Account', 'UD {0}'), relative, QT_TRANSLATE_NOOP('Account', 'UD {0}'), (relative, QT_TRANSLATE_NOOP('Account', 'UD {0}'), relative, QT_TRANSLATE_NOOP('Account', 'UD {0}'),
QT_TRANSLATE_NOOP('Account', 'UD')), QT_TRANSLATE_NOOP('Account', 'UD'), 'r'),
(quantitative_zerosum, QT_TRANSLATE_NOOP('Account', 'Q0 {0}'), quantitative, '{0}', (quantitative_zerosum, QT_TRANSLATE_NOOP('Account', 'Q0 {0}'), quantitative, '{0}',
QT_TRANSLATE_NOOP('Account', 'Quant Z-sum')), QT_TRANSLATE_NOOP('Account', 'Quant Z-sum'), 'q'),
(relative_zerosum, QT_TRANSLATE_NOOP('Account', 'R0 {0}'), relative, QT_TRANSLATE_NOOP('Account', 'UD {0}'), (relative_zerosum, QT_TRANSLATE_NOOP('Account', 'R0 {0}'), relative, QT_TRANSLATE_NOOP('Account', 'UD {0}'),
QT_TRANSLATE_NOOP('Account', 'Relat Z-sum')) QT_TRANSLATE_NOOP('Account', 'Relat Z-sum'), 'r')
) )
loading_progressed = pyqtSignal(int, int) loading_progressed = pyqtSignal(int, int)
...@@ -250,6 +260,13 @@ class Account(QObject): ...@@ -250,6 +260,13 @@ class Account(QObject):
text = QCoreApplication.translate('Account', Account.referentials[self.referential][3]) text = QCoreApplication.translate('Account', Account.referentials[self.referential][3])
return text.format(currency) return text.format(currency)
def ref_type(self):
"""
Return type of referential ('q' or 'r', for quantitative or relative)
:return: str
"""
return Account.referentials[self.referential][5]
def set_walletpool_size(self, size, password): def set_walletpool_size(self, size, password):
''' '''
Change the size of the wallet pool Change the size of the wallet pool
......
...@@ -49,7 +49,9 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget): ...@@ -49,7 +49,9 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget):
if block: if block:
ud = self.get_referential_diff_value(block['dividend']) ud = self.get_referential_diff_value(block['dividend'])
if isinstance(ud, int): # if referential type is quantitative...
if self.account.ref_type() == 'q':
# display int values
# use the float type of 64bits, to avoid display a 32bit signed integer... # use the float type of 64bits, to avoid display a 32bit signed integer...
localized_ud = QLocale().toString(float(ud), 'f', 0) localized_ud = QLocale().toString(float(ud), 'f', 0)
localized_mass_per_member = QLocale().toString( localized_mass_per_member = QLocale().toString(
...@@ -58,8 +60,8 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget): ...@@ -58,8 +60,8 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget):
localized_monetary_mass = QLocale().toString( localized_monetary_mass = QLocale().toString(
float(self.get_referential_diff_value(block['monetaryMass'])), 'f', 0 float(self.get_referential_diff_value(block['monetaryMass'])), 'f', 0
) )
else: else:
# display float values
localized_ud = QLocale().toString(ud, 'f', 6) localized_ud = QLocale().toString(ud, 'f', 6)
localized_mass_per_member = QLocale().toString( localized_mass_per_member = QLocale().toString(
self.get_referential_diff_value(block['monetaryMass'] / block['membersCount']), 'f', 6 self.get_referential_diff_value(block['monetaryMass'] / block['membersCount']), 'f', 6
...@@ -106,7 +108,9 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget): ...@@ -106,7 +108,9 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget):
self.label_general.setText(self.tr('No Universal Dividend created yet.')) self.label_general.setText(self.tr('No Universal Dividend created yet.'))
if block: if block:
if isinstance(ud, int): # if referential type is quantitative...
if self.account.ref_type() == 'q':
# display int values
localized_ud_t1 = QLocale().toString( localized_ud_t1 = QLocale().toString(
float( float(
self.get_referential_diff_value( self.get_referential_diff_value(
...@@ -119,6 +123,7 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget): ...@@ -119,6 +123,7 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget):
0 0
) )
else: else:
# display float values
localized_ud_t1 = QLocale().toString( localized_ud_t1 = QLocale().toString(
float( float(
self.get_referential_diff_value( self.get_referential_diff_value(
......
...@@ -94,22 +94,13 @@ class TransactionsTabWidget(QWidget, Ui_transactionsTabWidget): ...@@ -94,22 +94,13 @@ class TransactionsTabWidget(QWidget, Ui_transactionsTabWidget):
proxy = self.table_history.model() proxy = self.table_history.model()
balance = proxy.deposits - proxy.payments balance = proxy.deposits - proxy.payments
if isinstance(proxy.deposits, int):
localized_deposits = QLocale().toString( localized_deposits = QLocale().toString(
self.app.current_account.units_to_ref(proxy.deposits, self.community)) self.app.current_account.units_to_diff_ref(proxy.deposits, self.community))
localized_payments = QLocale().toString( localized_payments = QLocale().toString(
self.app.current_account.units_to_ref(proxy.payments, self.community)) self.app.current_account.units_to_diff_ref(proxy.payments, self.community))
localized_balance = QLocale().toString( localized_balance = QLocale().toString(
self.app.current_account.units_to_diff_ref(balance, self.community)) self.app.current_account.units_to_diff_ref(balance, self.community))
else:
localized_deposits = QLocale().toString(
self.app.current_account.units_to_ref(proxy.deposits, self.community), 'f', 6)
localized_payments = QLocale().toString(
self.app.current_account.units_to_ref(proxy.payments, self.community), 'f', 6)
localized_balance = QLocale().toString(
self.app.current_account.units_to_diff_ref(balance, self.community), 'f', 6)
self.label_deposit.setText(QCoreApplication.translate("TransactionsTabWidget", "<b>Deposits</b> {:} {:}").format( self.label_deposit.setText(QCoreApplication.translate("TransactionsTabWidget", "<b>Deposits</b> {:} {:}").format(
localized_deposits, localized_deposits,
self.app.current_account.ref_name(self.community.short_currency) self.app.current_account.ref_name(self.community.short_currency)
......
...@@ -124,9 +124,12 @@ Please try again later""")) ...@@ -124,9 +124,12 @@ Please try again later"""))
amount = self.wallet.value(self.community) amount = self.wallet.value(self.community)
ref_amount = self.account.units_to_ref(amount, self.community) ref_amount = self.account.units_to_ref(amount, self.community)
ref_name = self.account.ref_name(self.community.currency) ref_name = self.account.ref_name(self.community.currency)
if isinstance(ref_amount, int): # if referential type is quantitative...
ref_amount = QLocale().toString(ref_amount) if self.account.ref_type() == 'q':
# display int values
ref_amount = QLocale().toString(float(ref_amount), 'f', 0)
else: else:
# display float values
ref_amount = QLocale().toString(ref_amount, 'f', 6) ref_amount = QLocale().toString(ref_amount, 'f', 6)
self.label_total.setText("{0} {1}".format(ref_amount, ref_name)) self.label_total.setText("{0} {1}".format(ref_amount, ref_name))
self.spinbox_amount.setSuffix(" " + self.community.currency) self.spinbox_amount.setSuffix(" " + self.community.currency)
...@@ -141,9 +144,12 @@ Please try again later""")) ...@@ -141,9 +144,12 @@ Please try again later"""))
amount = self.wallet.value(self.community) amount = self.wallet.value(self.community)
ref_amount = self.account.units_to_ref(amount, self.community) ref_amount = self.account.units_to_ref(amount, self.community)
ref_name = self.account.ref_name(self.community.currency) ref_name = self.account.ref_name(self.community.currency)
if isinstance(ref_amount, int): # if referential type is quantitative...
ref_amount = QLocale().toString(ref_amount) if self.account.ref_type() == 'q':
# display int values
ref_amount = QLocale().toString(float(ref_amount), 'f', 0)
else: else:
# display float values
ref_amount = QLocale().toString(ref_amount, 'f', 6) ref_amount = QLocale().toString(ref_amount, 'f', 6)
self.label_total.setText("{0} {1}".format(ref_amount, ref_name)) self.label_total.setText("{0} {1}".format(ref_amount, ref_name))
self.spinbox_amount.setValue(0) self.spinbox_amount.setValue(0)
......
...@@ -101,16 +101,17 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): ...@@ -101,16 +101,17 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab):
amount = self.account.amount(self.community) amount = self.account.amount(self.community)
maximum = self.community.monetary_mass maximum = self.community.monetary_mass
# if referential type is quantitative...
if isinstance(self.get_referential_value(amount), int): if self.account.ref_type() == 'q':
# display int values
localized_amount = QLocale().toString(float(self.get_referential_value(amount)), 'f', 0) localized_amount = QLocale().toString(float(self.get_referential_value(amount)), 'f', 0)
else: localized_minimum = QLocale().toString(float(self.get_referential_value(0)), 'f', 0)
localized_amount = QLocale().toString(self.get_referential_value(amount), 'f', 6)
if isinstance(self.get_referential_value(maximum), int):
localized_maximum = QLocale().toString(float(self.get_referential_value(maximum)), 'f', 0) localized_maximum = QLocale().toString(float(self.get_referential_value(maximum)), 'f', 0)
else: else:
localized_maximum = QLocale().toString(self.get_referential_value(maximum), 'f', 6) # display float values
localized_amount = QLocale().toString(float(self.get_referential_value(amount)), 'f', 6)
localized_minimum = QLocale().toString(float(self.get_referential_value(0)), 'f', 6)
localized_maximum = QLocale().toString(float(self.get_referential_value(maximum)), 'f', 6)
# set infos in label # set infos in label
self.label_balance.setText( self.label_balance.setText(
...@@ -123,11 +124,11 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): ...@@ -123,11 +124,11 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab):
self.tr("Your money share "), self.tr("Your money share "),
self.tr("{:.2f}%").format(amount / maximum * 100) if maximum != 0 else "0%", self.tr("{:.2f}%").format(amount / maximum * 100) if maximum != 0 else "0%",
self.tr("Your part "), self.tr("Your part "),
self.tr("{:} {:} in [{:.2f} ; {:}] {:}") self.tr("{:} {:} in [{:} ; {:}] {:}")
.format( .format(
localized_amount, localized_amount,
self.get_referential_name(), self.get_referential_name(),
self.get_referential_value(0), localized_minimum,
localized_maximum, localized_maximum,
self.get_referential_name() self.get_referential_name()
) )
......
...@@ -109,9 +109,12 @@ class TxFilterProxyModel(QSortFilterProxyModel): ...@@ -109,9 +109,12 @@ class TxFilterProxyModel(QSortFilterProxyModel):
if source_data is not "": if source_data is not "":
amount_ref = self.account.units_to_diff_ref(source_data, amount_ref = self.account.units_to_diff_ref(source_data,
self.community) self.community)
if isinstance(amount_ref, int): # if referential type is quantitative...
return QLocale().toString(amount_ref) if self.account.ref_type() == 'q':
# display int values
return QLocale().toString(float(amount_ref), 'f', 0)
else: else:
# display float values
return QLocale().toString(amount_ref, 'f', 6) return QLocale().toString(amount_ref, 'f', 6)
if role == Qt.FontRole: if role == Qt.FontRole:
......
...@@ -39,9 +39,12 @@ class WalletsFilterProxyModel(QSortFilterProxyModel): ...@@ -39,9 +39,12 @@ class WalletsFilterProxyModel(QSortFilterProxyModel):
return source_data return source_data
if source_index.column() == self.sourceModel().columns_types.index('amount'): if source_index.column() == self.sourceModel().columns_types.index('amount'):
amount_ref = self.account.units_to_ref(source_data, self.community) amount_ref = self.account.units_to_ref(source_data, self.community)
if isinstance(amount_ref, int): # if referential type is quantitative...
return QLocale().toString(amount_ref) if self.account.ref_type() == 'q':
# display int values
return QLocale().toString(float(amount_ref), 'f', 0)
else: else:
# display float values
return QLocale().toString(amount_ref, 'f', 6) return QLocale().toString(amount_ref, 'f', 6)
if role == Qt.TextAlignmentRole: if role == Qt.TextAlignmentRole:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment