From 99a008e9082ea00a9a1784b7049d32dcbe20a80f Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Thu, 29 Aug 2019 11:30:40 +0100 Subject: [PATCH] explicitly join annual_billing and remove reference to service.id service.id isn't used in this query (both tables already have service_id), and explicitly joining makes what we're doing more obvious --- app/dao/fact_billing_dao.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/dao/fact_billing_dao.py b/app/dao/fact_billing_dao.py index 67a79261e..f02ffc7c3 100644 --- a/app/dao/fact_billing_dao.py +++ b/app/dao/fact_billing_dao.py @@ -42,9 +42,9 @@ def fetch_sms_free_allowance_remainder(start_date): func.greatest((AnnualBilling.free_sms_fragment_limit - func.sum(FactBilling.billable_units * FactBilling.rate_multiplier) ).cast(Integer), 0).label('sms_remainder') + ).join( + AnnualBilling, FactBilling.service_id == AnnualBilling.service_id, ).filter( - FactBilling.service_id == Service.id, - FactBilling.service_id == AnnualBilling.service_id, FactBilling.bst_date >= start_of_year, FactBilling.bst_date < start_date, FactBilling.notification_type == SMS_TYPE,