Skip to content

Commit 376950d

Browse files
mrsaicharan1iamareebjamal
authored andcommitted
fix: Fix and test cron job for Invoice Due Marking (#6510)
1 parent cbfc81e commit 376950d

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

app/api/helpers/scheduled_jobs.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,12 @@ def expire_pending_tickets():
164164
def event_invoices_mark_due():
165165
from app import current_app as app
166166
with app.app_context():
167-
db.session.query(EventInvoice).\
168-
filter(EventInvoice.status == 'upcoming',
169-
EventInvoice.event.ends_at >= datetime.datetime.now(),
170-
(EventInvoice.created_at + datetime.timedelta(days=30) <=
171-
datetime.datetime.now())).\
172-
update({'status': 'due'})
173-
174-
db.session.commit()
167+
db.session.query(EventInvoice).filter(
168+
EventInvoice.status == 'upcoming',
169+
Event.id == EventInvoice.event_id,
170+
Event.ends_at >= datetime.datetime.now(),
171+
(EventInvoice.created_at + datetime.timedelta(days=30) <= datetime.datetime.now())
172+
).update({EventInvoice.status: 'due'}, synchronize_session=False)
175173

176174

177175
def send_monthly_event_invoice():
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import datetime
2+
3+
from app import current_app as app, db
4+
from app.factories.event_invoice import EventInvoiceFactory
5+
from app.models.event_invoice import EventInvoice
6+
from app.api.helpers.scheduled_jobs import event_invoices_mark_due
7+
8+
from tests.all.integration.utils import OpenEventTestCase
9+
10+
11+
class TestScheduledJobs(OpenEventTestCase):
12+
13+
def test_event_invoices_mark_due(self):
14+
"""Method to test marking of event invoices as due"""
15+
16+
with app.test_request_context():
17+
event_invoice_new = EventInvoiceFactory(event__ends_at=datetime.datetime(2019, 7, 20))
18+
event_invoice_paid = EventInvoiceFactory(status="paid")
19+
20+
db.session.commit()
21+
22+
event_invoice_new_id = event_invoice_new.id
23+
event_invoice_paid_id = event_invoice_paid.id
24+
25+
event_invoices_mark_due()
26+
27+
status_new = EventInvoice.query.get(event_invoice_new_id).status
28+
status_paid = EventInvoice.query.get(event_invoice_paid_id).status
29+
30+
self.assertEqual(status_new, "due")
31+
self.assertNotEqual(status_paid, "due")

0 commit comments

Comments
 (0)