def format_outpat(outpat, xn):
    """
    Format an outpat for the given transaction.

    Format the given output filename pattern.  The pattern should
    be a format string with any combination of the following named
    fields:

    ``year``
      The year of the transaction.
    ``month``
      The month of the transaction, with leading zero for
      single-digit months.
    ``fy``
      The financial year of the transaction (being the year in
      which the financial year of the transaction *ends*).
      A financial year runs from 1 July to 30 June.
    ``date``
      The date object itself.  The format string may specify
      any attribute of the date object, e.g. ``{date.day}``.
      This field is deprecated.
    """
    return outpat.format(
        year=str(xn.date.year),
        month='{:02}'.format(xn.date.month),
        fy=str(xn.date.year if xn.date.month < 7 else xn.date.year + 1),
        date=xn.date
    )