Skip to content

Commit

Permalink
feat: add new accounts detected in OFX file
Browse files Browse the repository at this point in the history
* TODO: fix label height according to content in dialog
  • Loading branch information
opierre committed Oct 22, 2023
1 parent 0746ed6 commit 81c7c8f
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 57 deletions.
6 changes: 3 additions & 3 deletions budgetter/services/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Dashboard(QObject):
transactionEdited = Signal(object)
transactionsFound = Signal(object)
expensesDistribution = Signal(object)
convertOFXCompleted = Signal(dict, dict, str)
convertOFXCompleted = Signal(dict, str)

def get_banks_worker(self):
"""
Expand Down Expand Up @@ -226,9 +226,9 @@ def push_ofx_transactions(self, result: Tuple[dict, dict, str]):
:return: None
"""

ofx_data, header, message = result
_, header, message = result

self.convertOFXCompleted.emit(ofx_data, header, message)
self.convertOFXCompleted.emit(header, message)

# TODO: URL for posting JSON transactions
# # Create worker
Expand Down
5 changes: 2 additions & 3 deletions budgetter/view/panels/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,13 @@ def handle_get_accounts(self, accounts_list: list):
self._accounts.set_accounts(accounts_list)
self._transactions.set_accounts(accounts_list)

def handle_convert_ofx(self, ofx_data: dict, header: dict, message: str):
def handle_convert_ofx(self, header: dict, message: str):
"""
Handle OFX data converted to dict
:param ofx_data: OFX data
:param header: data header
:param message: error message
:return: None
"""

self._transactions.handle_convert_ofx(ofx_data, header, message)
self._transactions.handle_convert_ofx(header, message)
27 changes: 17 additions & 10 deletions budgetter/view/panels/home_panel/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ def __init__(self, gui, parent):
self.dialogs = []

# All button - Type
self.all = QPushButton(QCoreApplication.translate("transactions", "All"))
self.all = QPushButton(QCoreApplication.translate("transactions", "All", None))

# Expenses button - Type
self.expenses = QPushButton(QCoreApplication.translate("transactions", "Expenses"))
self.expenses = QPushButton(QCoreApplication.translate("transactions", "Expenses", None))

# Incomes button - Type
self.income = QPushButton(QCoreApplication.translate("transactions", "Income"))
self.income = QPushButton(QCoreApplication.translate("transactions", "Income", None))

# Transfers button - Type
self.transfer = QPushButton(QCoreApplication.translate("transactions", "Transfer"))
self.transfer = QPushButton(QCoreApplication.translate("transactions", "Transfer", None))

# All button - Account
self.all_account = QPushButton(QCoreApplication.translate("transactions", "All"))
self.all_account = QPushButton(QCoreApplication.translate("transactions", "All", None))
self.accounts = []

# Store item delegate
Expand Down Expand Up @@ -433,7 +433,7 @@ def import_transaction(self):

# Set focus on first widget when opening
dialog_content.content.import_path.setFocus()
QTimer.singleShot(200, dialog_content.load_ofx)
QTimer.singleShot(500, dialog_content.load_ofx)

