Time Entry

Supported by Redmine starting from version 1.1

Manager

All operations on the TimeEntry resource are provided by its manager. To get access to it you have to call redmine.time_entry where redmine is a configured redmine object. See the Configuration about how to configure redmine object.

Create methods

create

redminelib.managers.ResourceManager.create(**fields)

Creates new TimeEntry resource with given fields and saves it to the Redmine.

Parameters:
  • project_id (int issue_id or) – (required). The issue id or project id to log time on.

  • hours (int or float) – (required). The number of spent hours.

  • spent_on (string or date object) – (optional). The date the time was spent (current date if not set).

  • activity_id (int) – (optional). The id of the time activity. This parameter is required unless a default activity is defined in Redmine. Available activity ids can be retrieved per project using include=['time_entry_activities'], requires Redmine >= 3.4.0.

  • user_id (int) – (optional). Will create a time entry on behalf of this user id.

  • comments (string) – (optional). Short description for the entry (255 characters max).

Returns:

Resource object

>>> time_entry = redmine.time_entry.create(
...     issue_id=123,
...     spent_on=datetime.date(2014, 1, 14),
...     hours=3,
...     activity_id=10,
...     user_id=5,
...     comments='hello'
... )
>>> time_entry
<redminelib.resources.TimeEntry #12345>

new

redminelib.managers.ResourceManager.new()

Creates new empty TimeEntry resource but saves it to the Redmine only when save() is called, also calls pre_create() and post_create() methods of the Resource object. Valid attributes are the same as for create() method above.

Returns:

Resource object

>>> time_entry = redmine.time_entry.new()
>>> time_entry.issue_id = 123
>>> time_entry.spent_on = datetime.date(2014, 1, 14)
>>> time_entry.hours = 3
>>> time_entry.activity_id = 10
>>> time_entry.user_id = 5
>>> time_entry.comments = 'hello'
>>> time_entry.save()
<redminelib.resources.TimeEntry #12345>

Read methods

get

redminelib.managers.ResourceManager.get(resource_id)

Returns single TimeEntry resource from Redmine by its id.

Parameters:

resource_id (int) – (required). Id of the time entry.

Returns:

Resource object

>>> time_entry = redmine.time_entry.get(374)
>>> time_entry
<redminelib.resources.TimeEntry #374>

all

redminelib.managers.ResourceManager.all(**params)

Returns all TimeEntry resources from Redmine.

Parameters:
  • limit (int) – (optional). How much resources to return.

  • offset (int) – (optional). Starting from what resource to return the other resources.

Returns:

ResourceSet object

>>> time_entries = redmine.time_entry.all(offset=10, limit=100)
>>> time_entries
<redminelib.resultsets.ResourceSet object with TimeEntry resources>

filter

redminelib.managers.ResourceManager.filter(**filters)

Returns TimeEntry resources that match the given lookup parameters.

Parameters:
  • project_id (int or string) – (optional). Get time entries from the project with given id.

  • issue_id (int) – (optional). Get time entries from the issue with given id.

  • user_id (int) – (optional). Get time entries for the user with given id.

  • spent_on (string or date object) – (optional). Redmine >= 2.3.0 only. Date when time was spent.

  • from_date (string or date object) – (optional). Limit time entries from this date.

  • to_date (string or date object) – (optional). Limit time entries until this date.

  • hours (string) – (optional). Get only time entries that are =, >=, <= hours.

  • limit (int) – (optional). How much resources to return.

  • offset (int) – (optional). Starting from what resource to return the other resources.

Returns:

ResourceSet object

>>> time_entries = redmine.time_entry.filter(offset=10, limit=100, project_id='vacation', hours='>=8')
>>> time_entries
<redminelib.resultsets.ResourceSet object with TimeEntry resources>

Hint

You can also get time entries from an Issue, Project and User resource objects directly using time_entries relation:

>>> issue = redmine.issue.get(34213)
>>> issue.time_entries
<redminelib.resultsets.ResourceSet object with TimeEntry resources>

Update methods

update

redminelib.managers.ResourceManager.update(resource_id, **fields)

Updates values of given fields of a TimeEntry resource and saves them to the Redmine.

Parameters:
  • resource_id (int) – (required). Time entry id.

  • project_id (int issue_id or) – (optional). The issue id or project id to log time on.

  • hours (int) – (optional). The number of spent hours.

  • spent_on (string or date object) – (optional). The date the time was spent.

  • activity_id (int) – (optional). The id of the time activity. Available activity ids can be retrieved per project using include=['time_entry_activities'], requires Redmine >= 3.4.0.

  • user_id (int) – (optional). Will update a time entry on behalf of this user id.

  • comments (string) – (optional). Short description for the entry (255 characters max).

Returns:

True

>>> redmine.time_entry.update(
...     1,
...     issue_id=123,
...     spent_on=datetime.date(2014, 1, 14),
...     hours=3,
...     activity_id=10,
...     user_id=5,
...     comments='hello'
... )
True

save

redminelib.resources.TimeEntry.save(**attrs)

Saves the current state of a TimeEntry resource to the Redmine. Attrs that can be changed are the same as for update() method above.

Returns:

Resource object

>>> time_entry = redmine.time_entry.get(1)
>>> time_entry.issue_id = 123
>>> time_entry.spent_on = datetime.date(2014, 1, 14)
>>> time_entry.hours = 3
>>> time_entry.activity_id = 10
>>> time_entry.user_id = 5
>>> time_entry.comments = 'hello'
>>> time_entry.save()
<redminelib.resources.TimeEntry #1>

Added in version 2.1.0: Alternative syntax was introduced.

>>> time_entry = redmine.time_entry.get(1).save(
...     issue_id=123,
...     spent_on=datetime.date(2014, 1, 14),
...     hours=3,
...     activity_id=10,
...     comments='hello'
... )
>>> time_entry
<redminelib.resources.TimeEntry #1>

Delete methods

delete

redminelib.managers.ResourceManager.delete(resource_id)

Deletes single TimeEntry resource from Redmine by its id.

Parameters:

resource_id (int) – (required). Time entry id.

Returns:

True

>>> redmine.time_entry.delete(1)
True
redminelib.resources.TimeEntry.delete()

Deletes current TimeEntry resource object from Redmine.

Returns:

True

>>> entry = redmine.time_entry.get(1)
>>> entry.delete()
True

Export

Added in version 2.0.0.

redminelib.resultsets.ResourceSet.export(fmt, savepath=None, filename=None, columns=None, encoding='UTF-8')

Exports a resource set of TimeEntry resources in one of the following formats: atom, csv

Parameters:
  • fmt (string) – (required). Format to use for export.

  • savepath (string) – (optional). Path where to save the file.

  • filename (string) – (optional). Name that will be used for the file.

  • columns (iterable or string) – (optional). Iterable of column names or “all” string for all available columns or “all_gui” string for GUI like behaviour or iterable of elements with “all_gui” string and additional columns to export.

  • encoding – (optional). Encoding that will be used for the result file.

Returns:

String or Object

>>> entries = redmine.time_entry.all()
>>> entries.export('csv', savepath='/home/jsmith', filename='entries.csv', columns='all')
'/home/jsmith/entries.csv'