def create_wire_invoice(self, balance): # Gather relevant invoices if self.account and self.account.is_customer_billing_account: invoices = CustomerInvoice.objects.filter(account=self.account) else: invoices = Invoice.objects.filter( subscription__subscriber__domain=self.domain.name, is_hidden=False, date_paid__exact=None ).order_by('-date_start') self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.__class__.__name__, entry_point=EntryPoint.SELF_STARTED )[0] # If no start date supplied, default earliest start date of unpaid invoices if self.date_start: date_start = self.date_start else: date_start = invoices.aggregate(Min('date_start'))['date_start__min'] # If no end date supplied, default latest end date of unpaid invoices if self.date_end: date_end = self.date_end else: date_end = invoices.aggregate(Max('date_end'))['date_end__max'] if not date_end: date_end = datetime.datetime.today() date_due = date_end + datetime.timedelta(DEFAULT_DAYS_UNTIL_DUE) wire_invoice = WireInvoice.objects.create( domain=self.domain.name, date_start=date_start, date_end=date_end, date_due=date_due, balance=balance, ) record = WireBillingRecord.generate_record(wire_invoice) if record.should_send_email: try: for email in self.contact_emails: record.send_email(contact_email=email) except InvoiceEmailThrottledError as e: # Currently wire invoices are never throttled if not self.logged_throttle_error: log_accounting_error(six.text_type(e)) self.logged_throttle_error = True else: record.skipped_email = True record.save() return wire_invoice
def create_wire_invoice(self, balance): # Gather relevant invoices if self.account and self.account.is_customer_billing_account: invoices = CustomerInvoice.objects.filter(account=self.account) else: invoices = Invoice.objects.filter( subscription__subscriber__domain=self.domain.name, is_hidden=False, date_paid__exact=None ).order_by('-date_start') self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.__class__.__name__, entry_point=EntryPoint.SELF_STARTED )[0] # If no start date supplied, default earliest start date of unpaid invoices if self.date_start: date_start = self.date_start else: date_start = invoices.aggregate(Min('date_start'))['date_start__min'] # If no end date supplied, default latest end date of unpaid invoices if self.date_end: date_end = self.date_end else: date_end = invoices.aggregate(Max('date_end'))['date_end__max'] if not date_end: date_end = datetime.datetime.today() date_due = date_end + datetime.timedelta(DEFAULT_DAYS_UNTIL_DUE) wire_invoice = WireInvoice.objects.create( domain=self.domain.name, date_start=date_start, date_end=date_end, date_due=date_due, balance=balance, ) record = WireBillingRecord.generate_record(wire_invoice) if record.should_send_email: try: for email in self.contact_emails: record.send_email(contact_email=email) except InvoiceEmailThrottledError as e: # Currently wire invoices are never throttled if not self.logged_throttle_error: log_accounting_error(six.text_type(e)) self.logged_throttle_error = True else: record.skipped_email = True record.save() return wire_invoice
def create_wire_invoice(self, balance): # Gather relevant invoices invoices = Invoice.objects.filter( subscription__subscriber__domain=self.domain, is_hidden=False, date_paid__exact=None, ).order_by('-date_start') account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.__class__.__name__, created_by_invoicing=True, entry_point=EntryPoint.SELF_STARTED, )[0] # If no start date supplied, default earliest start date of unpaid invoices if self.date_start: date_start = self.date_start else: date_start = invoices.aggregate(Min('date_start'))['date_start__min'] # If no end date supplied, default latest end date of unpaid invoices if self.date_end: date_end = self.date_end else: date_end = invoices.aggregate(Max('date_end'))['date_end__max'] if not date_end: date_end = datetime.datetime.today() date_due = date_end + datetime.timedelta(DEFAULT_DAYS_UNTIL_DUE) # TODO: figure out how to handle line items wire_invoice = WireInvoice.objects.create( domain=self.domain.name, date_start=date_start, date_end=date_end, date_due=date_due, balance=balance, account=account ) record = WireBillingRecord.generate_record(wire_invoice) try: record.send_email(contact_emails=self.contact_emails) except InvoiceEmailThrottledError as e: # Currently wire invoices are never throttled if not self.logged_throttle_error: logger.error("[BILLING] %s" % e) self.logged_throttle_error = True return wire_invoice
def create_wire_invoice(self, balance): # Gather relevant invoices invoices = Invoice.objects.filter( subscription__subscriber__domain=self.domain, is_hidden=False, date_paid__exact=None, ).order_by('-date_start') account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.__class__.__name__, created_by_invoicing=True, entry_point=EntryPoint.SELF_STARTED, )[0] # If no start date supplied, default earliest start date of unpaid invoices if self.date_start: date_start = self.date_start else: date_start = invoices.aggregate( Min('date_start'))['date_start__min'] # If no end date supplied, default latest end date of unpaid invoices if self.date_end: date_end = self.date_end else: date_end = invoices.aggregate(Max('date_end'))['date_end__max'] if not date_end: date_end = datetime.datetime.today() date_due = date_end + datetime.timedelta(DEFAULT_DAYS_UNTIL_DUE) # TODO: figure out how to handle line items wire_invoice = WireInvoice.objects.create(domain=self.domain.name, date_start=date_start, date_end=date_end, date_due=date_due, balance=balance, account=account) record = WireBillingRecord.generate_record(wire_invoice) try: record.send_email(contact_emails=self.contact_emails) except InvoiceEmailThrottledError as e: # Currently wire invoices are never throttled if not self.logged_throttle_error: logger.error("[BILLING] %s" % e) self.logged_throttle_error = True return wire_invoice