feat: services kit and copy

This commit is contained in:
2024-08-06 04:53:50 +03:00
parent 93b0315b4a
commit a7c4fabed0
9 changed files with 442 additions and 28 deletions

34
test.py
View File

@@ -5,6 +5,7 @@ from sqlalchemy import select, func
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import joinedload
import models
from backend.session import session_maker
from models import User, PaymentRecord
@@ -12,31 +13,24 @@ from models import User, PaymentRecord
async def main():
session: AsyncSession = session_maker()
try:
d = datetime.date.today()
d = d.replace(day=1)
print(d)
stmt = (
deal_id = 133
source_product_id = 253
source_services_stmt = (
select(
PaymentRecord
)
.select_from(PaymentRecord)
.options(
joinedload(
PaymentRecord.user
)
models.DealProductService
)
.where(
func.date(func.date_trunc('month', PaymentRecord.start_date)) == d,
func.date(func.date_trunc('month', PaymentRecord.end_date)) == d,
PaymentRecord.start_date == PaymentRecord.end_date,
# PaymentRecord.user_id.in_(request.user_ids)
models.DealProductService.product_id == source_product_id,
models.DealProductService.deal_id == deal_id,
)
)
print(stmt.compile(compile_kwargs={
'literal_binds': True
}))
query_result = (await session.scalars(stmt)).all()
print(query_result)
result = (await session.scalars(source_services_stmt)).all()
services = [d.service for d in result]
for service in services:
print(
service.price_ranges
)
except Exception as e:
print(e)
await session.close()