Skip to content

Commit e071bda

Browse files
Merge pull request #68 from JaviCerveraIngram/CPS-44-product
Cps 44 Product Configuration params, templates and other updates
2 parents 7fab284 + f07095d commit e071bda

30 files changed

+469
-29
lines changed

connect/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self, api_url=None, api_key=None, products=None, file=None):
5959
self._api_key = api_key
6060
self._api_url = api_url if api_url.endswith('/') else api_url + '/'
6161
self._products = [products] \
62-
if isinstance(products, str) \
62+
if isinstance(products, str) and products \
6363
else products or []
6464

6565
# Store first created instance

connect/logger/logger.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import json
88
import logging
99
import os
10+
1011
from logging.config import dictConfig
11-
from connect.models import BaseModel, Fulfillment
12+
from connect.models.base import BaseModel
1213

1314
with open(os.path.join(os.path.dirname(__file__), 'config.json')) as config_file:
1415
config = json.load(config_file)
@@ -23,7 +24,7 @@ def log_request_data(args):
2324
base = " %(levelname)-6s; %(asctime)s; %(name)-6s; %(module)s:%(funcName)s:line"\
2425
"-%(lineno)d: %(message)s"
2526
sformat = args[0].id + base
26-
if isinstance(args[0], Fulfillment):
27+
if hasattr(args[0], 'asset') and hasattr(args[0].asset, 'id'):
2728
sformat = args[0].asset.id + " " + sformat
2829
[handler.setFormatter(logging.Formatter(sformat, "%I:%M:%S"))
2930
for handler in logger.handlers]

connect/models/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .contact import Contact
1818
from .contact_info import ContactInfo
1919
from .contract import Contract
20+
from .country import Country
2021
from .conversation import Conversation
2122
from .conversation_message import ConversationMessage
2223
from .customer_ui_settings import CustomerUiSettings
@@ -36,6 +37,7 @@
3637
from .product import Product
3738
from .product_category import ProductCategory
3839
from .product_configuration import ProductConfiguration
40+
from .product_configuration_parameter import ProductConfigurationParameter
3941
from .product_family import ProductFamily
4042
from .product_stats import ProductStats
4143
from .product_stats_info import ProductStatsInfo
@@ -68,6 +70,7 @@
6870
'Contact',
6971
'ContactInfo',
7072
'Contract',
73+
'Country',
7174
'Conversation',
7275
'ConversationMessage',
7376
'CustomerUiSettings',
@@ -87,6 +90,7 @@
8790
'Product',
8891
'ProductCategory',
8992
'ProductConfiguration',
93+
'ProductConfigurationParameter',
9094
'ProductFamily',
9195
'ProductStats',
9296
'ProductStatsInfo',

connect/models/agreement.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,8 @@ class Agreement(BaseModel):
7474
""" (:py:class:`.Marketplace` | None) Reference to marketplace object
7575
(for distribution agreement).
7676
"""
77+
78+
# Undocumented fields (they appear in PHP SDK)
79+
80+
name = None # type: str
81+
""" (str) Name of Agreement. """

connect/models/asset.py

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
from typing import List, Optional
77

88
from .base import BaseModel
9+
from .configuration import Configuration
910
from .connection import Connection
11+
from .contract import Contract
1012
from .item import Item
13+
from .marketplace import Marketplace
1114
from .param import Param
1215
from .product import Product
1316
from .tier_accounts import TierAccounts
@@ -58,32 +61,57 @@ class Asset(BaseModel):
5861
""" (str) Identification for asset object on eCommerce. """
5962

6063
external_uid = None # type: Optional[str]
61-
""" (str|None) Id of asset in eCommerce system """
64+
""" (str|None) Id of asset in eCommerce system. """
65+
66+
external_name = None # type: Optional[str]
67+
""" (str|None) Name of asset. """
6268

6369
product = None # type: Product
6470
""" (:py:class:`.Product`) Product object reference. """
6571

6672
connection = None # type: Connection
6773
""" (:py:class:`.Connection`) Connection object. """
6874

69-
items = None # type: List[Item]
70-
""" (List[:py:class:`.Item`]) List of asset product items. """
75+
contract = None # type: Contract
76+
""" (:py:class:`.Contract`) Contract Object reference. """
77+
78+
marketplace = None # type: Marketplace
79+
""" (:py:class:`.Marketplace`) Marketplace Object reference. """
7180

7281
params = None # type: List[Param]
7382
""" (List[:py:class:`.Param`]) List of product parameter objects. """
7483

7584
tiers = None # type: TierAccounts
7685
""" (:py:class:`.TierAccounts`) Supply chain accounts. """
7786

