Exemplo n.º 1
0
    def handle(self, *labels, **options):
        old_django_messages = MessageLogOld.objects.all()

        print "Migrating MessageLog"
        for message in old_django_messages:

            new_key = hashlib.md5(
                "%s %s %s %s %s %s"
                % (
                    message.couch_recipient,
                    message.domain,
                    message.phone_number,
                    message.direction,
                    message.date,
                    " ".join([str(ord(c)) for c in message.text]),  # hack to support arbitrarily encoded strings
                )
            ).hexdigest()
            try:
                couch_message = MessageLog(
                    _id=new_key,
                    couch_recipiet=message.couch_recipient,
                    domain=message.domain,
                    phone_number=message.phone_number,
                    direction=message.direction,
                    date=message.date,
                    text=message.text,
                )
                couch_message.save()
            except Exception as e:
                print "There was an error migrating MessageLog with text %s to couch_recipient %s in domain %s." % (
                    message.text,
                    message.couch_recipient,
                    message.domain,
                )
Exemplo n.º 2
0
    def handle(self, *labels, **options):
        old_django_messages = MessageLogOld.objects.all()

        print "Migrating MessageLog"
        for message in old_django_messages:

            new_key = hashlib.md5("%s %s %s %s %s %s" % (
                message.couch_recipient,
                message.domain,
                message.phone_number,
                message.direction,
                message.date,
                " ".join([str(ord(c)) for c in message.text
                          ])  # hack to support arbitrarily encoded strings
            )).hexdigest()
            try:
                couch_message = MessageLog(
                    _id=new_key,
                    couch_recipiet=message.couch_recipient,
                    domain=message.domain,
                    phone_number=message.phone_number,
                    direction=message.direction,
                    date=message.date,
                    text=message.text)
                couch_message.save()
            except Exception as e:
                print "There was an error migrating MessageLog with text %s to couch_recipient %s in domain %s." % (
                    message.text,
                    message.couch_recipient,
                    message.domain,
                )
Exemplo n.º 3
0
def deal_with_delinquent_mach_billable(billable):
    if len(billable.sync_attempts) > 6 and not (billable.rate_id and billable.mach_delivered_date):
        # billable information not complete, mark billable item as error and do not charge for the message.
        message = MessageLog.get(billable.log_id)
        message.billed = False
        message.billing_errors.append("Could not verify Mach billable after several attempts.")
        message.save()

        now = datetime.datetime.utcnow()
        # officially close out the billable
        billable.billable_date = billable.billable_date or now
        billable.modified_date = billable.modified_date or now
        billable.mach_delivered_date = billable.mach_delivered_date or now
        from hqbilling.models import UNKNOWN_RATE_ID
        billable.rate_id = billable.rate_id or UNKNOWN_RATE_ID
        if billable.mach_delivery_status != "accepted":
            # generally the status will say something other than accepted after a while once it's actually accepted,
            # however, sometimes it just stays at this. If it has any other delivery status at this point, mark it as
            # an error.
            billable.billable_amount = 0
            billable.conversion_rate = 1
            billable.dimagi_surcharge = billable.dimagi_surcharge or 0
            billable.has_error = True
            if not billable.error_message:
                billable.error_message = "Mach failed to send message due to '%s'" % billable.mach_delivery_status

        billable.save()
Exemplo n.º 4
0
def bill_client_for_sms(klass, message_id, **kwargs):
    from corehq.apps.sms.models import MessageLog
    try:
        message = MessageLog.get(message_id)
    except Exception as e:
        logging.exception("Failed to retrieve message log corresponding to billable: %s" % e)
        return
    try:
        klass.handle_api_response(message, **kwargs)
    except Exception as e:
        logging.exception("Failed create billable item from message %s.\n ERROR: %s" % (message, e))
Exemplo n.º 5
0
 def handle_noargs(self, *args, **options):
     mach_billables = MachSMSBillable.get_db().view(
         "hqbilling/sms_billables",
         startkey=["billable type date", "MachSMSBillable", "2013-08-01"],
         endkey=["billable type date", "MachSMSBillable", "2013-11-30"],
         reduce=False,
     ).all()
     mach_billables_ids = [billable['id'] for billable in mach_billables]
     billable_num = 0
     total_billables = len(mach_billables_ids)
     for billable_doc in iter_docs(MachSMSBillable.get_db(), mach_billables_ids):
         billable_num += 1
         billable = MachSMSBillable.wrap(billable_doc)
         message_log = MessageLog.get(billable.log_id)
         billable.billable_date = message_log.date
         billable.save()
         print "(%d/%d) Successfully restored billable date on Mach Billable %s to %s" \
               % (billable_num, total_billables, billable._id, billable.billable_date)