Exemple #1
0
    def rows(self):
        rows = []
        totals = [0,0,0]

        show_dupes = self.request.GET.get(SelectBillableDuplicateFilter.slug) == 'all'
        for domain in self.domains:
            if self.direction:
                billables = SMSBillable.by_domain_and_direction(domain.name, self.direction,
                    start=self.datespan.startdate_param_utc, end=self.datespan.enddate_param_utc)
            else:
                billables = SMSBillable.by_domain(domain.name,
                    start=self.datespan.startdate_param_utc, end=self.datespan.enddate_param_utc)
            # yes, I know I'm lazy...but this view is going away soon anyway
            billables.reverse()
            last_billable = None
            for billable in billables:
                if last_billable and last_billable.log_id == billable.log_id and not show_dupes:
                    continue
                totals[0] += billable.converted_billable_amount
                totals[1] += billable.dimagi_surcharge
                totals[2] += billable.total_billed
                row = [
                    self.table_cell(
                        billable.billable_date.isoformat(),
                        billable.billable_date.strftime("%Y-%m-%d %H:%M:%S")
                    ),
                    self.table_cell(
                        billable.modified_date.isoformat(),
                        billable.modified_date.strftime("%Y-%m-%d %H:%M:%S")
                    ),
                    self._format_client(domain),
                    billable.log_id,
                    domain.name,
                    SMS_DIRECTIONS.get(billable.direction),
                    billable.api_name(),
                    render_to_string("hqbilling/partials/billing_status_details.html", {
                        'has_error': billable.has_error,
                        'error_msg': billable.error_message,
                        'billable_type': billable.api_name(),
                        'billed_date': billable.billable_date.strftime("%d %b %Y at %H.%M UTC"),
                        'billable_id': billable._id,
                    }),
                    self._format_bill_amount(billable.converted_billable_amount),
                    self._format_bill_amount(billable.dimagi_surcharge),
                    self._format_bill_amount(billable.total_billed)
                ]
                rows.append(row)
                last_billable = billable
        self.total_row = ["", "", "", "", "", "", "", "Total Billed:"] + ["%.2f" % t for t in totals]
        return rows
Exemple #2
0
from django import forms
from django.conf import settings
from django.forms.util import ErrorList
from django.utils.safestring import mark_safe
from openpyxl.shared.exc import InvalidFileException
from corehq.apps.crud.models import BaseAdminCRUDForm
from dimagi.utils.excel import WorkbookJSONReader
from hqstyle.forms.widgets import BootstrapRadioSelect, \
    BootstrapAddressField, BootstrapPhoneNumberInput
from hqbilling.models import (SMSRate, MachSMSRate, TropoSMSRate, UnicelSMSRate, DimagiDomainSMSRate, OUTGOING,
    SMS_DIRECTIONS, INCOMING, DEFAULT_BASE, TaxRateByCountry, BillableCurrency, MACH_BASE_RATE)
from django.utils.translation import ugettext_lazy


DIRECTION_CHOICES = ((OUTGOING, SMS_DIRECTIONS.get(OUTGOING),), (INCOMING, SMS_DIRECTIONS.get(INCOMING),))
DUPE_CHECK_NEW = "new"
DUPE_CHECK_EXISTING = "existing"


class SMSRateForm(BaseAdminCRUDForm):
    doc_class = SMSRate

    # fields
    direction = forms.ChoiceField(widget=BootstrapRadioSelect, initial=OUTGOING, choices=DIRECTION_CHOICES)
    base_fee = forms.DecimalField(required=True, initial=DEFAULT_BASE, label="Fee")


class MachSMSRateForm(SMSRateForm):
    doc_class = MachSMSRate

    # fields
Exemple #3
0
 def options(self):
     return SMS_DIRECTIONS.items()