Skip to content

Commit 300432d

Browse files
Muhammad Noyan  AzizMuhammad Noyan  Aziz
authored andcommitted
feat: add custom type scripts for returnitem and transaction
1 parent 881cda1 commit 300432d

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

commerce_coordinator/apps/commercetools/catalog_info/constants.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ class TwoUKeys:
1616
FAILURE_FULFILMENT_STATE = '2u-fulfillment-failure-state'
1717

1818

19+
# Return Item Types
20+
RETURN_ITEM_CUSTOM_TYPE = 'returnItemCustomType'
21+
22+
# Return Item Custom Fields
23+
TRANSACTION_ID = 'transactionId'
24+
25+
# Transaction Types
26+
TRANSACTION_CUSTOM_TYPE = 'transactionCustomType'
27+
28+
# Transaction Custom Fields
29+
RETURN_ITEM_ID = 'returnItemId'
30+
31+
1932
class EdXFieldNames:
2033
"""edX Specific field names for use in Commercetools"""
2134

commerce_coordinator/apps/commercetools/catalog_info/foundational_types.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,49 @@ class TwoUCustomTypes:
116116
)
117117
]
118118
)
119+
120+
RETURN_ITEM_TYPE_DRAFT = TypeDraft(
121+
key=TwoUKeys.RETURN_ITEM_CUSTOM_TYPE,
122+
name=ls({'en': 'Return Item Custom Type'}),
123+
resource_type_ids=[ResourceTypeId.ORDER_RETURN_ITEM],
124+
# ^^^ this cannot be updated, the whole type has to be unassigned, removed and replaced.
125+
field_definitions=[
126+
# Updating Field Definitions only supports:
127+
# - basic field definitions changes, like label and input_hint, not type or
128+
# - whether it is required or not.
129+
# - It can add new ones.
130+
# If you need something done that can't be, the whole type has to be unassigned, removed and replaced.
131+
132+
FieldDefinition(
133+
type=CustomFieldStringType(),
134+
name=TwoUKeys.TRANSACTION_ID,
135+
required=False,
136+
label=ls({'en': 'Transaction ID'}),
137+
input_hint=TypeTextInputHint.SINGLE_LINE
138+
)
139+
]
140+
)
141+
142+
TRANSACTION_TYPE_DRAFT = TypeDraft(
143+
key=TwoUKeys.TRANSACTION_CUSTOM_TYPE,
144+
name=ls({'en': 'Transaction Custom Type'}),
145+
resource_type_ids=[ResourceTypeId.TRANSACTION],
146+
# ^^^ this cannot be updated, the whole type has to be unassigned, removed and replaced.
147+
field_definitions=[
148+
# Updating Field Definitions only supports:
149+
# - basic field definitions changes, like label and input_hint, not type or
150+
# - whether it is required or not.
151+
# - It can add new ones.
152+
# If you need something done that can't be, the whole type has to be unassigned, removed and replaced.
153+
154+
FieldDefinition(
155+
type=CustomFieldStringType(),
156+
name=TwoUKeys.RETURN_ITEM_ID,
157+
required=False,
158+
label=ls({'en': 'Return Item ID'}),
159+
input_hint=TypeTextInputHint.SINGLE_LINE
160+
)
161+
]
162+
)
163+
119164
"""2U Cross System User Information for Customer Objects"""
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json
2+
3+
from commercetools import CommercetoolsError
4+
from commerce_coordinator.apps.commercetools.catalog_info.foundational_types import TwoUCustomTypes
5+
from commerce_coordinator.apps.commercetools.management.commands._ct_api_client_command import (
6+
CommercetoolsAPIClientCommand
7+
)
8+
9+
class Command(CommercetoolsAPIClientCommand):
10+
help = 'Create a custom type for returnItem with field transactionId'
11+
12+
def handle(self, *args, **options):
13+
current_draft = TwoUCustomTypes.RETURN_ITEM_TYPE_DRAFT
14+
type_key = current_draft.key
15+
16+
try:
17+
ret = self.ct_api_client.base_client.types.get_by_key(type_key)
18+
print(f"ReturnItem custom type with field transactionId already exists: {json.dumps(ret.serialize())}")
19+
except CommercetoolsError as ex:
20+
ret = self.ct_api_client.base_client.types.create(
21+
TwoUCustomTypes.RETURN_ITEM_TYPE_DRAFT
22+
)
23+
print(f"Created ReturnItem custom type with field transactionId: {json.dumps(ret.serialize())}")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json
2+
3+
from commercetools import CommercetoolsError
4+
from commerce_coordinator.apps.commercetools.catalog_info.foundational_types import TwoUCustomTypes
5+
from commerce_coordinator.apps.commercetools.management.commands._ct_api_client_command import (
6+
CommercetoolsAPIClientCommand
7+
)
8+
9+
class Command(CommercetoolsAPIClientCommand):
10+
help = 'Create a custom type for transactions with field returnItemId'
11+
12+
def handle(self, *args, **options):
13+
current_draft = TwoUCustomTypes.TRANSACTION_TYPE_DRAFT
14+
type_key = current_draft.key
15+
16+
try:
17+
ret = self.ct_api_client.base_client.types.get_by_key(type_key)
18+
print(f"Transaction custom type with field returnItemId already exists: {json.dumps(ret.serialize())}")
19+
except CommercetoolsError as ex:
20+
ret = self.ct_api_client.base_client.types.create(
21+
TwoUCustomTypes.TRANSACTION_TYPE_DRAFT
22+
)
23+
print(f"Created Transaction custom type with field returnItemId: {json.dumps(ret.serialize())}")

0 commit comments

Comments
 (0)