XeroAPI / xero-python-oauth2-app

python app for demonstrating the xero-python SDK
MIT License
20 stars 32 forks source link

Timesheet Create Example #7

Closed NateJones5150 closed 3 years ago

NateJones5150 commented 4 years ago

Hi Team, this isn't an issue with the code - more hoping you can assist with the below.

Where can I see an example of a timesheet create for the demo apps you've created here? I've attempted to modify other "create" routes in the examples here but keep getting errors (see below). FYI I'm running this with the demo company.

Any direction/help you can provide would be massively appreciated.

Many thanks in advance.

My Timesheet Create route: @app.route("/payroll_au_timesheet_create") @xero_token_required def payroll_au_timesheet_create(): code = get_code_snippet("TIMESHEET","READ_ALL")

xero_tenant_id = get_xero_tenant_id()
payrollau_api = PayrollAuApi(api_client)

timesheetline = TimesheetLine(
    earnings_rate_id = "0a03847b-e537-4341-956b-2350a8c34a75",
    #tracking_item_id = "str",
    number_of_units = [8.0,8.0,8.0,5.0,4.0,3.0,8.0],
    updated_date_utc = dateutil.parser.parse("2020-08-09T00:00:00Z"),
    )

timesheet = Timesheet(
    employee_id = "7fb4f0aa-7a6f-45a1-acba-bf1c6e7deebd" ,
    end_date = dateutil.parser.parse("2020-08-09T00:00:00Z") ,
    hours = 24.0 ,
    start_date = dateutil.parser.parse("2020-08-03T00:00:00Z") ,
    status = TimesheetStatus.DRAFT ,
    #timesheet_id = "a112f73b-a6aa-48c6-a793-f344563b6a1c" ,
    timesheet_lines = timesheetline ,
    updated_date_utc = dateutil.parser.parse("2020-08-09T00:00:00Z") ,
    )

try:
    created_timesheet = payrollau_api.create_timesheet(
        xero_tenant_id, timesheet=timesheet
    )
except AccountingBadRequestException as exception:
    output = "Error: " + exception.reason
    json = jsonify(exception.error_data)
else:
    output = "Employee created with first name {}".format(
        getvalue(created_timesheet, "employees.0.first_name", "")
    )
    json = serialize_model(created_timesheet)

return render_template(
    "output.html", title="Timesheet", code=code, output=output, json=json, len = 0, set="payroll_au", endpoint="timesheet", action="create"
)

The error I'm getting: TypeError: 'TimesheetLine' object is not iterable

NateJones5150 commented 3 years ago

worked it out