# Buggy code
def get_outstanding_reference_documents(args):
    args = json.loads(args)

    party_account_currency = get_account_currency(args.get("party_account"))
    company_currency = frappe.db.get_value(
        "Company", args.get("company"), "default_currency"
    )

    # Get negative outstanding sales /purchase invoices
    total_field = (
        "base_grand_total"
        if party_account_currency == company_currency
        else "grand_total"
    )

    negative_outstanding_invoices = get_negative_outstanding_invoices(
        args.get("party_type"),
        args.get("party"),
        args.get("party_account"),
        total_field,
    )

    # Get positive outstanding sales /purchase invoices
    outstanding_invoices = get_outstanding_invoices(
        args.get("party_type"), args.get("party"), args.get("party_account")
    )

    for d in outstanding_invoices:
        d["exchange_rate"] = 1
        if party_account_currency != company_currency:
            if d.voucher_type in ("Sales Invoice", "Purchase Invoice", "Expense Claim"):
                d["exchange_rate"] = frappe.db.get_value(
                    d.voucher_type, d.voucher_no, "conversion_rate"
                )
            elif d.voucher_type == "Journal Entry":
                d["exchange_rate"] = get_exchange_rate(
                    party_account_currency, company_currency, d.posting_date
                )

    # Get all SO / PO which are not fully billed or aginst which full advance not paid
    orders_to_be_billed = get_orders_to_be_billed(
        args.get("posting_date"),
        args.get("party_type"),
        args.get("party"),
        party_account_currency,
        company_currency,
    )

    return negative_outstanding_invoices + outstanding_invoices + orders_to_be_billed


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/makarandbauskar/workspace/frappe/dev-bench/apps/erpnext/erpnext/subscription/doctype/subscription/subscription.py", line 120, in create_documents
send_notification(doc, data.print_format, data.recipients)
File "/Users/makarandbauskar/workspace/frappe/dev-bench/apps/erpnext/erpnext/subscription/doctype/subscription/subscription.py", line 178, in send_notification
print_format = print_format or new_rv.recurring_print_format
AttributeError: 'DeliveryNote' object has no attribute 'recurring_print_format'

# Fixed code
def get_outstanding_reference_documents(args):
    if isinstance(args, basestring):
        args = json.loads(args)

    party_account_currency = get_account_currency(args.get("party_account"))
    company_currency = frappe.db.get_value(
        "Company", args.get("company"), "default_currency"
    )

    # Get negative outstanding sales /purchase invoices
    total_field = (
        "base_grand_total"
        if party_account_currency == company_currency
        else "grand_total"
    )

    negative_outstanding_invoices = get_negative_outstanding_invoices(
        args.get("party_type"),
        args.get("party"),
        args.get("party_account"),
        total_field,
    )

    # Get positive outstanding sales /purchase invoices
    outstanding_invoices = get_outstanding_invoices(
        args.get("party_type"), args.get("party"), args.get("party_account")
    )

    for d in outstanding_invoices:
        d["exchange_rate"] = 1
        if party_account_currency != company_currency:
            if d.voucher_type in ("Sales Invoice", "Purchase Invoice", "Expense Claim"):
                d["exchange_rate"] = frappe.db.get_value(
                    d.voucher_type, d.voucher_no, "conversion_rate"
                )
            elif d.voucher_type == "Journal Entry":
                d["exchange_rate"] = get_exchange_rate(
                    party_account_currency, company_currency, d.posting_date
                )

    # Get all SO / PO which are not fully billed or aginst which full advance not paid
    orders_to_be_billed = get_orders_to_be_billed(
        args.get("posting_date"),
        args.get("party_type"),
        args.get("party"),
        party_account_currency,
        company_currency,
    )

    return negative_outstanding_invoices + outstanding_invoices + orders_to_be_billed