From e7c9406aa33ec1ab7e28cb33b1d6fb20a74137b0158c660d27a594d93c8a6a1e Mon Sep 17 00:00:00 2001 From: linuxero Date: Wed, 11 Dec 2024 23:33:59 +0100 Subject: [PATCH] Filtered customer view - clientele, provider, interested...etc --- Gui/CustomerTable.qml | 22 ++++++++++++++++------ lib/DB/BusinessDAO.py | 4 ++-- lib/DB/BusinessModel.py | 11 +++++++++-- lib/PyqcrmDataRoles.py | 3 ++- lib/PyqcrmFlags.py | 2 ++ main.py | 1 + 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Gui/CustomerTable.qml b/Gui/CustomerTable.qml index e11ea36..4c366cb 100644 --- a/Gui/CustomerTable.qml +++ b/Gui/CustomerTable.qml @@ -41,29 +41,34 @@ Item { { RadioButton { - + id: showAll checked: true text: qsTr("Alle") + onClicked: viewCriterion(showAll) } RadioButton { - - text: qsTr("Interessent") + id: showInterested + text: qsTr("Interessent") + onClicked: viewCriterion(showInterested) } RadioButton { - + id: showClientele text: qsTr("Kunden") + onClicked: viewCriterion(showClientele) } RadioButton { - + id: showProvider text: qsTr("Lieferant") + onClicked: viewCriterion(showProvider) } RadioButton { - + id: showFinished text: qsTr("Erledigt") + onClicked: viewCriterion(showFinished) } } @@ -196,6 +201,11 @@ Item { Layout.fillWidth: true } } + + function viewCriterion(criterion) + { + business_model.viewCriterion(criterion.text) + } } diff --git a/lib/DB/BusinessDAO.py b/lib/DB/BusinessDAO.py index 4a6e144..2680fdb 100644 --- a/lib/DB/BusinessDAO.py +++ b/lib/DB/BusinessDAO.py @@ -8,8 +8,8 @@ class BusinessDAO: self.__con = DbManager().getConnection() self.__cur = self.__con.cursor() - def getBusiness(self): - self.__cur.callproc("getCustomerView") + def getBusiness(self, criterion = "Alle"): + self.__cur.callproc("getCustomerView", (criterion,)) self.__all_cols = [desc[0] for desc in self.__cur.description] return self.__cur.fetchall(), self.__all_cols diff --git a/lib/DB/BusinessModel.py b/lib/DB/BusinessModel.py index c9d2ee6..e76b68a 100644 --- a/lib/DB/BusinessModel.py +++ b/lib/DB/BusinessModel.py @@ -1,6 +1,7 @@ # This Python file uses the following encoding: utf-8 from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, Signal from .BusinessDAO import BusinessDAO +from ..PyqcrmFlags import PyqcrmFlags # USERS TABLE # CUSTOMER_COLUMN_NAMES = \ @@ -67,8 +68,8 @@ class BusinessModel(QAbstractTableModel): super().__init__() self.__data = self.__getData() - def __getData(self): - rows, self.__visible_columns = BusinessDAO().getBusiness() + def __getData(self, criterion = "Alle"): + rows, self.__visible_columns = BusinessDAO().getBusiness(criterion) return rows def rowCount(self, parent= QModelIndex()): @@ -106,6 +107,12 @@ class BusinessModel(QAbstractTableModel): def onRowClicked(self, row): print(row) + @Slot(str) + def viewCriterion(self, criterion): + self.beginResetModel() + self.__data = self.__getData(criterion) + self.endResetModel() + @Slot(dict, int) def addBusiness(self, business, contact_id): BusinessDAO().addBusiness(business, contact_id) diff --git a/lib/PyqcrmDataRoles.py b/lib/PyqcrmDataRoles.py index a1d63c3..ebf00c5 100644 --- a/lib/PyqcrmDataRoles.py +++ b/lib/PyqcrmDataRoles.py @@ -4,5 +4,6 @@ from PySide6.QtCore import Qt from enum import IntEnum class PyqcrmDataRoles(IntEnum): - CITY_ROLE = Qt.UserRole + 1 + CITY_ROLE = Qt.UserRole + 100 + diff --git a/lib/PyqcrmFlags.py b/lib/PyqcrmFlags.py index de8e99a..1c5ac80 100644 --- a/lib/PyqcrmFlags.py +++ b/lib/PyqcrmFlags.py @@ -4,3 +4,5 @@ from enum import IntFlag class PyqcrmFlags(IntFlag): ADMIN = 1 USER = 2 + + diff --git a/main.py b/main.py index 42424f0..a93d54b 100644 --- a/main.py +++ b/main.py @@ -58,6 +58,7 @@ def publishContext(): engine.rootContext().setContextProperty("business_type", business_type) engine.rootContext().setContextProperty("contact_model", contact_model) + if __name__ == "__main__": #QResource.registerResource("rc_qml.py") app = QGuiApplication(sys.argv)