Returns all invoices that are unpaid on freckle but have transactions.

    This means, that the invoice is either partially paid and can be left as
    unpaid in freckle, or the invoice has been fully paid and should be set to
    paid in freckle as well.

def get_unpaid_invoices_with_transactions(branch=None):
    """
    Returns all invoices that are unpaid on freckle but have transactions.

    This means, that the invoice is either partially paid and can be left as
    unpaid in freckle, or the invoice has been fully paid and should be set to
    paid in freckle as well.

    """
    if not client:  # pragma: nocover
        return None
    result = {}
    try:
        unpaid_invoices = client.fetch_json(
            'invoices', query_params={'state': 'unpaid'})
    except (ConnectionError, HTTPError):  # pragma: nocover
        result.update({'error': _('Wasn\'t able to connect to Freckle.')})
    else:
        invoices = []
        for invoice in unpaid_invoices:
            invoice_with_transactions = models.Invoice.objects.filter(
                invoice_number=invoice['reference'],
                transactions__isnull=False)
            if branch:
                invoice_with_transactions = invoice_with_transactions.filter(
                    branch=branch)
            if invoice_with_transactions:
                invoices.append(invoice)
        result.update({'invoices': invoices})
    return result