Add basic support for updating a Harvest Time Entry via API

This commit is contained in:
Lance Edgar 2022-03-06 11:09:59 -06:00
parent d84cc7a9d9
commit 03066f1135
2 changed files with 27 additions and 5 deletions

View file

@ -128,13 +128,23 @@ class TimeEntryImporter(ToHarvest):
entry = self.webapi.put_time_entry(**kwargs)
return entry
def update_object(self, obj, host_data, local_data=None, all_fields=False):
def update_object(self, entry, host_data, local_data=None, all_fields=False):
if self.dry_run:
return obj
return entry
raise NotImplementedError
kwargs = {
'project_id': host_data['project_id'],
'task_id': host_data['task_id'],
'spent_date': host_data['spent_date'],
# 'started_time': host_data['started_time'],
# 'ended_time': host_data['ended_time'],
'hours': host_data['hours'],
'notes': host_data['notes'],
}
def delete_object(self, obj):
return self.webapi.update_time_entry(entry['id'], **kwargs)
def delete_object(self, entry):
if self.dry_run:
return True

View file

@ -163,7 +163,7 @@ class HarvestWebAPI(object):
response = self.get('/time_entries/{}'.format(time_entry_id))
return response.json()
def put_time_entry(self, **kwargs):
def create_time_entry(self, **kwargs):
"""
Create a new time entry. All kwargs are passed on as POST parameters.
@ -177,6 +177,9 @@ class HarvestWebAPI(object):
response = self.post('/time_entries', params=kwargs)
return response.json()
# TODO: deprecate / remove this
put_time_entry = create_time_entry
def stop_time_entry(self, time_entry_id):
"""
Stop a running time entry.
@ -186,6 +189,15 @@ class HarvestWebAPI(object):
response = self.patch('/time_entries/{}/stop'.format(time_entry_id))
return response.json()
def update_time_entry(self, time_entry_id, **kwargs):
"""
Update a time entry.
https://help.getharvest.com/api-v2/timesheets-api/timesheets/time-entries/#update-a-time-entry
"""
response = self.patch('/time_entries/{}'.format(time_entry_id), params=kwargs)
return response.json()
def make_harvest_webapi(config):
access_token = config.require('harvest', 'api.access_token')