Skip to content

Commit 5f98d9a

Browse files
committed
Fixes #43. The name of the subscription is read from the last entry in the subscription_details table.
1 parent 24eca3e commit 5f98d9a

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

rctab/routers/accounting/send_emails.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from databases import Database
1212
from jinja2 import Environment, PackageLoader, exceptions
1313
from sendgrid import Mail, SendGridAPIClient
14-
from sqlalchemy import asc, func, insert, or_, select
14+
from sqlalchemy import asc, desc, func, insert, or_, select
1515
from sqlalchemy.sql import Select
1616

1717
from rctab.constants import (
@@ -725,9 +725,13 @@ async def get_emails_sent_since(
725725

726726
emails_by_subscription = []
727727
for key, value in groupby(all_emails_sent, extract_sub_id):
728-
name_query = select([subscription_details.c.display_name.label("name")]).where(
729-
subscription_details.c.subscription_id == key
728+
name_query = (
729+
select([subscription_details.c.display_name.label("name")])
730+
.where(subscription_details.c.subscription_id == key)
731+
.order_by(desc(subscription_details.c.time_created))
732+
.limit(1)
730733
)
734+
731735
name_rows = await database.fetch_all(name_query)
732736
if name_rows:
733737
name = name_rows[0]["name"]
@@ -766,9 +770,13 @@ async def get_finance_entries_since(
766770
all_new_entries = [{**row._mapping} for row in rows]
767771
entries_by_subscription = []
768772
for key, value in groupby(all_new_entries, extract_sub_id):
769-
name_query = select([subscription_details.c.display_name.label("name")]).where(
770-
subscription_details.c.subscription_id == key
773+
name_query = (
774+
select([subscription_details.c.display_name.label("name")])
775+
.where(subscription_details.c.subscription_id == key)
776+
.order_by(desc(subscription_details.c.time_created))
777+
.limit(1)
771778
)
779+
772780
name_rows = await database.fetch_all(name_query)
773781
if name_rows:
774782
name = name_rows[0]["name"]

0 commit comments

Comments
 (0)