Exemple #1
0
    def rows(self):
        from corehq.apps.accounting.views import (
            WireInvoiceSummaryView, ManageBillingAccountView,
        )
        rows = []
        for invoice in self.invoices:
            new_this_month = (invoice.date_created.month == invoice.account.date_created.month
                              and invoice.date_created.year == invoice.account.date_created.year)
            try:
                contact_info = BillingContactInfo.objects.get(account=invoice.account)
            except BillingContactInfo.DoesNotExist:
                contact_info = BillingContactInfo()

            account_url = reverse(ManageBillingAccountView.urlname, args=[invoice.account.id])
            invoice_url = reverse(WireInvoiceSummaryView.urlname, args=(invoice.id,))
            columns = [
                format_datatables_data(
                    mark_safe(make_anchor_tag(invoice_url, invoice.invoice_number)),
                    invoice.id,
                ),
                format_datatables_data(
                    mark_safe(make_anchor_tag(account_url, invoice.account.name)),
                    invoice.account.name
                ),
                invoice.get_domain(),
                "YES" if new_this_month else "no",
                contact_info.company_name,
                contact_info.emails,
                contact_info.first_name,
                contact_info.last_name,
                contact_info.phone_number,
                contact_info.first_line,
                contact_info.second_line,
                contact_info.city,
                contact_info.state_province_region,
                contact_info.postal_code,
                contact_info.country,
                invoice.date_start,
                invoice.date_end,
                invoice.date_due,
                get_exportable_column(invoice.subtotal),
                get_exportable_column(invoice.balance),
                "Paid" if invoice.is_paid else "Not paid",
                "YES" if invoice.is_hidden else "no",
            ]

            if not self.is_rendered_as_email:
                columns.extend([
                    mark_safe(make_anchor_tag(invoice_url, 'Go to Invoice'))
                ])
            rows.append(columns)
        return rows
Exemple #2
0
    def rows(self):
        from corehq.apps.accounting.views import (
            InvoiceSummaryView, ManageBillingAccountView, EditSubscriptionView,
        )
        rows = []
        for invoice in self.invoices:
            new_this_month = (invoice.date_created.month == invoice.subscription.account.date_created.month
                              and invoice.date_created.year == invoice.subscription.account.date_created.year)
            try:
                contact_info = BillingContactInfo.objects.get(
                    account=invoice.subscription.account,
                )
            except BillingContactInfo.DoesNotExist:
                contact_info = BillingContactInfo()

            plan_name = u"{name} v{version}".format(
                name=invoice.subscription.plan_version.plan.name,
                version=invoice.subscription.plan_version.version,
            )
            plan_href = reverse(EditSubscriptionView.urlname, args=[invoice.subscription.id])
            account_name = invoice.subscription.account.name
            account_href = reverse(ManageBillingAccountView.urlname, args=[invoice.subscription.account.id])
            invoice_href = reverse(InvoiceSummaryView.urlname, args=(invoice.id,))

            columns = [
                format_datatables_data(
                    mark_safe(make_anchor_tag(invoice_href, invoice.invoice_number)),
                    invoice.id,
                ),
                format_datatables_data(
                    mark_safe(make_anchor_tag(account_href, account_name)),
                    invoice.subscription.account.name
                ),
                format_datatables_data(
                    mark_safe(make_anchor_tag(plan_href, plan_name)),
                    invoice.subscription.plan_version.plan.name
                ),
                invoice.subscription.subscriber.domain,
                "YES" if new_this_month else "no",
                contact_info.company_name,
                contact_info.emails,
                contact_info.first_name,
                contact_info.last_name,
                contact_info.phone_number,
                contact_info.first_line,
                contact_info.second_line,
                contact_info.city,
                contact_info.state_province_region,
                contact_info.postal_code,
                contact_info.country,
                invoice.subscription.account.salesforce_account_id or "--",
                invoice.subscription.salesforce_contract_id or "--",
                invoice.date_start,
                invoice.date_end,
                invoice.date_due if invoice.date_due else "None",
            ]

            plan_subtotal, plan_deduction = get_subtotal_and_deduction(
                invoice.lineitem_set.get_products().all()
            )
            sms_subtotal, sms_deduction = get_subtotal_and_deduction(
                invoice.lineitem_set.get_feature_by_type(FeatureType.SMS).all()
            )
            user_subtotal, user_deduction = get_subtotal_and_deduction(
                invoice.lineitem_set.get_feature_by_type(
                    FeatureType.USER
                ).all()
            )

            columns.extend([
                get_exportable_column(plan_subtotal),
                get_exportable_column(plan_deduction),
                get_exportable_column(sms_subtotal),
                get_exportable_column(sms_deduction),
                get_exportable_column(user_subtotal),
                get_exportable_column(user_deduction),
                get_exportable_column(invoice.subtotal),
                get_exportable_column(invoice.applied_credit),
                get_exportable_column(invoice.balance),
                "Paid" if invoice.is_paid else "Not paid",
                "YES" if invoice.is_hidden else "no",
            ])

            if not self.is_rendered_as_email:
                adjust_name = "Adjust Balance"
                adjust_href = "#adjustBalanceModal-{invoice_id}".format(invoice_id=invoice.id)
                adjust_attrs = {
                    "data-toggle": "modal",
                    "data-target": adjust_href,
                    "class": "btn",
                }
                columns.extend([
                    mark_safe(make_anchor_tag(adjust_href, adjust_name, adjust_attrs)),
                    mark_safe(make_anchor_tag(
                        invoice_href,
                        "Go to Invoice",
                        {"class": "btn"},
                    ))
                ])
            rows.append(columns)
        return rows