This commit is contained in:
Андрей Дувакин 2025-01-16 21:21:14 +05:00
parent 68b858be84
commit 9baaba223d
6 changed files with 152 additions and 18 deletions

View File

@ -39,6 +39,8 @@ class User(base):
other_info = Column(Text)
email = Column(VARCHAR(100))
password = Column(VARCHAR(150))
is_dismissed = Column(Boolean, default=False)
dismiss_date = Column(Date)
helper_id = Column(Integer, ForeignKey('users.id'))
director_id = Column(Integer, ForeignKey('users.id'))
@ -48,6 +50,7 @@ class User(base):
post = relationship('Post', back_populates='users')
comments = relationship('Comment', back_populates='user')
users_event = relationship('UserEvent', back_populates='user')
class DepartmentUser(base):
@ -131,6 +134,8 @@ class EventType(base):
id = Column(Integer, primary_key=True, autoincrement=True)
title = Column(VARCHAR(100))
events = relationship('Event', back_populates='type')
class EventStatus(base):
__tablename__ = 'event_statuses'
@ -150,6 +155,9 @@ class Event(base):
type_id = Column(Integer, ForeignKey('event_types.id'))
status_id = Column(Integer, ForeignKey('event_statuses.id'))
type = relationship('EventType', back_populates='events')
users_event = relationship('UserEvent', back_populates='event')
class DepartmentEvent(base):
__tablename__ = 'department_events'
@ -174,6 +182,9 @@ class UserEvent(base):
event_id = Column(Integer, ForeignKey('events.id'))
user_id = Column(Integer, ForeignKey('users.id'))
event = relationship('Event', back_populates='users_event')
user = relationship('User', back_populates='users_event')
class WorkingCalendar(base):
__tablename__ = 'workingcalendar'
@ -188,9 +199,9 @@ class Attendance(base):
id = Column(Integer, primary_key=True, autoincrement=True)
date = Column(Date)
is_attended = Column(Boolean)
reason = Column(Text)
user = Column(Integer, ForeignKey('users.id'))
user_id = Column(Integer, ForeignKey('users.id'))
class VacationTimetable(base):
@ -200,7 +211,7 @@ class VacationTimetable(base):
start_date = Column(Date)
end_date = Column(Date)
user = Column(Integer, ForeignKey('users.id'))
user_id = Column(Integer, ForeignKey('users.id'))
def init_db():

View File

@ -39,6 +39,8 @@ class User(base):
other_info = Column(Text)
email = Column(VARCHAR(100))
password = Column(VARCHAR(150))
is_dismissed = Column(Boolean, default=False)
dismiss_date = Column(Date)
helper_id = Column(Integer, ForeignKey('users.id'))
director_id = Column(Integer, ForeignKey('users.id'))

View File

@ -11,11 +11,19 @@ class EmployeeCardWidget(QWidget):
uic.loadUi('ui/card_widget.ui', self)
self.setStyleSheet('''
QWidget {
background-color: rgb(228, 244, 204);
}
''')
if user.is_dismissed:
self.setStyleSheet('''
QWidget {
background-color: rgba(150, 150, 150, 150);
}
''')
self.pushButton.setEnabled(False)
else:
self.setStyleSheet('''
QWidget {
background-color: rgb(228, 244, 204);
}
''')
with connect() as session:
department = session.query(Department).filter(Department.id == user.department_id).first()

View File

