Deal

Requires Pro Edition and CRM plugin >= 3.3.0.

Manager

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

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

  • name (string) – (required). Deal name.

  • contact_id (int) – (optional). Deal contact id.

  • price (int) – (optional). Deal price.

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

  • probability (int) – (optional). Deal probability.

  • due_date (string or date object) – (optional). Deal should be won by this date.

  • background (string) – (optional). Deal background.

  • status_id (int) – (optional). Deal status id.

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

  • assigned_to_id (int) – (optional). Deal will be assigned to this user id.

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

Returns:

Resource object

>>> deal = redmine.deal.create(
...     project_id='vacation',
...     name='FooBar',
...     contact_id=1,
...     price=1000,
...     currency='EUR',
...     probability=80,
...     due_date=datetime.date(2014, 12, 12),
...     background='some deal background',
...     status_id=1,
...     category_id=1,
...     assigned_to_id=12,
...     custom_fields=[{'id': 1, 'value': 'foo'}, {'id': 2, 'value': 'bar'}]
... )
>>> deal
<redminelib.resources.Deal #123>

new

redminelib.managers.ResourceManager.new()

Creates new empty Deal resource but saves it to the CRM 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

>>> deal = redmine.deal.new()
>>> deal.project_id = 'vacation'
>>> deal.name = 'FooBar'
>>> deal.contact_id = 1
>>> deal.price = 1000
>>> deal.currency = 'EUR'
>>> deal.probability = 80
>>> deal.due_date = datetime.date(2014, 12, 12)
>>> deal.background = 'some deal background'
>>> deal.status_id = 1
>>> deal.category_id = 1
>>> deal.assigned_to_id = 12
>>> deal.custom_fields = [{'id': 1, 'value': 'foo'}, {'id': 2, 'value': 'bar'}]
>>> deal.save()
<redminelib.resources.Deal #123>

Read methods

get

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

Returns single Deal resource from the CRM plugin by its id.

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

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

    • notes

Returns:

Resource object

>>> deal = redmine.deal.get(123, include=['notes'])
>>> deal
<redminelib.resources.Deal #123>

Hint

Deal 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 Deal 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 Deal resource object are the same as in the get() method above:

>>> deal = redmine.deal.get(123)
>>> deal.notes
<redminelib.resultsets.ResourceSet object with Note resources>

all

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

Returns all Deal resources from the CRM 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

>>> deals = redmine.deal.all(limit=50)
>>> deals
<redminelib.resultsets.ResourceSet object with Deal resources>

filter

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

Returns Deal resources that match the given lookup parameters.

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

  • assigned_to_id (int) – (optional). Get deals which are assigned to this user id.

  • query_id (int) – (optional). Get deals for the given query id.

  • status_id (int) – (optional). Get deals which have this status id.

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

>>> deals = redmine.deal.filter(project_id='vacation', assigned_to_id=123, status_id=1, search='Smith')
>>> deals
<redminelib.resultsets.ResourceSet object with Deal resources>

Hint

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

>>> project = redmine.project.get('vacation')
>>> project.deals
<redminelib.resultsets.ResourceSet object with Deal resources>

Update methods

update

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

Updates values of given fields of a Deal resource and saves them to the CRM plugin.

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

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

  • contact_id (int) – (optional). Deal contact id.

  • price (int) – (optional). Deal price.

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

  • probability (int) – (optional). Deal probability.

  • due_date (string or date object) – (optional). Deal should be won by this date.

  • background (string) – (optional). Deal background.

  • status_id (int) – (optional). Deal status id.

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

  • assigned_to_id (int) – (optional). Deal will be assigned to this user id.

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

Returns:

True

>>> redmine.deal.update(
...     123,
...     name='FooBar',
...     contact_id=1,
...     price=1000,
...     currency='EUR',
...     probability=80,
...     due_date=datetime.date(2014, 12, 12),
...     background='some deal background',
...     status_id=1,
...     category_id=1,
...     assigned_to_id=12,
...     custom_fields=[{'id': 1, 'value': 'foo'}, {'id': 2, 'value': 'bar'}]
... )
True

save

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

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

Returns:

Resource object

>>> deal = redmine.deal.get(123)
>>> deal.name = 'FooBar'
>>> deal.contact_id = 1
>>> deal.price = 1000
>>> deal.currency = 'EUR'
>>> deal.probability = 80
>>> deal.due_date = datetime.date(2014, 12, 12)
>>> deal.background = 'some deal background'
>>> deal.status_id = 1
>>> deal.category_id = 1
>>> deal.assigned_to_id = 12
>>> deal.custom_fields = [{'id': 1, 'value': 'foo'}, {'id': 2, 'value': 'bar'}]
>>> deal.save()
<redminelib.resources.Deal #123>

Added in version 2.1.0: Alternative syntax was introduced.

>>> deal = redmine.deal.get(123).save(
...     contact_id=1,
...     price=1000,
...     currency='EUR',
...     probability=80,
...     due_date=datetime.date(2014, 12, 12),
...     background='some deal background',
...     status_id=1,
...     category_id=1,
...     assigned_to_id=12,
...     custom_fields=[{'id': 1, 'value': 'foo'}, {'id': 2, 'value': 'bar'}]
... )
>>> deal
<redminelib.resources.Deal #123>

Delete methods

delete

redminelib.managers.ResourceManager.delete(resource_id)

Deletes single Deal resource from the CRM plugin by its id.

Parameters:

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

Returns:

True

>>> redmine.deal.delete(123)
True
redminelib.resources.Deal.delete()

Deletes current Deal resource object from the CRM plugin.

Returns:

True

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

Export

Added in version 2.0.0.

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

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

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