Exemplo n.º 1
0
 def testSMSBilling(self):
     generate_monthly_bills()
     last_bill = HQMonthlyBill.get_bills(self.domain.name).first()
     if last_bill:
         self.assertEqual(self.tropo_bill.total_billed, last_bill.incoming_sms_billed)
         self.assertEqual(self.unicel_bill.total_billed + self.mach_bill.total_billed, last_bill.outgoing_sms_billed)
     else:
         raise Exception("Monthly Bill not successfully generated.")
Exemplo n.º 2
0
    def rows(self):
        rows = []

        for domain in self.domains:
            all_bills = HQMonthlyBill.get_bills(domain.name,
                start=self.datespan.startdate_param_utc,
                end=self.datespan.enddate_param_utc
            ).all()
            for bill in all_bills:
                nice_start = bill.billing_period_start.strftime("%B %d, %Y")
                nice_end = bill.billing_period_end.strftime("%B %d, %Y")
                rows.append([
                    domain.name,
                    self._format_client(domain),
                    self.table_cell(
                        bill.billing_period_start,
                        nice_start
                    ),
                    self.table_cell(
                        bill.billing_period_end,
                        nice_end
                    ),
                    self._format_bill_amount(bill.incoming_sms_billed),
                    self._format_bill_amount(bill.outgoing_sms_billed),
                    self._format_bill_amount(bill.incoming_sms_billed+bill.outgoing_sms_billed),
                    bill.currency.currency_code,
                    self.table_cell(
                        int(bill.paid),
                        mark_safe(render_to_string("hqbilling/partials/paid_button.html", {
                            'payment_status': "yes" if bill.paid else "no",
                            'bill_id': bill.get_id,
                            'payment_status_text': "Paid" if bill.paid else "Not Paid",
                            'button_class': "btn-success paid" if bill.paid else "btn-danger",
                            'billing_start': nice_start,
                            'billing_end': nice_end,
                            'domain': domain.name,
                        }))
                    ),
                    mark_safe('<a href="%s" class="btn btn-primary">View Invoice</a>' %
                        reverse("billing_invoice", kwargs=dict(bill_id=bill.get_id))),
                    mark_safe('<a href="%s" class="btn"><i class="icon icon-list"></i> View Itemized</a>' %
                        reverse("billing_itemized", kwargs=dict(bill_id=bill.get_id)))
                ])

        return rows
Exemplo n.º 3
0
    def handle(self, *args, **options):
        if len(args) < 2:
            raise CommandError("year and month are required")

        if len(args) > 2:
            domains = [Domain.get_by_name(args[2])]
        else:
            domains = SelectSMSBillableDomainsFilter.get_billable_domains()

        first_day, last_day = month_span(int(args[0]), int(args[1]))
        print "\nRecalculating SMS in HQ Bills\n----\n"
        for domain in domains:
            bills_for_domain = HQMonthlyBill.get_bills(domain.name,
                start=first_day.isoformat(),
                end=last_day.isoformat()).all()
            print "Found %d SMS Bills for domain %s" % (len(bills_for_domain), domain.name)
            for bill in bills_for_domain:
                bill._get_sms_activities(INCOMING)
                bill._get_sms_activities(OUTGOING)
                bill.save()
                sys.stdout.flush()
            print "\n"