|
3 | 3 | # This file is part of the Ingram Micro Cloud Blue Connect SDK. |
4 | 4 | # Copyright (c) 2019-2020 Ingram Micro. All Rights Reserved. |
5 | 5 |
|
6 | | -import datetime |
7 | | -from typing import Union |
| 6 | +from deprecation import deprecated |
8 | 7 |
|
9 | | -from .asset import Asset |
10 | | -from .base import BaseModel |
11 | | -from .contract import Contract |
12 | | -from .conversation import Conversation |
13 | | -from .marketplace import Marketplace |
14 | | -from .user import User |
| 8 | +from .asset_request import AssetRequest |
15 | 9 | from .schemas import FulfillmentSchema |
16 | 10 |
|
17 | 11 |
|
18 | | -class Fulfillment(BaseModel): |
| 12 | +class Fulfillment(AssetRequest): |
19 | 13 | """ Represents a request for the :py:class:`connect.resource.FulfillmentAutomation` |
20 | 14 | resource. |
21 | 15 | """ |
22 | | - |
23 | 16 | _schema = FulfillmentSchema() |
24 | 17 |
|
25 | | - type = None # type: str |
26 | | - """ (str) Asset status. See :py:class:`.Asset` class for details. """ |
27 | | - |
28 | | - created = None # type: datetime.datetime |
29 | | - """ (datetime.datetime) Date of request creation. """ |
30 | | - |
31 | | - updated = None # type: datetime.datetime |
32 | | - """ (datetime.datetime) Date of last request modification. """ |
33 | | - |
34 | | - status = None # type: str |
35 | | - """ (str) Status of request. One of: |
36 | | -
|
37 | | - - pending |
38 | | - - inquiring |
39 | | - - failed |
40 | | - - approved |
41 | | -
|
42 | | - Valid status changes: |
43 | | -
|
44 | | - - pending -> inquiring |
45 | | - - pending -> failed |
46 | | - - pending -> approved |
47 | | - - inquiring -> failed |
48 | | - - inquiring -> approved |
49 | | - - inquiring -> pending |
50 | | - """ |
51 | | - |
52 | | - params_form_url = None # type: str |
53 | | - """ (str) URL for customer/reseller/provider for modifying param value |
54 | | - based on vendor's feedback. |
55 | | - """ |
56 | | - |
57 | | - activation_key = None # type: str |
58 | | - """ (str) Activation key content for activating the subscription on vendor portal. |
59 | | - This markdown formatted message is sent to customer. |
60 | | - """ |
61 | | - |
62 | | - reason = None # type: str |
63 | | - """ (str) Fail reason in case of status of request is failed. """ |
64 | | - |
65 | | - note = None # type: str |
66 | | - """ (str) Details of note. """ |
67 | | - |
68 | | - asset = None # type: Asset |
69 | | - """ (:py:class:`.Asset`) Asset object. """ |
70 | | - |
71 | | - contract = None # type: Contract |
72 | | - """ (:py:class:`.Contract`) Contract object. """ |
73 | | - |
74 | | - marketplace = None # type: Marketplace |
75 | | - """ (:py:class:`.Marketplace`) Marketplace object. """ |
76 | | - |
77 | | - assignee = None # type: Union[User, str, None] |
78 | | - """ (:py:class:`.User` | None) Details of the user assigned to the request. """ |
79 | | - |
80 | | - @property |
81 | | - def new_items(self): |
82 | | - """ |
83 | | - :return: New items. |
84 | | - :rtype: List[Item] |
85 | | - """ |
86 | | - return list(filter( |
87 | | - lambda item: item.quantity > 0 and item.old_quantity == 0, |
88 | | - self.asset.items)) |
89 | | - |
90 | | - @property |
91 | | - def changed_items(self): |
92 | | - """ |
93 | | - :return: Changed items. |
94 | | - :rtype: List[Item] |
95 | | - """ |
96 | | - return list(filter( |
97 | | - lambda item: item.quantity > 0 and item.old_quantity > 0, |
98 | | - self.asset.items)) |
99 | | - |
100 | | - @property |
101 | | - def removed_items(self): |
102 | | - """ |
103 | | - :return: Removed items. |
104 | | - :rtype: List[Item] |
105 | | - """ |
106 | | - return list(filter( |
107 | | - lambda item: item.quantity == 0 and item.old_quantity > 0, |
108 | | - self.asset.items)) |
109 | | - |
110 | | - def needs_migration(self, migration_key='migration_info'): |
111 | | - """ |
112 | | - Indicates whether the request contains data to be migrated from a legacy product. |
113 | | - Migration is performed by an external service. All you have to do for a request that |
114 | | - needs migration is to skip processing by raising a |
115 | | - :py:class:`connect.exceptions.SkipRequest` exception. |
116 | | -
|
117 | | - :param str migration_key: The name of the parameter that contains the migration data |
118 | | - (optional; default value is ``migration_info``). |
119 | | - :return: Whether the request needs migrating. |
120 | | - :rtype: bool |
121 | | - """ |
122 | | - param = self.asset.get_param_by_id(migration_key) |
123 | | - return param is not None and bool(param.value) |
124 | | - |
125 | | - def get_conversation(self, config=None): |
126 | | - """ |
127 | | - :param Config config: Configuration, or ``None`` to use the environment config (default). |
128 | | - :return: The conversation for this request, or ``None`` if there is none. |
129 | | - :rtype: Conversation|None |
130 | | - """ |
131 | | - from connect.resources.base import ApiClient |
132 | | - |
133 | | - client = ApiClient(config, base_path='conversations') |
134 | | - response, _ = client.get(params={'instance_id': self.id}) |
135 | | - try: |
136 | | - conversations = Conversation.deserialize(response) |
137 | | - if conversations and conversations[0].id: |
138 | | - response, _ = client.get(conversations[0].id) |
139 | | - return Conversation.deserialize(response) |
140 | | - else: |
141 | | - return None |
142 | | - except ValueError: |
143 | | - return None |
| 18 | + @deprecated(deprecated_in='19.2', |
| 19 | + details='Use `connect.models.AssetRequest` instead.') |
| 20 | + def __init__(self, *args, **kwargs): |
| 21 | + super(Fulfillment, self).__init__(*args, **kwargs) |
0 commit comments