mirror of
https://github.com/koloideal/DutyLog.git
synced 2026-06-10 10:25:29 +03:00
update
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import asyncio
|
||||
from datetime import date
|
||||
|
||||
from dutylog.infrastructure.database.config import create_engine, create_session_maker
|
||||
from dutylog.infrastructure.database.dao.hours_transactions_dao import HoursTransactionsDAO
|
||||
from dutylog.infrastructure.database.dao.residents_dao import ResidentsDAO
|
||||
from dutylog.infrastructure.database.dao.rooms_dao import RoomsDAO
|
||||
from dutylog.infrastructure.database.dao.floors_dao import FloorsDAO
|
||||
from dutylog.infrastructure.database.dao.reporting_periods_dao import ReportingPeriodsDAO
|
||||
from dutylog.infrastructure.database.dao.users_dao import UsersDAO
|
||||
from dutylog.infrastructure.database.repositories.hours_transactions_repository import (
|
||||
HoursTransactionsRepository,
|
||||
)
|
||||
from dutylog.infrastructure.database.repositories.residents_repository import ResidentsRepository
|
||||
from dutylog.infrastructure.database.repositories.rooms_repository import RoomsRepository
|
||||
from dutylog.infrastructure.database.repositories.floors_repository import FloorsRepository
|
||||
from dutylog.infrastructure.database.repositories.reporting_periods_repository import (
|
||||
ReportingPeriodsRepository,
|
||||
)
|
||||
from dutylog.infrastructure.database.repositories.users_repository import UsersRepository
|
||||
from dutylog.infrastructure.utils.config import load_config
|
||||
from dutylog.services.report_service import ReportService
|
||||
|
||||
|
||||
async def test_report_generation() -> None:
|
||||
config = load_config()
|
||||
engine = create_engine(config.database.url)
|
||||
session_maker = create_session_maker(engine)
|
||||
|
||||
async with session_maker() as session:
|
||||
hours_transactions_dao = HoursTransactionsDAO(session)
|
||||
residents_dao = ResidentsDAO(session)
|
||||
rooms_dao = RoomsDAO(session)
|
||||
floors_dao = FloorsDAO(session)
|
||||
reporting_periods_dao = ReportingPeriodsDAO(session)
|
||||
users_dao = UsersDAO(session)
|
||||
|
||||
hours_transactions_repository = HoursTransactionsRepository(
|
||||
hours_transactions_dao, residents_dao
|
||||
)
|
||||
residents_repository = ResidentsRepository(residents_dao)
|
||||
rooms_repository = RoomsRepository(rooms_dao)
|
||||
floors_repository = FloorsRepository(floors_dao)
|
||||
reporting_periods_repository = ReportingPeriodsRepository(reporting_periods_dao)
|
||||
users_repository = UsersRepository(users_dao)
|
||||
|
||||
report_service = ReportService(
|
||||
hours_transactions_repository,
|
||||
residents_repository,
|
||||
rooms_repository,
|
||||
floors_repository,
|
||||
users_repository,
|
||||
)
|
||||
|
||||
active_period = await reporting_periods_repository.get_active_period()
|
||||
|
||||
if not active_period:
|
||||
print("⚠️ Нет активного периода")
|
||||
return
|
||||
|
||||
print(f"📅 Активный период: с {active_period.start_date}")
|
||||
|
||||
end_date = active_period.end_date if active_period.end_date else date.today()
|
||||
|
||||
print(f"📊 Генерирую отчёт за период {active_period.start_date} - {end_date}")
|
||||
|
||||
report_file = await report_service.generate_period_report(
|
||||
active_period.start_date, end_date
|
||||
)
|
||||
|
||||
filename = f"test_report_{active_period.start_date}_{end_date}.xlsx"
|
||||
with open(filename, "wb") as f:
|
||||
f.write(report_file.read())
|
||||
|
||||
print(f"✅ Отчёт сохранён в файл: {filename}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(test_report_generation())
|
||||
Reference in New Issue
Block a user