<commit_before>import os
from refreshbooks import api
from sirius.models import Contract, Project
from sirius.errors import RecordNotFoundError

freshbooks = api.TokenClient(
    os.environ['FRESHBOOKS_URL'],
    os.environ['FRESHBOOKS_TOKEN'],
    user_agent='Sirius/1.0'
)

def freshbooks_sync(data):
    project_id = long(data['project_id'])
    contract_id = long(data['contract_id'])

    project = Project.get_by_id(project_id)
    if project is None:
        raise RecordNotFoundError('Project', project_id)

    contract = Contract.get_by_id(contract_id, parent=project.key)
    if contract is None:
        raise RecordNotFoundError('Contract', contract_id)

    for invoice in contract.invoices:
        if invoice[0] is None:
            invoice[0] = _create_invoice(project.url, invoice[1], invoice[3])
            invoice[2] = 'saved'

    contract.put()

def _create_invoice(notes, name, amount):
    """Creates an invoice in Freshbooks.

    Arguments:
        notes -- invoice notes
        name -- name of the invoice
        amount -- invoice amount

    Returns:
        invoice ID
    """
    return freshbooks.invoice.create(
        invoice=dict(
            client_id=os.environ['FRESHBOOKS_CLIENT_ID'],
            status='draft',
            notes=notes,
            lines=[
                api.types.line(
                    name=name,
                    unit_cost=amount,
                    quantity='1'
                )
            ]
        )
    )<commit_msg>use correct line description for invoice<commit_after>import os
from refreshbooks import api
from sirius.models import Contract, Project
from sirius.errors import RecordNotFoundError

freshbooks = api.TokenClient(
    os.environ['FRESHBOOKS_URL'],
    os.environ['FRESHBOOKS_TOKEN'],
    user_agent='Sirius/1.0'
)

def freshbooks_sync(data):
    project_id = long(data['project_id'])
    contract_id = long(data['contract_id'])

    project = Project.get_by_id(project_id)
    if project is None:
        raise RecordNotFoundError('Project', project_id)

    contract = Contract.get_by_id(contract_id, parent=project.key)
    if contract is None:
        raise RecordNotFoundError('Contract', contract_id)

    for invoice in contract.invoices:
        if invoice[0] is None:
            name = '{0} - {1}'.format(contract.name, invoice[1])
            invoice_id = _create_invoice(project.url, name, invoice[3])
            invoice = (invoice_id, invoice[1], 'saved', invoice[3])

    contract.put()

def _create_invoice(notes, name, amount):
    """Creates an invoice in Freshbooks.

    Arguments:
        notes -- invoice notes
        name -- name of the invoice
        amount -- invoice amount

    Returns:
        invoice ID
    """
    response = freshbooks.invoice.create(
        invoice=dict(
            client_id=os.environ['FRESHBOOKS_CLIENT_ID'],
            status='draft',
            notes=notes,
            lines=[
                api.types.line(
                    description=name,
                    unit_cost=amount,
                    quantity='1'
                )
            ]
        )
    )
    return int(response.invoice_id)
{'fraction_non_alphanumeric': 0.09955611921369689, 'fraction_numerical': 0.0057070386810399495, 'mean_word_length': 2.2933194154488517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4205047', 'n_tokens_mistral': 950, 'n_tokens_neox': 907, 'n_words': 204}