def _render_transaction(transaction):
    """Render out a transaction as string.

    Args:
        transaction: A Transaction.

    Returns:
        A string containing the transaction in Beancount's format.

    """
    lines = ['{} {} "{}" "{}"'.format(transaction.date, transaction.flag,
        transaction.payee, transaction.narration)]
    if transaction.meta and len(transaction.meta.keys()) > 0:
        for key, value in transaction.meta.items():
            lines.append('    {}: "{}"'.format(key, value))
    for posting in transaction.postings:
        line = '    {}'.format(posting.account)
        if posting.units.number or posting.units.currency:
            number_length = str(posting.units.number).find('.')
            line += ' ' * max(49 - len(posting.account) - number_length, 2)
            line += '{} {}'.format(posting.units.number or '', posting.
                units.currency or '')
        lines.append(line)
    return '\n'.join(lines)
