@@ -0,0 +1,1071 @@
+from django.db.models import Q%0Afrom corehq.apps.smsbillables.models import SmsBillable%0Afrom django.core.management.base import LabelCommand%0Afrom corehq.apps.sms.models import SMSLog%0A%0A%0Aclass Command(LabelCommand):%0A    help = (%22Make sure domain is filled in for SMSBillable where domain is %22%0A            %22None. This retro-fixes an issue where domains weren't stored %22%0A            %22in the billable during its creation. September 2014.%22)%0A    args = %22%22%0A    label = %22%22%0A%0A    def handle(self, *args, **options):%0A        missing_domain_billables = SmsBillable.objects.filter(%0A            Q(domain=u'') %7C Q(domain=None)%0A        )%0A        for billable in missing_domain_billables:%0A            msg_log = SMSLog.get(billable.log_id)%0A            billable.domain = msg_log.domain%0A            if billable.domain:%0A                billable.save()%0A                print %22Updated Billable from %25s for domain %25s%22 %25 (%0A                    billable.date_created, billable.domain%0A                )%0A            else:%0A                print %22could not find a domain in SMSLog %25s.%22 %25 billable.log_id%0A

fix old SMSBillables with no domain