-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add scripts for adding custom fields to returnitem and transact…
…ion (#281)
- Loading branch information
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
commerce_coordinator/apps/commercetools/management/commands/create_returnitem_custom_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import json | ||
|
||
from commercetools import CommercetoolsError | ||
|
||
from commerce_coordinator.apps.commercetools.catalog_info.foundational_types import TwoUCustomTypes | ||
from commerce_coordinator.apps.commercetools.management.commands._ct_api_client_command import ( | ||
CommercetoolsAPIClientCommand | ||
) | ||
|
||
|
||
class Command(CommercetoolsAPIClientCommand): | ||
help = 'Create a custom type for returnItem with field transactionId' | ||
|
||
def handle(self, *args, **options): | ||
current_draft = TwoUCustomTypes.RETURN_ITEM_TYPE_DRAFT | ||
type_key = current_draft.key | ||
|
||
try: | ||
ret = self.ct_api_client.base_client.types.get_by_key(type_key) | ||
print(f"ReturnItem custom type with field transactionId already exists: {json.dumps(ret.serialize())}") | ||
except CommercetoolsError as ex: | ||
ret = self.ct_api_client.base_client.types.create( | ||
TwoUCustomTypes.RETURN_ITEM_TYPE_DRAFT | ||
) | ||
print(f"Created ReturnItem custom type with field transactionId: {json.dumps(ret.serialize())}") |
25 changes: 25 additions & 0 deletions
25
...erce_coordinator/apps/commercetools/management/commands/create_transaction_custom_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import json | ||
|
||
from commercetools import CommercetoolsError | ||
|
||
from commerce_coordinator.apps.commercetools.catalog_info.foundational_types import TwoUCustomTypes | ||
from commerce_coordinator.apps.commercetools.management.commands._ct_api_client_command import ( | ||
CommercetoolsAPIClientCommand | ||
) | ||
|
||
|
||
class Command(CommercetoolsAPIClientCommand): | ||
help = 'Create a custom type for transactions with field returnItemId' | ||
|
||
def handle(self, *args, **options): | ||
current_draft = TwoUCustomTypes.TRANSACTION_TYPE_DRAFT | ||
type_key = current_draft.key | ||
|
||
try: | ||
ret = self.ct_api_client.base_client.types.get_by_key(type_key) | ||
print(f"Transaction custom type with field returnItemId already exists: {json.dumps(ret.serialize())}") | ||
except CommercetoolsError as ex: | ||
ret = self.ct_api_client.base_client.types.create( | ||
TwoUCustomTypes.TRANSACTION_TYPE_DRAFT | ||
) | ||
print(f"Created Transaction custom type with field returnItemId: {json.dumps(ret.serialize())}") |