Expense¶
Added in version 2.4.0.
Requires Pro Edition and Invoices plugin >= 4.1.3.
Manager¶
All operations on the Expense resource are provided by its manager. To get access to it
you have to call redmine.expense
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 Expense resource with given fields and saves it to the Invoices plugin.
- Parameters:
project_id (int or string) – (required). Id or identifier of expense’s project.
status_id (int) – (required). Expense status id:
1 - draft
2 - new
3 - billed
4 - paid
expense_date (string or date object) – (required). Date when expense occurred.
price (string) – (optional). Expense amount.
currency (string) – (optional). Expense currency.
contact_id (int) – (optional). Expense contact id.
assigned_to_id (int) – (optional). Expense will be assigned to this user id.
is_billable (bool) – (optional). Whether expense is billable.
linked_issue_id (int) – (optional). Issue id to be linked with this expense.
description (string) – (optional). Expense description.
uploads (list) – (optional). Uploads as [{'': ''}, ...], accepted keys are:
path (required). Absolute file path or file-like object that should be uploaded.
filename (optional). Name of the file after upload.
description (optional). Description of the file.
content_type (optional). Content type of the file.
- Returns:
Resource object
>>> expense = redmine.expense.create(
... project_id='invoices',
... status_id=2,
... expense_date='2023-01-11',
... price='13.56',
... currency='USD',
... contact_id=3,
... assigned_to_id=12,
... is_billable=True,
... description='description',
... linked_issue_id=557,
... uploads=[{'path': '/absolute/path/to/file'}, {'path': BytesIO(b'I am content of file 2')}]
... )
>>> expense
<redminelib.resources.Expense #123>
new¶
- redminelib.managers.ResourceManager.new()
Creates new empty Expense resource, but saves it to the Invoices plugin only when
save()
is called, also callspre_create()
andpost_create()
methods of the Resource object. Valid attributes are the same as forcreate()
method above.- Returns:
Resource object
>>> expense = redmine.expense.new()
>>> expense.project_id = 'invoices'
>>> expense.status_id = 2
>>> expense.expense_date = '2023-01-11'
>>> expense.price = '13.56'
>>> expense.currency = 'USD'
>>> expense.contact_id = 3
>>> expense.assigned_to_id = 12
>>> expense.is_billable = True
>>> expense.description = 'description'
>>> expense.linked_issue_id = 557
>>> expense.uploads = [{'path': '/absolute/path/to/file'}, {'path': BytesIO(b'I am content of file 2')}]
>>> expense.save()
<redminelib.resources.Expense #123>
Read methods¶
get¶
- redminelib.managers.ResourceManager.get(resource_id, **params)
Returns single Expense resource from the Invoices plugin by its id.
- Parameters:
resource_id (int) – (required). Id of the expense.
- Returns:
Resource object
>>> expense = redmine.expense.get(123)
>>> expense
<redminelib.resources.Expense #123>
all¶
- redminelib.managers.ResourceManager.all(**params)
Returns all Expense resources from the Invoices plugin.
- Parameters:
limit (int) – (optional). How much resources to return.
offset (int) – (optional). Starting from what resource to return the other resources.
- Returns:
ResourceSet object
>>> expenses = redmine.expense.all(limit=50)
>>> expenses
<redminelib.resultsets.ResourceSet object with Expense resources>
filter¶
- redminelib.managers.ResourceManager.filter(**filters)
Returns Expense resources that match the given lookup parameters.
- Parameters:
project_id (int or string) – (optional). Id or identifier of expenses’s project.
assigned_to_id (int) – (optional). Get expenses which are assigned to this user id.
status_id (int) – (optional). Get expenses which have this status id.
contact_id (int) – (optional). Get expenses for the given contact id.
author_id (int) – (optional). Get expenses created by given author id.
is_billable (bool) – (optional). Whether expense is billable.
currency (string) – (optional). Get expenses which have the given currency.
expense_date (string or date object) – (optional). Get expenses occurred on the given date.
search (string) – (optional). Get expenses with given search string.
limit (int) – (optional). How much resources to return.
offset (int) – (optional). Starting from what resource to return the other resources.
- Returns:
ResourceSet object
>>> expenses = redmine.expense.filter(project_id='invoices', assigned_to_id=123, status_id=3, search='EXP', is_billable=True)
>>> expenses
<redminelib.resultsets.ResourceSet object with Expense resources>
Hint
You can also get expenses from a Project, User, Contact and CrmQuery resource objects directly using
expenses
relation:
>>> project = redmine.project.get('invoices')
>>> project.expenses
<redminelib.resultsets.ResourceSet object with Expense resources>
Update methods¶
update¶
- redminelib.managers.ResourceManager.update(resource_id, **fields)
Updates values of given fields of an Expense resource and saves them to the Invoices plugin.
- Parameters:
resource_id (int) – (required). Expense id.
project_id (int or string) – (required). Id or identifier of expense’s project.
status_id (int) – (required). Expense status id:
1 - draft
2 - new
3 - billed
4 - paid
expense_date (string or date object) – (required). Date when expense occurred.
price (string) – (optional). Expense amount.
currency (string) – (optional). Expense currency.
contact_id (int) – (optional). Expense contact id.
assigned_to_id (int) – (optional). Expense will be assigned to this user id.
is_billable (bool) – (optional). Whether expense is billable.
linked_issue_id (int) – (optional). Issue id to be linked with this expense.
description (string) – (optional). Expense description.
uploads (list) – (optional). Uploads as [{'': ''}, ...], accepted keys are:
path (required). Absolute file path or file-like object that should be uploaded.
filename (optional). Name of the file after upload.
description (optional). Description of the file.
content_type (optional). Content type of the file.
- Returns:
True
>>> redmine.expense.update(
... 123,
... project_id='invoices',
... status_id=2,
... expense_date='2023-01-11',
... price='13.56',
... currency='USD',
... contact_id=3,
... assigned_to_id=12,
... is_billable=True,
... description='description',
... linked_issue_id=557,
... uploads=[{'path': '/absolute/path/to/file'}, {'path': BytesIO(b'I am content of file 2')}]
... )
True
save¶
- redminelib.resources.Expense.save(**attrs)
Saves the current state of an Expense resource to the Invoices plugin. Attrs that can be changed are the same as for
update()
method above.- Returns:
Resource object
>>> expense = redmine.expense.get(123)
>>> expense.project_id = 'invoices'
>>> expense.status_id = 2
>>> expense.expense_date = '2023-01-11'
>>> expense.price = '13.56'
>>> expense.currency = 'USD'
>>> expense.contact_id = 3
>>> expense.assigned_to_id = 12
>>> expense.is_billable = True
>>> expense.description = 'description'
>>> expense.linked_issue_id = 557
>>> expense.uploads = [{'path': '/absolute/path/to/file'}, {'path': BytesIO(b'I am content of file 2')}]
>>> expense.save()
<redminelib.resources.Expense #123>
Added in version 2.1.0: Alternative syntax was introduced.
>>> expense = redmine.expense.get(123).save(
... project_id='invoices',
... status_id=2,
... expense_date='2023-01-11',
... price='13.56',
... currency='USD',
... contact_id=3,
... assigned_to_id=12,
... is_billable=True,
... description='description',
... linked_issue_id=557,
... uploads=[{'path': '/absolute/path/to/file'}, {'path': BytesIO(b'I am content of file 2')}]
... )
>>> expense
<redminelib.resources.Expense #123>
Delete methods¶
delete¶
- redminelib.managers.ResourceManager.delete(resource_id)
Deletes single Expense resource from the Invoices plugin by its id.
- Parameters:
resource_id (int) – (required). Expense id.
- Returns:
True
>>> redmine.expense.delete(123)
True
- redminelib.resources.Expense.delete()
Deletes current Expense resource object from the Invoices plugin.
- Returns:
True
>>> expense = redmine.expense.get(1)
>>> expense.delete()
True
Export¶
Added in version 2.0.0.
- redminelib.resultsets.ResourceSet.export(fmt, savepath=None, filename=None)
Exports a resource set of Expense resources in one of the following formats: 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.
- Returns:
String or Object
>>> expenses = redmine.expense.all()
>>> expenses.export('csv', savepath='/home/jsmith', filename='expenses.csv')
'/home/jsmith/expenses.csv'