Product

Added in version 2.5.0.

Requires Pro Edition and Products plugin >= 2.1.5.

Manager

All operations on the Product resource are provided by its manager. To get access to it you have to call redmine.product 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 Product resource with given fields and saves it to the Products plugin.

Parameters:
  • name (string) – (required). Product name.

  • project_id (int or string) – (required). Id or identifier of product’s project.

  • status_id (int) – (optional). Product status id:

    • 1 - active

    • 2 - inactive

  • code (string) – (optional). Product code.

  • price (string) – (optional). Product price.

  • currency (string) – (optional). Product currency.

  • category_id (int) – (optional). Product category id.

  • description (string) – (optional). Product description.

  • tag_list (list) – (optional). List of tags.

  • custom_fields (list) – (optional). Custom fields as [{‘id’: 1, ‘value’: ‘foo’}].

  • image (dict) – (optional). Image to be used for the product as dict, accepted keys are:

    • path (required). Absolute file path or file-like object that should be uploaded.

    • filename (optional). Required if a file-like object is provided.

  • 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

>>> product = redmine.product.create(
...     project_id='products',
...     name='foobar',
...     status_id=2,
...     code='P-001',
...     price='9.99',
...     currency='USD',
...     category_id=8,
...     description='product description',
...     tag_list=['foo', 'bar'],
...     custom_fields=[{'id': 1, 'value': '11'}],
...     image={'path': '/absolute/path/to/file.jpg'},
...     uploads=[{'path': '/absolute/path/to/file'}, {'path': BytesIO(b'I am content of file 2')}]
... )
>>> product
<redminelib.resources.Product #123>

new

redminelib.managers.ResourceManager.new()

Creates new empty Product resource, but saves it to the Products plugin 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

>>> product = redmine.product.new()
>>> product.project_id = 'products'
>>> product.name = 'foobar'
>>> product.status_id = 2
>>> product.code = 'P-001'
>>> product.price = '9.99'
>>> product.currency = 'USD'
>>> product.category_id = 8
>>> product.description = 'product description'
>>> product.tag_list = ['foo', 'bar']
>>> product.custom_fields = [{'id': 1, 'value': '11'}]
>>> product.image = {'path': '/absolute/path/to/file.jpg'}
>>> product.uploads = [{'path': '/absolute/path/to/file'}, {'path': BytesIO(b'I am content of file 2')}]
>>> product.save()
<redminelib.resources.Product #123>

Read methods

get

redminelib.managers.ResourceManager.get(resource_id, **params)

Returns single Product resource from the Products plugin by its id.

Parameters:
  • resource_id (int) – (required). Id of the product.

  • include (list) – (optional). Fetches associated data in one call. Accepted values:

    • attachments

Returns:

Resource object

>>> product = redmine.product.get(123, include=['attachments'])
>>> product
<redminelib.resources.Product #123>

Hint

Product resource object provides you with on demand includes. On demand includes are the other resource objects wrapped in a ResourceSet which are associated with a Product resource object. Keep in mind that on demand includes are retrieved in a separate request, that means that if the speed is important it is recommended to use get() method with include keyword argument. On demand includes provided by the Product resource object are the same as in the get() method above:

>>> product = redmine.product.get(123)
>>> product.attachments
<redminelib.resultsets.ResourceSet object with Attachment resources>

all

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

Returns all Product resources from the Products 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

>>> products = redmine.product.all(limit=50)
>>> products
<redminelib.resultsets.ResourceSet object with Product resources>

filter

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

Returns Product resources that match the given lookup parameters.

Parameters:
  • project_id (int or string) – (optional). Get products for the given project id.

  • author_id (int) – (optional). Get products created by given author id.

  • status_id (int) – (optional). Get products for the given status id:

    • 1 - active

    • 2 - inactive

  • category_id (int) – (optional). Get products for the given category id.

  • code (string) – (optional). Get products for the given code.

  • name (string) – (optional). Get products for the given name.

  • price (string) – (optional). Get products for the given price.

  • sort (string) – (optional). Column to sort, append :desc to invert the order:

    • code

    • name

    • created_at

    • updated_at

  • search (string) – (optional). Get products for the 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