@ -1,13 +1,13 @@
import datetime
from PyQt6 import uic
from PyQt6.QtWidgets import QDialog, QWidget, QHBoxLayout, QLabel, QDateEdit, QMessageBox
from PyQt6.QtWidgets import QDialog, QWidget, QHBoxLayout, QLabel, QDateEdit, QMessageBox, QVBoxLayout, QPushButton
from data.connect import connect, Event, UserEvent, EventType, Attendance, VacationTimetable, WorkingCalendar
from data.connect import connect, Event, UserEvent, EventType, Attendance, VacationTimetable, WorkingCalendar, User
class EventsListDialog(QDialog):
def __init__(self, user):
def __init__(self, user, parent, department):
super().__init__()
uic.loadUi('ui/events_dialog_window.ui', self)
@ -27,6 +27,8 @@ class EventsListDialog(QDialog):
self.future = False
self.user = user
self.parent = parent
self.department = department
self.dateEdit.dateChanged.connect(self.set_minimum_date)
self.dateEdit.setDate(datetime.date.today())
@ -45,9 +47,30 @@ class EventsListDialog(QDialog):
self.pushButton_5.clicked.connect(self.add_new_event)
self.pushButton_6.clicked.connect(self.dismiss_employee)
self.change_future()
self.change_current()
def dismiss_employee(self):
future_curser = list(
filter(
lambda x: x.datetime_event.date() > datetime.date.today(),
self.curses
)
)
if future_curser:
QMessageBox.warning(
self,
'Внимание',
'Увольнение сотрудников с предстоящими обучениями запрещено!'
)
return
self.accept_dissmiss = AcceptDismissEmployee(self.user, self)
self.accept_dissmiss.exec()
def add_new_event(self):
if self.comboBox.currentText() == 'Обучение':
with connect() as session:
@ -353,6 +376,72 @@ class EventsListDialog(QDialog):
self.verticalLayout_3.addWidget(event_widget)
class AcceptDismissEmployee(QDialog):
def __init__(self, user, parent):
super().__init__()
self.setWindowTitle('Увольнение сотрудника')
self.lyt = QVBoxLayout()
self.user = user
self.parent = parent
lbl1 = QLabel(f'Вы уверены, что хотите уволить сотрудника: {user.last_name} {user.first_name}?')
self.lyt.addWidget(lbl1)
h_lyt = QHBoxLayout()
button1 = QPushButton('Уволить')
button1.clicked.connect(self.dismiss_employee)
h_lyt.addWidget(button1)
button2 = QPushButton('Отмена')
h_lyt.addWidget(button2)
button2.clicked.connect(self.close)
self.lyt.addLayout(h_lyt)
self.setLayout(self.lyt)
def dismiss_employee(self):
with connect() as session:
user = session.query(User).filter(User.id == self.user.id).first()
user.is_dismissed = True
user.dismiss_date = datetime.date.today()
session.commit()
QMessageBox.information(
self,
'Внимание',
'Сотрудник был уволен'
)
future_attendances = list(
filter(
lambda x: x.date > datetime.date.today(),
self.parent.attendances
)
)
future_vacations = list(
filter(
lambda x: x.start_date > datetime.date.today(),
self.parent.vacations
)
)
with connect() as session:
for i in future_attendances:
session.delete(i)
for i in future_vacations:
session.delete(i)
self.parent.parent.select_department(self.parent.department.id)
self.parent.close()
self.close()
class EventWidget(QWidget):
def __init__(self, start_date, end_date=None, reason=None):
super().__init__()

View File

@ -1,3 +1,5 @@
import datetime
from PyQt6 import uic
from PyQt6.QtWidgets import QMainWindow
@ -48,15 +50,21 @@ class MainWindow(QMainWindow):
employee = button.employee
edit_widget = EmployeeDialogWidget(self.selected_department, self.department_employees, self,
employee)
self.create_employee_dialog = EventsListDialog(employee)
employee)
self.create_employee_dialog = EventsListDialog(employee, self, self.selected_department)
self.create_employee_dialog.gridLayout_2.addWidget(edit_widget)
self.create_employee_dialog.exec()
def search_employees(self, department_id):
with connect() as session:
employees = session.query(User).filter(User.department_id == department_id).all()
self.department_employees += employees
for employee in employees:
if employee.is_dismissed:
if (datetime.date.today() - employee.dismiss_date).days <= 30:
self.department_employees.append(employee)
else:
self.department_employees.append(employee)
child_departments = session.query(Department).filter(Department.parent_id == department_id).all()

View File

@ -40,7 +40,7 @@ background-color: rgb(228, 244, 204);
<x>0</x>
<y>0</y>
<width>69</width>
<height>606</height>
<height>595</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
@ -121,7 +121,7 @@ background-color: rgb(228, 244, 204);
<x>0</x>
<y>0</y>
<width>897</width>
<height>504</height>
<height>495</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
@ -161,7 +161,7 @@ background-color: rgb(228, 244, 204);
<x>0</x>
<y>0</y>
<width>877</width>
<height>452</height>
<height>443</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
@ -240,7 +240,7 @@ background-color: rgb(228, 244, 204);
<x>0</x>
<y>0</y>
<width>897</width>
<height>94</height>
<height>92</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
@ -345,6 +345,22 @@ background-color: rgb(228, 244, 204);
</property>
</spacer>
</item>
<item row="7" column="0" colspan="3">
<widget class="QPushButton" name="pushButton_6">
<property name="font">
<font>
<pointsize>13</pointsize>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 0, 0);</string>
</property>
<property name="text">
<string>Уволить</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>