78-
def get_param_by_id(self, id_):
87+
items = None # type: List[Item]
88+
""" (List[:py:class:`.Item`]) List of asset product items. """
89+
90+
configuration = None # type: Configuration
91+
""" (:py:class:`.Configuration`) List of Product and Marketplace Configuration Phase Parameter
92+
Context-Bound Object. """
93+
94+
def get_param_by_id(self, param_id):
7995
""" Get a parameter of the asset.
8096
81-
:param str id_: Id of the the parameter to get.
97+
:param str param_id: Id of the the parameter to get.
8298
:return: The parameter with the given id, or ``None`` if it was not found.
8399
:rtype: :py:class:`.Param` | None
84100
"""
85101
try:
86-
return list(filter(lambda param: param.id == id_, self.params))[0]
102+
return list(filter(lambda param: param.id == param_id, self.params))[0]
103+
except IndexError:
104+
return None
105+
106+
def get_item_by_id(self, item_id):
107+
""" Get an item of the asset.
108+
109+
:param str item_id: Id of the item to get.
110+
:return: The item with the given id, or ``None`` if it was not found.
111+
:rtype: :py:class:`.Item` | None
112+
"""
113+
try:
114+
return list(filter(lambda item: item.id == item_id, self.items))[0]
87115
except IndexError:
88116
return None
89117

@@ -98,3 +126,30 @@ def get_item_by_mpn(self, mpn):
98126
return list(filter(lambda item: item.mpn == mpn, self.items))[0]
99127
except IndexError:
100128
return None
129+
130+
def get_item_by_global_id(self, global_id):
131+
""" Get an item of the asset.
132+
133+
:param str global_id: Global id of the item to get.
134+
:return: The item with the given global id, or ``None`` if it was not found.
135+
:rtype: :py:class:`.Item` | None
136+
"""
137+
try:
138+
return list(filter(lambda item: item.global_id == global_id, self.items))[0]
139+
except IndexError:
140+
return None
141+
142+
def get_requests(self, config=None):
143+
""" Get the requests for this asset.
144+
145+
:param Config config: Config object or ``None`` to use environment config (default).
146+
:return: The requests for this asset.
147+
:rtype: List[Fulfillment]
148+
"""
149+
from connect.config import Config
150+
from connect.resources.base import ApiClient
151+
from .fulfillment import Fulfillment
152+
text, _ = ApiClient(
153+
config or Config.get_instance(),
154+
'assets/' + self.id + '/requests').get()
155+
return Fulfillment.deserialize(text)

connect/models/configuration.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,15 @@ class Configuration(BaseModel):
2525

2626
params = None # type: List[Param]
2727
""" (List[:py:class:`.Param`]) """
28+
29+
def get_param_by_id(self, param_id):
30+
""" Get a parameter of the configuration.
31+
32+
:param str param_id: Id of the the parameter to get.
33+
:return: The parameter with the given id, or ``None`` if it was not found.
34+
:rtype: :py:class:`.Param` | None
35+
"""
36+
try:
37+
return list(filter(lambda param: param.id == param_id, self.params))[0]
38+
except IndexError:
39+
return None

connect/models/contact_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ContactInfo(BaseModel):
2424
country = None # type: str
2525
""" (str) Country code. """
2626

27-
state = None # type: str
27+
state = None # type: Optional[str]
2828
""" (str) State name. """
2929

3030
city = None # type: str

connect/models/country.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# This file is part of the Ingram Micro Cloud Blue Connect SDK.
4+
# Copyright (c) 2019 Ingram Micro. All Rights Reserved.
5+
6+
from .base import BaseModel
7+
from .schemas import CountrySchema
8+
9+
10+
class Country(BaseModel):
11+
""" An instance of a hub. """
12+
13+
_schema = CountrySchema()
14+
15+
name = None # type: str
16+
""" (str) Country name """
17+
18+
icon = None # type: str
19+
""" (str) Icon path. """
20+
21+
zone = None # type: str
22+
""" (str) Geographical zone. """

connect/models/fulfillment.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .contract import Contract
1111
from .conversation import Conversation
1212
from .marketplace import Marketplace
13+
from .user import User
1314
from .schemas import FulfillmentSchema
1415

1516

@@ -72,6 +73,9 @@ class Fulfillment(BaseModel):
7273
marketplace = None # type: Marketplace
7374
""" (:py:class:`.Marketplace`) Marketplace object. """
7475

76+
assignee = None # type: User
77+
""" (:py:class:`.User`) Details of the user assigned to the request. """
78+
7579
@property
7680
def new_items(self):
7781
"""

connect/models/item.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,15 @@ class Item(BaseModel):
5454

5555
name = None # type: str
5656
""" (str) Name. """
57+
58+
def get_param_by_id(self, param_id):
59+
""" Get a parameter of the item.
60+
61+
:param str param_id: Id of the the parameter to get.
62+
:return: The parameter with the given id, or ``None`` if it was not found.
63+
:rtype: :py:class:`.Param` | None
64+
"""
65+
try:
66+
return list(filter(lambda param: param.id == param_id, self.params))[0]
67+
except IndexError:
68+
return None

0 commit comments

Comments
 (0)