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
This commit is contained in:
Leo Hemsted
2019-08-29 11:30:40 +01:00
parent 741d75c3a9
commit 99a008e908

View File

@@ -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,