def escape_dialog(self):
"""
Expand Down Expand Up @@ -666,21 +666,28 @@ def add_filter(self):
account.style().unpolish(account)
account.style().polish(account)

def handle_convert_ofx(self, ofx_data: dict, header: dict, message: str):
def handle_convert_ofx(self, header: dict, message: str):
"""
Handle OFX data converted to dict
:param ofx_data: OFX data
:param header: data header
:param message: error message
:return: None
:return: None
"""

# TODO: update open dialog with import date and account concerned
# self._transactions.handle_convert_ofx(ofx_data)
if message != "":
self.dialogs[-1].central_widget().set_error(message)

# Update info on dialog
new_accounts = []
for account in header.get("accounts", []):
if account.get("account_id", "") not in self.account_identifiers:
new_accounts.append(account.get("account_id", ""))

self.dialogs[-1].central_widget().set_header_info(
header.get("count", -1),
header.get("start_date", "xx/xx/xxxx").strftime("%d/%m/%Y"),
header.get("end_date", "xx/xx/xxxx").strftime("%d/%m/%Y"),
new_accounts,
)
29 changes: 13 additions & 16 deletions budgetter/view/skeletons/ImportTransactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Ui_ImportTransactions(object):
def setupUi(self, ImportTransactions):
if not ImportTransactions.objectName():
ImportTransactions.setObjectName("ImportTransactions")
ImportTransactions.resize(476, 179)
ImportTransactions.resize(435, 163)
ImportTransactions.setStyleSheet("QWidget#transaction \n"
"{\n"
" background-color: #1C293B;\n"
Expand Down Expand Up @@ -181,26 +181,13 @@ def setupUi(self, ImportTransactions):
"\n"
"QProgressBar\n"
"{\n"
" background-color: #1c293b;\n"
" border: none;\n"
" border-radius: 2px;\n"
"}\n"
"\n"
"QProgressBar[activated=\"true\"] \n"
"{\n"
" background-color: #212f41;\n"
" border: none;\n"
" border-radius: 2px;\n"
"}\n"
"\n"
"QProgressBar::chunk \n"
"{\n"
" background-color: #1c293b;\n"
" border-radius: 2px;\n"
"}\n"
"\n"
"QProgressBar[activated=\"true\"]::chunk \n"
"{\n"
" background-color: #199ce5;\n"
" border-radius: 2px;\n"
"}")
Expand Down Expand Up @@ -230,8 +217,8 @@ def setupUi(self, ImportTransactions):
self.horizontalLayout.setContentsMargins(-1, -1, -1, 0)
self.import_path = MaterialOutlinedLineEdit(self.transaction)
self.import_path.setObjectName("import_path")
self.import_path.setMinimumSize(QSize(320, 50))
self.import_path.setMaximumSize(QSize(16777215, 50))
self.import_path.setMinimumSize(QSize(400, 50))
self.import_path.setMaximumSize(QSize(400, 50))
self.import_path.setReadOnly(True)

self.horizontalLayout.addWidget(self.import_path)
Expand All @@ -245,13 +232,23 @@ def setupUi(self, ImportTransactions):
self.verticalLayout_2.setContentsMargins(0, -1, 0, -1)
self.header_info = QLabel(self.transaction)
self.header_info.setObjectName("header_info")
sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.header_info.sizePolicy().hasHeightForWidth())
self.header_info.setSizePolicy(sizePolicy)
self.header_info.setMinimumSize(QSize(400, 0))
self.header_info.setMaximumSize(QSize(400, 16777215))
font1 = QFont()
font1.setFamilies([u"Roboto"])
font1.setPointSize(10)
font1.setItalic(True)
self.header_info.setFont(font1)
self.header_info.setStyleSheet("color: rgba(255, 255, 255, 100);\n"
"font-style: italic;")
self.header_info.setTextFormat(Qt.AutoText)
self.header_info.setScaledContents(False)
self.header_info.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop)
self.header_info.setWordWrap(True)

self.verticalLayout_2.addWidget(self.header_info)
Expand Down
48 changes: 31 additions & 17 deletions budgetter/view/skeletons/ImportTransactions.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>476</width>
<height>179</height>
<width>435</width>
<height>163</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -166,26 +166,13 @@ QRadioButton
}

QProgressBar
{
background-color: #1c293b;
border: none;
border-radius: 2px;
}

QProgressBar[activated=&quot;true&quot;]
{
background-color: #212f41;
border: none;
border-radius: 2px;
}

QProgressBar::chunk
{
background-color: #1c293b;
border-radius: 2px;
}

QProgressBar[activated=&quot;true&quot;]::chunk
{
background-color: #199ce5;
border-radius: 2px;
Expand Down Expand Up @@ -247,13 +234,13 @@ QProgressBar[activated=&quot;true&quot;]::chunk
<widget class="MaterialOutlinedLineEdit" name="import_path">
<property name="minimumSize">
<size>
<width>320</width>
<width>400</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<width>400</width>
<height>50</height>
</size>
</property>
Expand All @@ -280,6 +267,24 @@ QProgressBar[activated=&quot;true&quot;]::chunk
</property>
<item>
<widget class="QLabel" name="header_info">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>400</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<family>Roboto</family>
Expand All @@ -294,6 +299,15 @@ font-style: italic;</string>
<property name="text">
<string>Importing nb transactions from start date to end end date on accounts A and B</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
Expand Down
48 changes: 40 additions & 8 deletions budgetter/view/widgets/dialog_widgets/import_transactions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import List

from PySide6.QtCore import Signal
from PySide6.QtGui import QIcon
Expand Down Expand Up @@ -43,8 +44,8 @@ def configure(self):
browse_action.triggered.connect(self.load_ofx)

# Hide header info first and progress bar
self.content.header_info.setVisible(False)
self.content.import_transactions_progress.setVisible(False)
# self.content.header_info.setVisible(False)
# self.content.import_transactions_progress.setVisible(False)

def load_ofx(self):
"""
Expand All @@ -65,25 +66,56 @@ def load_ofx(self):
self.content.import_path.setText(file_name)
self.importTransactions.emit(file_name)

def set_header_info(self, nb_transactions: int, start_date: str, end_date: str):
def set_header_info(self, nb_transactions: int, start_date: str, end_date: str, new_accounts: List[str]):
"""
Update header info
:param nb_transactions: number of transactions imported
:param start_date: start date
:param end_date: end date
:param new_accounts: new accounts detected to create
:return: None
"""

# Show both widgets for info
self.content.header_info.setVisible(True)
self.content.import_transactions_progress.setVisible(True)

# Set content
if new_accounts:
accounts_list = "\n".join(new_accounts)
end_message = f"{len(new_accounts)} new accounts detected: \n{accounts_list}"
nb_lines = len(accounts_list) + 1
else:
end_message = ""
nb_lines = 0
message = f"Importing {nb_transactions} transactions from {start_date} to {end_date}...\n{end_message}"
self.content.header_info.setText(message)
print(message)
height_font = self.content.header_info.fontMetrics().height()
print(height_font)
print(2 + nb_lines)
self.content.header_info.setFixedHeight((2 + nb_lines) * height_font)
self.content.header_info.update()
self.content.import_transactions_progress.setRange(0, 0)

# Emit signal to resize dialog parent
# self.computeResize.emit()

def set_error(self, error: str):
"""
Update header info with error message
:param error: error content
:return: None
"""

# Show both widgets for info
self.content.header_info.setVisible(True)
self.content.import_transactions_progress.setVisible(False)

# Emit signal to resize dialog parent
self.computeResize.emit()

self.content.header_info.setText(f"Importing {nb_transactions} transactions from {start_date} to {end_date}...")
self.content.import_transactions_progress.setRange(0, 0)
self.content.import_transactions_progress.setProperty("activated", "true")
self.content.import_transactions_progress.style().unpolish(self.content.import_transactions_progress)
self.content.import_transactions_progress.style().polish(self.content.import_transactions_progress)
# Set content
self.content.header_info.setText(f"Importing transactions from current file failed: {error}")

0 comments on commit 81c7c8f

Please sign in to comment.