add cancel schedule
This commit is contained in:
@@ -62,14 +62,14 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
enrollment['course'] = old_course
|
||||
|
||||
created_at: datetime = fromisoformat(enrollment['created_at']) # type: ignore
|
||||
start_date, end_date = get_billing_period(
|
||||
start_period, end_period = get_billing_period(
|
||||
billing_day=new_image['billing_day'],
|
||||
date_=created_at,
|
||||
)
|
||||
pk = 'BILLING#ORG#{org_id}'.format(org_id=org_id)
|
||||
sk = 'START#{start}#END#{end}'.format(
|
||||
start=start_date.isoformat(),
|
||||
end=end_date.isoformat(),
|
||||
start=start_period.isoformat(),
|
||||
end=end_period.isoformat(),
|
||||
)
|
||||
|
||||
logger.info('Enrollment found', data=enrollment)
|
||||
@@ -91,7 +91,8 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
'id': pk,
|
||||
'sk': f'{sk}#SCHEDULE#AUTO_CLOSE',
|
||||
'ttl': ttl(
|
||||
start_dt=datetime.combine(end_date, time()) + timedelta(days=1)
|
||||
start_dt=datetime.combine(end_period, time())
|
||||
+ timedelta(days=1)
|
||||
),
|
||||
'created_at': now_,
|
||||
}
|
||||
|
||||
@@ -32,17 +32,17 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
)
|
||||
|
||||
created_at: datetime = fromisoformat(new_image['created_at']) # type: ignore
|
||||
start_date, end_date = get_billing_period(
|
||||
start_period, end_period = get_billing_period(
|
||||
billing_day=int(subscription['billing_day']),
|
||||
date_=created_at,
|
||||
)
|
||||
pk = 'BILLING#ORG#{org_id}'.format(org_id=subscription['org_id'])
|
||||
sk = 'START#{start}#END#{end}'.format(
|
||||
start=start_date.isoformat(),
|
||||
end=end_date.isoformat(),
|
||||
start=start_period.isoformat(),
|
||||
end=end_period.isoformat(),
|
||||
)
|
||||
|
||||
if now_.date() > end_date:
|
||||
if now_.date() > end_period:
|
||||
logger.debug('Enrollment outside the billing period')
|
||||
return False
|
||||
|
||||
|
||||
@@ -25,13 +25,13 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
now_ = now()
|
||||
# Key pattern `BILLING#ORG#{org_id}`
|
||||
*_, org_id = keys['id'].split('#')
|
||||
# Key pattern `START#{start_date}#END#{end_date}#SCHEDULE#AUTO_CLOSE`
|
||||
_, start_date, _, end_date, *_ = keys['sk'].split('#')
|
||||
# Key pattern `START#{start_period}#END#{end_period}#SCHEDULE#AUTO_CLOSE`
|
||||
_, start_period, _, end_period, *_ = keys['sk'].split('#')
|
||||
|
||||
result = order_layer.collection.query(
|
||||
KeyPair(
|
||||
pk=keys['id'],
|
||||
sk=f'START#{start_date}#END#{end_date}#ENROLLMENT',
|
||||
sk=f'START#{start_period}#END#{end_period}#ENROLLMENT',
|
||||
),
|
||||
limit=150,
|
||||
)
|
||||
@@ -40,8 +40,8 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
{
|
||||
'template_uri': BILLING_TEMPLATE_URI,
|
||||
'args': {
|
||||
'start_date': start_date,
|
||||
'end_date': end_date,
|
||||
'start_date': start_period,
|
||||
'end_date': end_period,
|
||||
'items': result['items'],
|
||||
},
|
||||
},
|
||||
@@ -56,7 +56,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
logger.info('The request timed out')
|
||||
raise
|
||||
|
||||
object_key = f'billing/{org_id}/{start_date}_{end_date}.pdf'
|
||||
object_key = f'billing/{org_id}/{start_period}_{end_period}.pdf'
|
||||
s3_uri = f's3://{BUCKET_NAME}/{object_key}'
|
||||
|
||||
try:
|
||||
@@ -74,7 +74,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
transact.update(
|
||||
key=KeyPair(
|
||||
pk=keys['id'],
|
||||
sk=f'START#{start_date}#END#{end_date}',
|
||||
sk=f'START#{start_period}#END#{end_period}',
|
||||
),
|
||||
update_expr='SET #status = :status, s3_uri = :s3_uri, \
|
||||
updated_at = :updated_at',
|
||||
|
||||
@@ -12,7 +12,7 @@ from boto3clients import dynamodb_client, s3_client, sesv2_client
|
||||
from config import EMAIL_SENDER, USER_TABLE
|
||||
|
||||
SUBJECT = (
|
||||
'Relatório de matrículas realizadas entre {start_date} e {end_date} na EDUSEG®'
|
||||
'Relatório de matrículas realizadas entre {start_period} e {end_period} na EDUSEG®'
|
||||
)
|
||||
REPLY_TO = ('Carolina Brand', 'carolina@somosbeta.com.br')
|
||||
BCC = [
|
||||
@@ -24,7 +24,7 @@ MESSAGE = """
|
||||
Oi, tudo bem?<br/><br/>
|
||||
|
||||
Em anexo você encontra o relatório das matrículas realizadas no período de
|
||||
<strong>{start_date}</strong> a <strong>{end_date}</strong>.<br/><br/>
|
||||
<strong>{start_period}</strong> a <strong>{end_period}</strong>.<br/><br/>
|
||||
|
||||
<a href="https://admin.saladeaula.digital/{org_id}/billing?start={start_query}&end={end_query}">
|
||||
📈 Clique aqui para ver mais detalhes do relatório
|
||||
@@ -43,8 +43,8 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
new_image = event.detail['new_image']
|
||||
# Key pattern `BILLING#ORG#{org_id}`
|
||||
*_, org_id = new_image['id'].split('#')
|
||||
# Key pattern `START#{start_date}#END#{end_date}
|
||||
_, start_date, _, end_date, *_ = new_image['sk'].split('#')
|
||||
# Key pattern `START#{start_period}#END#{v}
|
||||
_, start_period, _, end_period, *_ = new_image['sk'].split('#')
|
||||
|
||||
emailmsg = Message(
|
||||
from_=EMAIL_SENDER,
|
||||
@@ -52,24 +52,24 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
reply_to=REPLY_TO,
|
||||
bcc=BCC,
|
||||
subject=SUBJECT.format(
|
||||
start_date=_locale_dateformat(start_date),
|
||||
end_date=_locale_dateformat(end_date),
|
||||
start_period=_locale_dateformat(start_period),
|
||||
end_period=_locale_dateformat(end_period),
|
||||
),
|
||||
)
|
||||
emailmsg.add_alternative(
|
||||
MESSAGE.format(
|
||||
org_id=org_id,
|
||||
start_date=_locale_dateformat(start_date),
|
||||
end_date=_locale_dateformat(end_date),
|
||||
start_query=start_date,
|
||||
end_query=start_date,
|
||||
start_period=_locale_dateformat(start_period),
|
||||
end_period=_locale_dateformat(end_period),
|
||||
start_query=start_period,
|
||||
end_query=end_period,
|
||||
)
|
||||
)
|
||||
attachment = MIMEApplication(_get_file_bytes(new_image['s3_uri']))
|
||||
attachment.add_header(
|
||||
'Content-Disposition',
|
||||
'attachment',
|
||||
filename=f'{start_date}_{end_date}.pdf',
|
||||
filename=f'{start_period}_{end_period}.pdf',
|
||||
)
|
||||
emailmsg.attach(attachment)
|
||||
|
||||
|
||||
@@ -30,14 +30,14 @@ def test_cancel_enrollment(
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
now_ = now()
|
||||
start_date, end_date = get_billing_period(
|
||||
start_period, end_period = get_billing_period(
|
||||
billing_day=6,
|
||||
date_=now_,
|
||||
)
|
||||
pk = 'BILLING#ORG#cJtK9SsnJhKPyxESe7g3DG'
|
||||
sk = 'START#{start}#END#{end}#ENROLLMENT#{enrollment_id}'.format(
|
||||
start=start_date.isoformat(),
|
||||
end=end_date.isoformat(),
|
||||
start=start_period.isoformat(),
|
||||
end=end_period.isoformat(),
|
||||
enrollment_id=enrollment_id,
|
||||
)
|
||||
# Add up-to-date enrollment item to billing
|
||||
|
||||
Reference in New Issue
Block a user