Esempio n. 1
0
    def setUp(self):
        super(TestCustomerBillingRecord, self).setUp()
        self.billing_contact = generator.create_arbitrary_web_user_name()
        self.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True)
        self.domain = Domain(name='test')
        self.domain.save()
        self.invoice_start, self.invoice_end = get_previous_month_date_range()
        self.currency = generator.init_default_currency()
        self.account = generator.billing_account(self.dimagi_user, self.billing_contact)
        self.account.is_customer_billing_account = True
        self.account.save()

        self.subscription_length = 4  # months
        subscription_start_date = datetime.date(2016, 2, 23)
        subscription_end_date = add_months_to_date(subscription_start_date, self.subscription_length)
        self.subscription = generator.generate_domain_subscription(
            self.account,
            self.domain,
            date_start=subscription_start_date,
            date_end=subscription_end_date,
        )
        self.invoice = CustomerInvoice(
            account=self.account,
            date_start=self.invoice_start,
            date_end=self.invoice_end,
            is_hidden=False
        )
        self.customer_billing_record = CustomerBillingRecord(invoice=self.invoice)
Esempio n. 2
0
 def _email_invoice(self):
     record = CustomerBillingRecord.generate_record(self.customer_invoice)
     try:
         if self.recipients:
             for email in self.recipients:
                 record.send_email(contact_email=email)
         elif self.account.dimagi_contact:
             record.send_email(contact_email=self.account.dimagi_contact,
                               cc_emails=[settings.ACCOUNTS_EMAIL])
         else:
             record.send_email(contact_email=settings.ACCOUNTS_EMAIL)
     except InvoiceEmailThrottledError as e:
         log_accounting_error(str(e))
Esempio n. 3
0
 def _email_invoice(self):
     record = CustomerBillingRecord.generate_record(self.customer_invoice)
     try:
         if self.recipients:
             for email in self.recipients:
                 record.send_email(contact_email=email)
         elif self.account.enterprise_admin_emails:
             for email in self.account.enterprise_admin_emails:
                 record.send_email(contact_email=email)
         elif self.account.dimagi_contact:
             record.send_email(contact_email=self.account.dimagi_contact,
                               cc_emails=[settings.ACCOUNTS_EMAIL])
         else:
             record.send_email(contact_email=settings.ACCOUNTS_EMAIL)
     except InvoiceEmailThrottledError as e:
         log_accounting_error(str(e))