From cf5822c95062792a98f2fc036dc1b81f553eee0bb1bbd0f50d0a544a2ef8ac36 Mon Sep 17 00:00:00 2001 From: Yuri Becker Date: Wed, 16 Apr 2025 11:00:06 +0200 Subject: [PATCH] Somewhat fix errors when adding an applicant --- Gui/Employees/AddEmployee.qml | 26 +++++++------------ Gui/Employees/ApplicantForm.qml | 11 ++++++++ Gui/Employees/ApplicantPersonalData.qml | 34 +++++-------------------- lib/DB/EmployeeDAO.py | 27 ++++++++------------ lib/DB/EmployeeModel.py | 2 +- 5 files changed, 38 insertions(+), 62 deletions(-) diff --git a/Gui/Employees/AddEmployee.qml b/Gui/Employees/AddEmployee.qml index 9ce7e0e..f05c3b7 100644 --- a/Gui/Employees/AddEmployee.qml +++ b/Gui/Employees/AddEmployee.qml @@ -13,11 +13,12 @@ ColumnLayout { saveBtn.enabled = true; } function onAddNewEmployee(added) { - if (added) + if (added) { console.log('addedsuccesfully'); - else + contentStack.pop(); + } else { console.log('failedtoadd'); - contentStack.pop(); + } } Layout.fillHeight: true @@ -36,33 +37,25 @@ ColumnLayout { font.pixelSize: 35 text: qsTr("Mitarbeiter / Bewerber hinzufügen") } - ButtonGroup { - buttons: radio.children - - onClicked: { - checkFields(); - personalData.requiredField(); - } - } RowLayout { Layout.fillWidth: true - spacing: 50 + spacing: Dimensions.l Frame { Layout.alignment: Qt.AlignTop Layout.fillWidth: true + Layout.horizontalStretchFactor: 1 - //implicitWidth: parent.width ApplicantPersonalData { id: personalData - width: parent.width + implicitWidth: parent.width } } Frame { Layout.alignment: Qt.AlignTop Layout.fillWidth: true - visible: radio.children[1].checked + Layout.horizontalStretchFactor: 1 ColumnLayout { Layout.alignment: Qt.AlignTop @@ -74,7 +67,6 @@ ColumnLayout { } ApplicantNationalInsurance { id: nationalInsurance - } ApplicantVarious { id: applicantVarious @@ -103,7 +95,7 @@ ColumnLayout { onClicked: { const new_applicant = JsLib.parseForm(personalData, bankAccount, nationalInsurance, applicantVarious); - employee_model.addEmployee(new_applicant, false); + employee_model.addEmployee(new_applicant); } } } diff --git a/Gui/Employees/ApplicantForm.qml b/Gui/Employees/ApplicantForm.qml index 5a6f0f9..257dead 100644 --- a/Gui/Employees/ApplicantForm.qml +++ b/Gui/Employees/ApplicantForm.qml @@ -95,24 +95,33 @@ ColumnLayout { id: street label: qsTr("Straße") + mandatory: true TextField { implicitWidth: fieldM placeholderText: qsTr("Musterstraße") + + validator: NotEmptyValidator { + } } } Field { id: houseno + mandatory: true label: qsTr("Hausnummer") TextField { implicitWidth: fieldS placeholderText: qsTr("1a") + + validator: NotEmptyValidator { + } } } Field { label: qsTr("PLZ") + mandatory: true ComboBox { id: postcode @@ -125,6 +134,8 @@ ColumnLayout { onActivated: currentValue onCurrentIndexChanged: city.currentIndex = postcode.currentIndex + + validator: NotEmptyValidator {} } } Field { diff --git a/Gui/Employees/ApplicantPersonalData.qml b/Gui/Employees/ApplicantPersonalData.qml index 51728dc..298a73e 100644 --- a/Gui/Employees/ApplicantPersonalData.qml +++ b/Gui/Employees/ApplicantPersonalData.qml @@ -7,14 +7,10 @@ GridLayout { id: personalData function checkPersonalField() { - if (radio.children[0].checked) { - return (firstname.text.trim() && lastname.text.trim()); - } else { - return (firstname.text.trim() && lastname.text.trim() && street.text.trim() && houseno.text.trim() && (postcode.editText.trim() || postcode.currentText.trim()) && (city.editText.trim() || city.currentText.trim()) && birthday.text.trim() && phonenumber.text.trim() && cellphone.text.trim() && email.text.trim() && jobdescription.text.trim() && contractstart.text.trim() && contractend.text.trim() && briefAnrede.text.trim()); - } + return (firstname.text.trim() && lastname.text.trim() && street.text.trim() && houseno.text.trim() && (postcode.editText.trim() || postcode.currentText.trim()) && (city.editText.trim() || city.currentText.trim()) && birthday.text.trim() && phonenumber.text.trim() && cellphone.text.trim() && email.text.trim() && jobdescription.text.trim() && contractstart.text.trim() && contractend.text.trim() && briefAnrede.text.trim()); } function requiredField() { - var pf = (radio.children[1].checked) ? "Pflichtfeld" : ""; + const pf = "Pflichtfeld"; street.placeholderText = pf; phonenumber.placeholderText = pf; cellphone.placeholderText = pf; @@ -131,7 +127,8 @@ GridLayout { popup.height: 300 textRole: "display" - validator: PostcodeValidator {} + validator: PostcodeValidator { + } onActivated: currentValue onCurrentIndexChanged: city.currentIndex = postcode.currentIndex @@ -160,7 +157,6 @@ GridLayout { Label { Layout.alignment: Qt.AlignRight text: qsTr("Geburtsname") - visible: radio.children[1].checked } TextField { id: birthname @@ -169,14 +165,12 @@ GridLayout { Layout.columnSpan: 3 Layout.fillWidth: true - visible: radio.children[1].checked onTextChanged: checkFields() } Label { Layout.alignment: Qt.AlignRight text: qsTr("Geburtsdatum*") - visible: radio.children[1].checked } TextField { id: birthday @@ -185,7 +179,6 @@ GridLayout { Layout.columnSpan: 3 Layout.fillWidth: true - visible: radio.children[1].checked validator: RegularExpressionValidator { regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/ @@ -204,7 +197,6 @@ GridLayout { Label { Layout.alignment: Qt.AlignRight text: qsTr("Geburtsort*") - visible: radio.children[1].checked } TextField { id: placeofbirth @@ -213,7 +205,6 @@ GridLayout { Layout.columnSpan: 3 Layout.fillWidth: true - visible: radio.children[1].checked onTextChanged: checkFields() } @@ -269,14 +260,14 @@ GridLayout { placeholderText: qsTr("beispiel@domain.de") placeholderTextColor: "red" - validator: EmailAddressValidator {} + validator: EmailAddressValidator { + } onTextChanged: checkFields() } Label { Layout.alignment: Qt.AlignRight text: qsTr("Familienstand") - visible: radio.children[1].checked } ComboBox { id: maritalstatus @@ -287,12 +278,10 @@ GridLayout { Layout.fillWidth: true editable: false model: [qsTr("ledig"), qsTr("verheiratet"), qsTr("verwitwet"), qsTr("geschieden")] - visible: radio.children[1].checked } Label { Layout.alignment: Qt.AlignRight text: qsTr("Stundenlohn") - visible: radio.children[1].checked } TextField { id: salary @@ -302,14 +291,12 @@ GridLayout { Layout.columnSpan: 3 Layout.fillWidth: true placeholderTextColor: "red" - visible: radio.children[1].checked onTextChanged: checkFields() } Label { Layout.alignment: Qt.AlignRight text: qsTr("Jobbeschreibung") - visible: radio.children[1].checked } TextField { id: jobdescription @@ -319,14 +306,12 @@ GridLayout { Layout.columnSpan: 3 Layout.fillWidth: true placeholderTextColor: "red" - visible: radio.children[1].checked onTextChanged: checkFields() } Label { Layout.alignment: Qt.AlignRight text: qsTr("Vertragsbeginn") - visible: radio.children[1].checked } TextField { id: contractstart @@ -336,7 +321,6 @@ GridLayout { Layout.columnSpan: 3 Layout.fillWidth: true placeholderTextColor: "red" - visible: radio.children[1].checked validator: RegularExpressionValidator { regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/ @@ -355,7 +339,6 @@ GridLayout { Label { Layout.alignment: Qt.AlignRight text: qsTr("Vertragsende") - visible: radio.children[1].checked } TextField { id: contractend @@ -365,7 +348,6 @@ GridLayout { Layout.columnSpan: 3 Layout.fillWidth: true placeholderTextColor: "red" - visible: radio.children[1].checked validator: RegularExpressionValidator { regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/ @@ -384,7 +366,6 @@ GridLayout { Label { Layout.alignment: Qt.AlignRight text: qsTr("Arbeitszeiten Tage") - visible: radio.children[1].checked } ComboBox { id: workdays @@ -393,12 +374,10 @@ GridLayout { Layout.fillWidth: true model: ["1", "2", "3", "4", "5", "6", "7"] - visible: radio.children[1].checked } Label { Layout.alignment: Qt.AlignRight text: qsTr("Stunden") - visible: radio.children[1].checked } ComboBox { id: workhours @@ -407,7 +386,6 @@ GridLayout { Layout.fillWidth: true model: ["1", "2", "3", "4", "5", "6", "7", "8"] - visible: radio.children[1].checked } Label { Layout.alignment: Qt.AlignRight diff --git a/lib/DB/EmployeeDAO.py b/lib/DB/EmployeeDAO.py index b3ad69f..42ecac0 100644 --- a/lib/DB/EmployeeDAO.py +++ b/lib/DB/EmployeeDAO.py @@ -16,35 +16,30 @@ class EmployeeDAO(QObject): if self.__con: self.__cur = self.__con.cursor() - def getEmployees(self, enc_key, criterion = "Alle", processed = False, fired = False, every_state = True): + def getEmployees(self, enc_key, criterion="Alle", processed=False, fired=False, every_state=True): try: if self.__cur: - self.__cur.callproc("getEmployeeTable", (criterion, processed, fired, every_state, enc_key, )) + self.__cur.callproc("getEmployeeTable", (criterion, processed, fired, every_state, enc_key,)) self.__all_cols = [desc[0] for desc in self.__cur.description] - return self.__cur.fetchall(), self.__all_cols + return self.__cur.fetchall(), self.__all_cols else: return None, None except mariadb.Error as e: print(str(e)) - def getEmployee(self, employee_id, enc_key = None): + def getEmployee(self, employee_id, enc_key=None): try: if self.__cur: self.__cur.callproc("getEmployee", (employee_id, enc_key,)) - #self.__all_cols = [desc[0] for desc in self.__cur.description] - return self.__cur.fetchall() #, self.__all_cols + # self.__all_cols = [desc[0] for desc in self.__cur.description] + return self.__cur.fetchall() # , self.__all_cols else: return None except mariadb.Error as e: print(str(e)) - def addEmployee(self, data, enc_key, applicant = True): - try: - if self.__cur: - self.__cur.callproc("addApplicant", (json.dumps(data), applicant, enc_key,)) - self.__con.commit() - self.newEmployeeAdded.emit(True) - - except mariadb.Error as e: - print(str(e)) - self.newEmployeeAdded.emit(False) + def addEmployee(self, data, enc_key, applicant=True): + if self.__cur: + self.__cur.callproc("addApplicant", (json.dumps(data), applicant, enc_key,)) + self.__con.commit() + self.newEmployeeAdded.emit(True) diff --git a/lib/DB/EmployeeModel.py b/lib/DB/EmployeeModel.py index e5357aa..0a38809 100644 --- a/lib/DB/EmployeeModel.py +++ b/lib/DB/EmployeeModel.py @@ -27,7 +27,7 @@ class EmployeeModel(QAbstractTableModel): self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY'] self.__getData() - @Slot(dict, bool) + @Slot(dict) def addEmployee(self, new_employee): if 'worklicense' in new_employee: new_employee['worklicense'] = int(new_employee['worklicense'])