Ejemplo n.º 1
0
    def save(self):
        mach_file = self.cleaned_data['mach_file']
        overwrite = self.cleaned_data['overwrite']

        for row in mach_file:
            row = dict([(key.split(' ')[0], val) for key, val in row.items()])
            mach_rate = MachSMSRate.get_default(**row)

            # clean up parser
            for k in ['mcc', 'country_code', 'mnc']:
                row[k] = str(row[k])

            for k in ['network_surcharge']:
                val = row[k] or 0.0
                row[k] = "%f" % val

            if mach_rate and not overwrite:
                continue
            if not mach_rate:
                mach_rate = MachSMSRate()
            for key, item in row.items():
                try:
                    setattr(mach_rate, key, item)
                except AttributeError:
                    pass
            mach_rate.save()
Ejemplo n.º 2
0
def update_mach_billables():
    """
    Goes through all billable items tied to mach (SMS records) and tries
    to make sure that they are properly associated with rates from mach.
    """
    mach_data = get_mach_data(days=3)
    try:
        # rateless billables are Mach Billables that do not have a delivered date
        rateless_billables = MachSMSBillable.get_rateless()
        for billable in rateless_billables:
            billable.sync_attempts.append(datetime.datetime.utcnow())
            for data in mach_data:
                phone_number = data[3]
                if phone_number == billable.phone_number:
                    mach_number = MachPhoneNumber.get_by_number(phone_number, data)
                    rate_item = MachSMSRate.get_by_number(billable.direction, mach_number)

                    billable.calculate_rate(rate_item)
                    billable.save()

                    billable.update_mach_delivery_status(data)
                    billable.save()

                    if billable.rate_id and billable.mach_delivered_date:
                        break
            deal_with_delinquent_mach_billable(billable)

    except Exception as e:
        logging.error("There was an error updating mach billables: %s" % e)