>>> products = redmine.product.filter(project_id='products', author_id=123, status_id=1, search='prod', sort='created_at:desc')
>>> products
<redminelib.resultsets.ResourceSet object with Product resources>

Hint

You can also get products from a Project, User and CrmQuery resource objects directly using products relation:

>>> project = redmine.project.get('products')
>>> project.products
<redminelib.resultsets.ResourceSet object with Product resources>

Update methods

update

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

Updates values of given fields of a Product resource and saves them to the Products plugin.

Parameters:
  • resource_id (int) – (required). Product id.

  • name (string) – (optional). Product name.

  • project_id (int or string) – (optional). Id or identifier of product’s project.

  • status_id (int) – (optional). Product status id:

    • 1 - active

    • 2 - inactive

  • code (string) – (optional). Product code.

  • price (string) – (optional). Product price.

  • currency (string) – (optional). Product currency.

  • category_id (int) – (optional). Product category id.

  • description (string) – (optional). Product description.

  • tag_list (list) – (optional). List of tags.

  • custom_fields (list) – (optional). Custom fields as [{‘id’: 1, ‘value’: ‘foo’}].

  • image (dict) – (optional). Image to be used for the product as dict, accepted keys are:

    • path (required). Absolute file path or file-like object that should be uploaded.

    • filename (optional). Required if a file-like object is provided.

  • 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.product.update(
...     123,
...     project_id='products',
...     name='foobar',
...     status_id=2,
...     code='P-001',
...     price='9.99',
...     currency='USD',
...     category_id=8,
...     description='product description',
...     tag_list=['foo', 'bar'],
...     custom_fields=[{'id': 1, 'value': '11'}],
...     image={'path': '/absolute/path/to/file.jpg'},
...     uploads=[{'path': '/absolute/path/to/file'}, {'path': BytesIO(b'I am content of file 2')}]
... )
True

save

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

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

Returns:

Resource object

>>> product = redmine.product.get(123)
>>> product.project_id = 'products'
>>> product.name = 'foobar'
>>> product.status_id = 2
>>> product.code = 'P-001'
>>> product.price = '9.99'
>>> product.currency = 'USD'
>>> product.category_id = 8
>>> product.description = 'product description'
>>> product.tag_list = ['foo', 'bar']
>>> product.custom_fields = [{'id': 1, 'value': '11'}]
>>> product.image = {'path': '/absolute/path/to/file.jpg'}
>>> product.uploads = [{'path': '/absolute/path/to/file'}, {'path': BytesIO(b'I am content of file 2')}]
>>> product.save()
<redminelib.resources.Product #123>

Added in version 2.1.0: Alternative syntax was introduced.

>>> product = redmine.product.get(123).save(
...     project_id='products',
...     name='foobar',
...     status_id=2,
...     code='P-001',
...     price='9.99',
...     currency='USD',
...     category_id=8,
...     description='product description',
...     tag_list=['foo', 'bar'],
...     custom_fields=[{'id': 1, 'value': '11'}],
...     image={'path': '/absolute/path/to/file.jpg'},
...     uploads=[{'path': '/absolute/path/to/file'}, {'path': BytesIO(b'I am content of file 2')}]
... )
>>> product
<redminelib.resources.Product #123>

Delete methods

delete

redminelib.managers.ResourceManager.delete(resource_id)

Deletes single Product resource from the Products plugin by its id.

Parameters:

resource_id (int) – (required). Product id.

Returns:

True

>>> redmine.product.delete(123)
True
redminelib.resources.Product.delete()

Deletes current Product resource object from the Products plugin.

Returns:

True

>>> product = redmine.product.get(1)
>>> product.delete()
True

Export

redminelib.resultsets.ResourceSet.export(fmt, savepath=None, filename=None)

Exports a resource set of Product 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

>>> products = redmine.product.all()
>>> products.export('csv', savepath='/home/jsmith', filename='products.csv')
'/home/jsmith/products.csv'