Esempio n. 1
0
class CustomLineItemTaxedPriceSchema(helpers.BaseSchema):
    total_net = helpers.Discriminator(
        allow_none=True,
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "highPrecision":
            helpers.absmod(__name__, ".common.HighPrecisionMoneySchema"),
            "centPrecision":
            helpers.absmod(__name__, ".common.MoneySchema"),
        },
        missing=None,
        data_key="totalNet",
    )
    total_gross = helpers.Discriminator(
        allow_none=True,
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "highPrecision":
            helpers.absmod(__name__, ".common.HighPrecisionMoneySchema"),
            "centPrecision":
            helpers.absmod(__name__, ".common.MoneySchema"),
        },
        missing=None,
        data_key="totalGross",
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):

        return models.CustomLineItemTaxedPrice(**data)
class CartDiscountDraftSchema(marshmallow.Schema):
    "Marshmallow schema for :class:`commercetools.types.CartDiscountDraft`."
    name = LocalizedStringField(allow_none=True)
    key = marshmallow.fields.String(allow_none=True, missing=None)
    description = LocalizedStringField(allow_none=True, missing=None)
    value = helpers.Discriminator(
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "absolute": "commercetools.schemas._cart_discount.CartDiscountValueAbsoluteSchema",
            "giftLineItem": "commercetools.schemas._cart_discount.CartDiscountValueGiftLineItemSchema",
            "relative": "commercetools.schemas._cart_discount.CartDiscountValueRelativeSchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
    )
    cart_predicate = marshmallow.fields.String(
        allow_none=True, data_key="cartPredicate"
    )
    target = helpers.Discriminator(
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "customLineItems": "commercetools.schemas._cart_discount.CartDiscountCustomLineItemsTargetSchema",
            "lineItems": "commercetools.schemas._cart_discount.CartDiscountLineItemsTargetSchema",
            "shipping": "commercetools.schemas._cart_discount.CartDiscountShippingCostTargetSchema",
            "multiBuyCustomLineItems": "commercetools.schemas._cart_discount.MultiBuyCustomLineItemsTargetSchema",
            "multiBuyLineItems": "commercetools.schemas._cart_discount.MultiBuyLineItemsTargetSchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
        missing=None,
    )
    sort_order = marshmallow.fields.String(allow_none=True, data_key="sortOrder")
    is_active = marshmallow.fields.Bool(
        allow_none=True, missing=None, data_key="isActive"
    )
    valid_from = marshmallow.fields.DateTime(
        allow_none=True, missing=None, data_key="validFrom"
    )
    valid_until = marshmallow.fields.DateTime(
        allow_none=True, missing=None, data_key="validUntil"
    )
    requires_discount_code = marshmallow.fields.Bool(
        allow_none=True, data_key="requiresDiscountCode"
    )
    stacking_mode = marshmallow_enum.EnumField(
        types.StackingMode, by_value=True, missing=None, data_key="stackingMode"
    )
    custom = marshmallow.fields.Nested(
        nested="commercetools.schemas._type.CustomFieldsSchema",
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
        missing=None,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data):
        return types.CartDiscountDraft(**data)
class SubscriptionDraftSchema(helpers.BaseSchema):
    changes = helpers.LazyNestedField(
        nested=helpers.absmod(__name__, ".ChangeSubscriptionSchema"),
        allow_none=True,
        many=True,
        unknown=marshmallow.EXCLUDE,
        metadata={"omit_empty": True},
        missing=None,
    )
    destination = helpers.Discriminator(
        allow_none=True,
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "EventGrid":
            helpers.absmod(__name__, ".AzureEventGridDestinationSchema"),
            "AzureServiceBus":
            helpers.absmod(__name__, ".AzureServiceBusDestinationSchema"),
            "GoogleCloudPubSub":
            helpers.absmod(__name__, ".GoogleCloudPubSubDestinationSchema"),
            "IronMQ":
            helpers.absmod(__name__, ".IronMqDestinationSchema"),
            "SNS":
            helpers.absmod(__name__, ".SnsDestinationSchema"),
            "SQS":
            helpers.absmod(__name__, ".SqsDestinationSchema"),
        },
        missing=None,
    )
    key = marshmallow.fields.String(allow_none=True,
                                    metadata={"omit_empty": True},
                                    missing=None)
    messages = helpers.LazyNestedField(
        nested=helpers.absmod(__name__, ".MessageSubscriptionSchema"),
        allow_none=True,
        many=True,
        unknown=marshmallow.EXCLUDE,
        metadata={"omit_empty": True},
        missing=None,
    )
    format = helpers.Discriminator(
        allow_none=True,
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "CloudEvents":
            helpers.absmod(__name__, ".DeliveryCloudEventsFormatSchema"),
            "Platform":
            helpers.absmod(__name__, ".DeliveryPlatformFormatSchema"),
        },
        metadata={"omit_empty": True},
        missing=None,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):

        return models.SubscriptionDraft(**data)
class ShippingRateSchema(helpers.BaseSchema):
    price = helpers.Discriminator(
        allow_none=True,
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "centPrecision":
            helpers.absmod(__name__, ".common.CentPrecisionMoneySchema"),
            "highPrecision":
            helpers.absmod(__name__, ".common.HighPrecisionMoneySchema"),
        },
        missing=None,
    )
    free_above = helpers.Discriminator(
        allow_none=True,
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "centPrecision":
            helpers.absmod(__name__, ".common.CentPrecisionMoneySchema"),
            "highPrecision":
            helpers.absmod(__name__, ".common.HighPrecisionMoneySchema"),
        },
        metadata={"omit_empty": True},
        missing=None,
        data_key="freeAbove",
    )
    is_matching = marshmallow.fields.Boolean(
        allow_none=True,
        metadata={"omit_empty": True},
        missing=None,
        data_key="isMatching",
    )
    tiers = marshmallow.fields.List(
        helpers.Discriminator(
            allow_none=True,
            discriminator_field=("type", "type"),
            discriminator_schemas={
                "CartClassification":
                helpers.absmod(__name__, ".CartClassificationTierSchema"),
                "CartScore":
                helpers.absmod(__name__, ".CartScoreTierSchema"),
                "CartValue":
                helpers.absmod(__name__, ".CartValueTierSchema"),
            },
        ),
        allow_none=True,
        missing=None,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):

        return models.ShippingRate(**data)
Esempio n. 5
0
class SubscriptionDraftSchema(marshmallow.Schema):
    """Marshmallow schema for :class:`commercetools.types.SubscriptionDraft`."""

    changes = helpers.LazyNestedField(
        nested="commercetools._schemas._subscription.ChangeSubscriptionSchema",
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
        many=True,
        missing=None,
    )
    destination = helpers.Discriminator(
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "EventGrid":
            "commercetools._schemas._subscription.AzureEventGridDestinationSchema",
            "AzureServiceBus":
            "commercetools._schemas._subscription.AzureServiceBusDestinationSchema",
            "GoogleCloudPubSub":
            "commercetools._schemas._subscription.GoogleCloudPubSubDestinationSchema",
            "IronMQ":
            "commercetools._schemas._subscription.IronMqDestinationSchema",
            "SNS": "commercetools._schemas._subscription.SnsDestinationSchema",
            "SQS": "commercetools._schemas._subscription.SqsDestinationSchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
    )
    key = marshmallow.fields.String(allow_none=True, missing=None)
    messages = helpers.LazyNestedField(
        nested="commercetools._schemas._subscription.MessageSubscriptionSchema",
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
        many=True,
        missing=None,
    )
    format = helpers.Discriminator(
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "CloudEvents":
            "commercetools._schemas._subscription.DeliveryCloudEventsFormatSchema",
            "Platform":
            "commercetools._schemas._subscription.DeliveryPlatformFormatSchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
        missing=None,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.SubscriptionDraft(**data)
Esempio n. 6
0
class ShippingRateSchema(marshmallow.Schema):
    """Marshmallow schema for :class:`commercetools.types.ShippingRate`."""

    price = helpers.Discriminator(
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "centPrecision":
            "commercetools._schemas._common.CentPrecisionMoneySchema",
            "highPrecision":
            "commercetools._schemas._common.HighPrecisionMoneySchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
    )
    free_above = helpers.Discriminator(
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "centPrecision":
            "commercetools._schemas._common.CentPrecisionMoneySchema",
            "highPrecision":
            "commercetools._schemas._common.HighPrecisionMoneySchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
        missing=None,
        data_key="freeAbove",
    )
    is_matching = marshmallow.fields.Bool(allow_none=True,
                                          missing=None,
                                          data_key="isMatching")
    tiers = marshmallow.fields.List(
        helpers.Discriminator(
            discriminator_field=("type", "type"),
            discriminator_schemas={
                "CartClassification":
                "commercetools._schemas._shipping_method.CartClassificationTierSchema",
                "CartScore":
                "commercetools._schemas._shipping_method.CartScoreTierSchema",
                "CartValue":
                "commercetools._schemas._shipping_method.CartValueTierSchema",
            },
            unknown=marshmallow.EXCLUDE,
            allow_none=True,
        ))

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.ShippingRate(**data)
class FieldDefinitionSchema(marshmallow.Schema):
    """Marshmallow schema for :class:`commercetools.types.FieldDefinition`."""

    type = helpers.Discriminator(
        discriminator_field=("name", "name"),
        discriminator_schemas={
            "Boolean": "commercetools._schemas._type.CustomFieldBooleanTypeSchema",
            "DateTime": "commercetools._schemas._type.CustomFieldDateTimeTypeSchema",
            "Date": "commercetools._schemas._type.CustomFieldDateTypeSchema",
            "Enum": "commercetools._schemas._type.CustomFieldEnumTypeSchema",
            "LocalizedEnum": "commercetools._schemas._type.CustomFieldLocalizedEnumTypeSchema",
            "LocalizedString": "commercetools._schemas._type.CustomFieldLocalizedStringTypeSchema",
            "Money": "commercetools._schemas._type.CustomFieldMoneyTypeSchema",
            "Number": "commercetools._schemas._type.CustomFieldNumberTypeSchema",
            "Reference": "commercetools._schemas._type.CustomFieldReferenceTypeSchema",
            "Set": "commercetools._schemas._type.CustomFieldSetTypeSchema",
            "String": "commercetools._schemas._type.CustomFieldStringTypeSchema",
            "Time": "commercetools._schemas._type.CustomFieldTimeTypeSchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
    )
    name = marshmallow.fields.String(allow_none=True)
    label = LocalizedStringField(allow_none=True)
    required = marshmallow.fields.Bool(allow_none=True)
    input_hint = marshmallow_enum.EnumField(
        types.TypeTextInputHint, by_value=True, missing=None, data_key="inputHint"
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.FieldDefinition(**data)
class DiscountCodeUpdateSchema(marshmallow.Schema):
    "Marshmallow schema for :class:`commercetools.types.DiscountCodeUpdate`."
    version = marshmallow.fields.Integer(allow_none=True)
    actions = marshmallow.fields.List(
        helpers.Discriminator(
            discriminator_field=("action", "action"),
            discriminator_schemas={
                "changeCartDiscounts": "commercetools.schemas._discount_code.DiscountCodeChangeCartDiscountsActionSchema",
                "changeGroups": "commercetools.schemas._discount_code.DiscountCodeChangeGroupsActionSchema",
                "changeIsActive": "commercetools.schemas._discount_code.DiscountCodeChangeIsActiveActionSchema",
                "setCartPredicate": "commercetools.schemas._discount_code.DiscountCodeSetCartPredicateActionSchema",
                "setCustomField": "commercetools.schemas._discount_code.DiscountCodeSetCustomFieldActionSchema",
                "setCustomType": "commercetools.schemas._discount_code.DiscountCodeSetCustomTypeActionSchema",
                "setDescription": "commercetools.schemas._discount_code.DiscountCodeSetDescriptionActionSchema",
                "setMaxApplications": "commercetools.schemas._discount_code.DiscountCodeSetMaxApplicationsActionSchema",
                "setMaxApplicationsPerCustomer": "commercetools.schemas._discount_code.DiscountCodeSetMaxApplicationsPerCustomerActionSchema",
                "setName": "commercetools.schemas._discount_code.DiscountCodeSetNameActionSchema",
                "setValidFrom": "commercetools.schemas._discount_code.DiscountCodeSetValidFromActionSchema",
                "setValidFromAndUntil": "commercetools.schemas._discount_code.DiscountCodeSetValidFromAndUntilActionSchema",
                "setValidUntil": "commercetools.schemas._discount_code.DiscountCodeSetValidUntilActionSchema",
            },
            unknown=marshmallow.EXCLUDE,
            allow_none=True,
        ),
        allow_none=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data):
        return types.DiscountCodeUpdate(**data)
Esempio n. 9
0
class CartDiscountChangeTargetActionSchema(CartDiscountUpdateActionSchema):
    """Marshmallow schema for :class:`commercetools.types.CartDiscountChangeTargetAction`."""

    target = helpers.Discriminator(
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "customLineItems":
            "commercetools._schemas._cart_discount.CartDiscountCustomLineItemsTargetSchema",
            "lineItems":
            "commercetools._schemas._cart_discount.CartDiscountLineItemsTargetSchema",
            "shipping":
            "commercetools._schemas._cart_discount.CartDiscountShippingCostTargetSchema",
            "multiBuyCustomLineItems":
            "commercetools._schemas._cart_discount.MultiBuyCustomLineItemsTargetSchema",
            "multiBuyLineItems":
            "commercetools._schemas._cart_discount.MultiBuyLineItemsTargetSchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        del data["action"]
        return types.CartDiscountChangeTargetAction(**data)
class ProductDiscountChangeValueActionSchema(ProductDiscountUpdateActionSchema
                                             ):
    """Marshmallow schema for :class:`commercetools.types.ProductDiscountChangeValueAction`."""

    value = helpers.Discriminator(
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "absolute":
            "commercetools._schemas._product_discount.ProductDiscountValueAbsoluteDraftSchema",
            "external":
            "commercetools._schemas._product_discount.ProductDiscountValueExternalDraftSchema",
            "relative":
            "commercetools._schemas._product_discount.ProductDiscountValueRelativeDraftSchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        del data["action"]
        return types.ProductDiscountChangeValueAction(**data)
class InventoryEntryUpdateSchema(marshmallow.Schema):
    "Marshmallow schema for :class:`commercetools.types.InventoryEntryUpdate`."
    version = marshmallow.fields.Integer(allow_none=True)
    actions = marshmallow.fields.List(
        helpers.Discriminator(
            discriminator_field=("action", "action"),
            discriminator_schemas={
                "addQuantity": "commercetools.schemas._inventory.InventoryEntryAddQuantityActionSchema",
                "changeQuantity": "commercetools.schemas._inventory.InventoryEntryChangeQuantityActionSchema",
                "removeQuantity": "commercetools.schemas._inventory.InventoryEntryRemoveQuantityActionSchema",
                "setCustomField": "commercetools.schemas._inventory.InventoryEntrySetCustomFieldActionSchema",
                "setCustomType": "commercetools.schemas._inventory.InventoryEntrySetCustomTypeActionSchema",
                "setExpectedDelivery": "commercetools.schemas._inventory.InventoryEntrySetExpectedDeliveryActionSchema",
                "setRestockableInDays": "commercetools.schemas._inventory.InventoryEntrySetRestockableInDaysActionSchema",
                "setSupplyChannel": "commercetools.schemas._inventory.InventoryEntrySetSupplyChannelActionSchema",
            },
            unknown=marshmallow.EXCLUDE,
            allow_none=True,
        ),
        allow_none=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.InventoryEntryUpdate(**data)
Esempio n. 12
0
class ReviewUpdateSchema(marshmallow.Schema):
    "Marshmallow schema for :class:`commercetools.types.ReviewUpdate`."
    version = marshmallow.fields.Integer(allow_none=True)
    actions = marshmallow.fields.List(
        helpers.Discriminator(
            discriminator_field=("action", "action"),
            discriminator_schemas={
                "setAuthorName": "commercetools.schemas._review.ReviewSetAuthorNameActionSchema",
                "setCustomField": "commercetools.schemas._review.ReviewSetCustomFieldActionSchema",
                "setCustomType": "commercetools.schemas._review.ReviewSetCustomTypeActionSchema",
                "setCustomer": "commercetools.schemas._review.ReviewSetCustomerActionSchema",
                "setKey": "commercetools.schemas._review.ReviewSetKeyActionSchema",
                "setLocale": "commercetools.schemas._review.ReviewSetLocaleActionSchema",
                "setRating": "commercetools.schemas._review.ReviewSetRatingActionSchema",
                "setTarget": "commercetools.schemas._review.ReviewSetTargetActionSchema",
                "setText": "commercetools.schemas._review.ReviewSetTextActionSchema",
                "setTitle": "commercetools.schemas._review.ReviewSetTitleActionSchema",
                "transitionState": "commercetools.schemas._review.ReviewTransitionStateActionSchema",
            },
            unknown=marshmallow.EXCLUDE,
            allow_none=True,
        ),
        allow_none=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data):
        return types.ReviewUpdate(**data)
Esempio n. 13
0
class TaxCategoryUpdateSchema(marshmallow.Schema):
    "Marshmallow schema for :class:`commercetools.types.TaxCategoryUpdate`."
    version = marshmallow.fields.Integer(allow_none=True)
    actions = marshmallow.fields.List(
        helpers.Discriminator(
            discriminator_field=("action", "action"),
            discriminator_schemas={
                "addTaxRate":
                "commercetools.schemas._tax_category.TaxCategoryAddTaxRateActionSchema",
                "changeName":
                "commercetools.schemas._tax_category.TaxCategoryChangeNameActionSchema",
                "removeTaxRate":
                "commercetools.schemas._tax_category.TaxCategoryRemoveTaxRateActionSchema",
                "replaceTaxRate":
                "commercetools.schemas._tax_category.TaxCategoryReplaceTaxRateActionSchema",
                "setDescription":
                "commercetools.schemas._tax_category.TaxCategorySetDescriptionActionSchema",
                "setKey":
                "commercetools.schemas._tax_category.TaxCategorySetKeyActionSchema",
            },
            unknown=marshmallow.EXCLUDE,
            allow_none=True,
        ),
        allow_none=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.TaxCategoryUpdate(**data)
class ExtensionUpdateSchema(marshmallow.Schema):
    "Marshmallow schema for :class:`commercetools.types.ExtensionUpdate`."
    version = marshmallow.fields.Integer(allow_none=True)
    actions = marshmallow.fields.List(
        helpers.Discriminator(
            discriminator_field=("action", "action"),
            discriminator_schemas={
                "changeDestination":
                "commercetools.schemas._extension.ExtensionChangeDestinationActionSchema",
                "changeTriggers":
                "commercetools.schemas._extension.ExtensionChangeTriggersActionSchema",
                "setKey":
                "commercetools.schemas._extension.ExtensionSetKeyActionSchema",
                "setTimeoutInMs":
                "commercetools.schemas._extension.ExtensionSetTimeoutInMsActionSchema",
            },
            unknown=marshmallow.EXCLUDE,
            allow_none=True,
        ),
        allow_none=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data):
        return types.ExtensionUpdate(**data)
Esempio n. 15
0
class CartDiscountChangeValueActionSchema(CartDiscountUpdateActionSchema):
    value = helpers.Discriminator(
        allow_none=True,
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "absolute": helpers.absmod(
                __name__, ".CartDiscountValueAbsoluteDraftSchema"
            ),
            "giftLineItem": helpers.absmod(
                __name__, ".CartDiscountValueGiftLineItemDraftSchema"
            ),
            "relative": helpers.absmod(
                __name__, ".CartDiscountValueRelativeDraftSchema"
            ),
        },
        missing=None,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        del data["action"]
        return models.CartDiscountChangeValueAction(**data)
Esempio n. 16
0
class CartDiscountChangeTargetActionSchema(CartDiscountUpdateActionSchema):
    target = helpers.Discriminator(
        allow_none=True,
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "customLineItems": helpers.absmod(
                __name__, ".CartDiscountCustomLineItemsTargetSchema"
            ),
            "lineItems": helpers.absmod(__name__, ".CartDiscountLineItemsTargetSchema"),
            "shipping": helpers.absmod(
                __name__, ".CartDiscountShippingCostTargetSchema"
            ),
            "multiBuyCustomLineItems": helpers.absmod(
                __name__, ".MultiBuyCustomLineItemsTargetSchema"
            ),
            "multiBuyLineItems": helpers.absmod(
                __name__, ".MultiBuyLineItemsTargetSchema"
            ),
        },
        missing=None,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        del data["action"]
        return models.CartDiscountChangeTargetAction(**data)
Esempio n. 17
0
class CartDiscountValueAbsoluteSchema(CartDiscountValueSchema):
    money = marshmallow.fields.List(
        helpers.Discriminator(
            allow_none=True,
            discriminator_field=("type", "type"),
            discriminator_schemas={
                "centPrecision": helpers.absmod(
                    __name__, ".common.CentPrecisionMoneySchema"
                ),
                "highPrecision": helpers.absmod(
                    __name__, ".common.HighPrecisionMoneySchema"
                ),
            },
        ),
        allow_none=True,
        missing=None,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        del data["type"]
        return models.CartDiscountValueAbsolute(**data)
Esempio n. 18
0
class TransactionSchema(marshmallow.Schema):
    "Marshmallow schema for :class:`commercetools.types.Transaction`."
    id = marshmallow.fields.String(allow_none=True)
    timestamp = marshmallow.fields.DateTime(allow_none=True, missing=None)
    type = marshmallow_enum.EnumField(types.TransactionType, by_value=True)
    amount = helpers.Discriminator(
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "centPrecision":
            "commercetools.schemas._common.CentPrecisionMoneySchema",
            "highPrecision":
            "commercetools.schemas._common.HighPrecisionMoneySchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
    )
    interaction_id = marshmallow.fields.String(allow_none=True,
                                               missing=None,
                                               data_key="interactionId")
    state = marshmallow_enum.EnumField(types.TransactionState,
                                       by_value=True,
                                       missing=None)

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.Transaction(**data)
class CustomFieldSetTypeSchema(FieldTypeSchema):
    """Marshmallow schema for :class:`commercetools.types.CustomFieldSetType`."""

    element_type = helpers.Discriminator(
        discriminator_field=("name", "name"),
        discriminator_schemas={
            "Boolean": "commercetools._schemas._type.CustomFieldBooleanTypeSchema",
            "DateTime": "commercetools._schemas._type.CustomFieldDateTimeTypeSchema",
            "Date": "commercetools._schemas._type.CustomFieldDateTypeSchema",
            "Enum": "commercetools._schemas._type.CustomFieldEnumTypeSchema",
            "LocalizedEnum": "commercetools._schemas._type.CustomFieldLocalizedEnumTypeSchema",
            "LocalizedString": "commercetools._schemas._type.CustomFieldLocalizedStringTypeSchema",
            "Money": "commercetools._schemas._type.CustomFieldMoneyTypeSchema",
            "Number": "commercetools._schemas._type.CustomFieldNumberTypeSchema",
            "Reference": "commercetools._schemas._type.CustomFieldReferenceTypeSchema",
            "Set": "commercetools._schemas._type.CustomFieldSetTypeSchema",
            "String": "commercetools._schemas._type.CustomFieldStringTypeSchema",
            "Time": "commercetools._schemas._type.CustomFieldTimeTypeSchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
        data_key="elementType",
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        del data["name"]
        return types.CustomFieldSetType(**data)
Esempio n. 20
0
class SubscriptionChangeDestinationActionSchema(SubscriptionUpdateActionSchema
                                                ):
    """Marshmallow schema for :class:`commercetools.types.SubscriptionChangeDestinationAction`."""

    destination = helpers.Discriminator(
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "EventGrid":
            "commercetools._schemas._subscription.AzureEventGridDestinationSchema",
            "AzureServiceBus":
            "commercetools._schemas._subscription.AzureServiceBusDestinationSchema",
            "GoogleCloudPubSub":
            "commercetools._schemas._subscription.GoogleCloudPubSubDestinationSchema",
            "IronMQ":
            "commercetools._schemas._subscription.IronMqDestinationSchema",
            "SNS": "commercetools._schemas._subscription.SnsDestinationSchema",
            "SQS": "commercetools._schemas._subscription.SqsDestinationSchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        del data["action"]
        return types.SubscriptionChangeDestinationAction(**data)
class ProductDiscountDraftSchema(marshmallow.Schema):
    "Marshmallow schema for :class:`commercetools.types.ProductDiscountDraft`."
    name = LocalizedStringField(allow_none=True)
    key = marshmallow.fields.String(allow_none=True, missing=None)
    description = LocalizedStringField(allow_none=True, missing=None)
    value = helpers.Discriminator(
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "absolute":
            "commercetools.schemas._product_discount.ProductDiscountValueAbsoluteDraftSchema",
            "external":
            "commercetools.schemas._product_discount.ProductDiscountValueExternalDraftSchema",
            "relative":
            "commercetools.schemas._product_discount.ProductDiscountValueRelativeDraftSchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
    )
    predicate = marshmallow.fields.String(allow_none=True)
    sort_order = marshmallow.fields.String(allow_none=True,
                                           data_key="sortOrder")
    is_active = marshmallow.fields.Bool(allow_none=True, data_key="isActive")
    valid_from = marshmallow.fields.DateTime(allow_none=True,
                                             missing=None,
                                             data_key="validFrom")
    valid_until = marshmallow.fields.DateTime(allow_none=True,
                                              missing=None,
                                              data_key="validUntil")

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.ProductDiscountDraft(**data)
Esempio n. 22
0
class CartClassificationTierSchema(ShippingRatePriceTierSchema):
    value = marshmallow.fields.String(allow_none=True, missing=None)
    price = helpers.LazyNestedField(
        nested=helpers.absmod(__name__, ".common.MoneySchema"),
        allow_none=True,
        unknown=marshmallow.EXCLUDE,
        missing=None,
    )
    tiers = marshmallow.fields.List(
        helpers.Discriminator(
            allow_none=True,
            discriminator_field=("type", "type"),
            discriminator_schemas={
                "CartClassification":
                helpers.absmod(__name__, ".CartClassificationTierSchema")
            },
        ),
        allow_none=True,
        missing=None,
    )
    is_matching = marshmallow.fields.Boolean(
        allow_none=True,
        metadata={"omit_empty": True},
        missing=None,
        data_key="isMatching",
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        del data["type"]
        return models.CartClassificationTier(**data)
class ExtensionDraftSchema(marshmallow.Schema):
    "Marshmallow schema for :class:`commercetools.types.ExtensionDraft`."
    key = marshmallow.fields.String(allow_none=True, missing=None)
    destination = helpers.Discriminator(
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "AWSLambda":
            "commercetools.schemas._extension.ExtensionAWSLambdaDestinationSchema",
            "HTTP":
            "commercetools.schemas._extension.ExtensionHttpDestinationSchema",
        },
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
    )
    triggers = marshmallow.fields.Nested(
        nested="commercetools.schemas._extension.ExtensionTriggerSchema",
        unknown=marshmallow.EXCLUDE,
        allow_none=True,
        many=True,
    )
    timeout_in_ms = marshmallow.fields.Integer(allow_none=True,
                                               missing=None,
                                               data_key="timeoutInMs")

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data):
        return types.ExtensionDraft(**data)
class StoreUpdateSchema(marshmallow.Schema):
    """Marshmallow schema for :class:`commercetools.types.StoreUpdate`."""

    version = marshmallow.fields.Integer(allow_none=True)
    actions = marshmallow.fields.List(
        helpers.Discriminator(
            discriminator_field=("action", "action"),
            discriminator_schemas={
                "setLanguages": "commercetools._schemas._store.StoreSetLanguagesActionSchema",
                "setName": "commercetools._schemas._store.StoreSetNameActionSchema",
                "addDistributionChannel": "commercetools._schemas._store.StoresAddDistributionChannelsActionSchema",
                "addSupplyChannel": "commercetools._schemas._store.StoresAddSupplyChannelsActionSchema",
                "removeDistributionChannel": "commercetools._schemas._store.StoresRemoveDistributionChannelsActionSchema",
                "removeSupplyChannel": "commercetools._schemas._store.StoresRemoveSupplyChannelsActionSchema",
                "setDistributionChannels": "commercetools._schemas._store.StoresSetDistributionChannelsActionSchema",
                "setSupplyChannels": "commercetools._schemas._store.StoresSetSupplyChannelsActionSchema",
            },
            unknown=marshmallow.EXCLUDE,
            allow_none=True,
        ),
        allow_none=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.StoreUpdate(**data)
Esempio n. 25
0
class SubscriptionUpdateSchema(marshmallow.Schema):
    """Marshmallow schema for :class:`commercetools.types.SubscriptionUpdate`."""

    version = marshmallow.fields.Integer(allow_none=True)
    actions = marshmallow.fields.List(
        helpers.Discriminator(
            discriminator_field=("action", "action"),
            discriminator_schemas={
                "changeDestination":
                "commercetools._schemas._subscription.SubscriptionChangeDestinationActionSchema",
                "setChanges":
                "commercetools._schemas._subscription.SubscriptionSetChangesActionSchema",
                "setKey":
                "commercetools._schemas._subscription.SubscriptionSetKeyActionSchema",
                "setMessages":
                "commercetools._schemas._subscription.SubscriptionSetMessagesActionSchema",
            },
            unknown=marshmallow.EXCLUDE,
            allow_none=True,
        ),
        allow_none=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        return types.SubscriptionUpdate(**data)
class SubscriptionUpdateSchema(helpers.BaseSchema):
    version = marshmallow.fields.Integer(allow_none=True, missing=None)
    actions = marshmallow.fields.List(
        helpers.Discriminator(
            allow_none=True,
            discriminator_field=("action", "action"),
            discriminator_schemas={
                "changeDestination":
                helpers.absmod(__name__,
                               ".SubscriptionChangeDestinationActionSchema"),
                "setChanges":
                helpers.absmod(__name__,
                               ".SubscriptionSetChangesActionSchema"),
                "setKey":
                helpers.absmod(__name__, ".SubscriptionSetKeyActionSchema"),
                "setMessages":
                helpers.absmod(__name__,
                               ".SubscriptionSetMessagesActionSchema"),
            },
        ),
        allow_none=True,
        missing=None,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):

        return models.SubscriptionUpdate(**data)
class CartDiscountUpdateSchema(marshmallow.Schema):
    "Marshmallow schema for :class:`commercetools.types.CartDiscountUpdate`."
    version = marshmallow.fields.Integer(allow_none=True)
    actions = marshmallow.fields.List(
        helpers.Discriminator(
            discriminator_field=("action", "action"),
            discriminator_schemas={
                "changeCartPredicate": "commercetools.schemas._cart_discount.CartDiscountChangeCartPredicateActionSchema",
                "changeIsActive": "commercetools.schemas._cart_discount.CartDiscountChangeIsActiveActionSchema",
                "changeName": "commercetools.schemas._cart_discount.CartDiscountChangeNameActionSchema",
                "changeRequiresDiscountCode": "commercetools.schemas._cart_discount.CartDiscountChangeRequiresDiscountCodeActionSchema",
                "changeSortOrder": "commercetools.schemas._cart_discount.CartDiscountChangeSortOrderActionSchema",
                "changeStackingMode": "commercetools.schemas._cart_discount.CartDiscountChangeStackingModeActionSchema",
                "changeTarget": "commercetools.schemas._cart_discount.CartDiscountChangeTargetActionSchema",
                "changeValue": "commercetools.schemas._cart_discount.CartDiscountChangeValueActionSchema",
                "setCustomField": "commercetools.schemas._cart_discount.CartDiscountSetCustomFieldActionSchema",
                "setCustomType": "commercetools.schemas._cart_discount.CartDiscountSetCustomTypeActionSchema",
                "setDescription": "commercetools.schemas._cart_discount.CartDiscountSetDescriptionActionSchema",
                "setKey": "commercetools.schemas._cart_discount.CartDiscountSetKeyActionSchema",
                "setValidFrom": "commercetools.schemas._cart_discount.CartDiscountSetValidFromActionSchema",
                "setValidFromAndUntil": "commercetools.schemas._cart_discount.CartDiscountSetValidFromAndUntilActionSchema",
                "setValidUntil": "commercetools.schemas._cart_discount.CartDiscountSetValidUntilActionSchema",
            },
            unknown=marshmallow.EXCLUDE,
            allow_none=True,
        ),
        allow_none=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data):
        return types.CartDiscountUpdate(**data)
class SubscriptionChangeDestinationActionSchema(SubscriptionUpdateActionSchema
                                                ):
    destination = helpers.Discriminator(
        allow_none=True,
        discriminator_field=("type", "type"),
        discriminator_schemas={
            "EventGrid":
            helpers.absmod(__name__, ".AzureEventGridDestinationSchema"),
            "AzureServiceBus":
            helpers.absmod(__name__, ".AzureServiceBusDestinationSchema"),
            "GoogleCloudPubSub":
            helpers.absmod(__name__, ".GoogleCloudPubSubDestinationSchema"),
            "IronMQ":
            helpers.absmod(__name__, ".IronMqDestinationSchema"),
            "SNS":
            helpers.absmod(__name__, ".SnsDestinationSchema"),
            "SQS":
            helpers.absmod(__name__, ".SqsDestinationSchema"),
        },
        missing=None,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data, **kwargs):
        del data["action"]
        return models.SubscriptionChangeDestinationAction(**data)
class CustomerGroupUpdateSchema(UpdateSchema):
    "Marshmallow schema for :class:`commercetools.types.CustomerGroupUpdate`."
    actions = marshmallow.fields.List(
        helpers.Discriminator(
            discriminator_field=("action", "action"),
            discriminator_schemas={
                "changeName":
                "commercetools.schemas._customer_group.CustomerGroupChangeNameActionSchema",
                "setCustomField":
                "commercetools.schemas._customer_group.CustomerGroupSetCustomFieldActionSchema",
                "setCustomType":
                "commercetools.schemas._customer_group.CustomerGroupSetCustomTypeActionSchema",
                "setKey":
                "commercetools.schemas._customer_group.CustomerGroupSetKeyActionSchema",
            },
            unknown=marshmallow.EXCLUDE,
            allow_none=True,
        ),
        allow_none=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data):
        return types.CustomerGroupUpdate(**data)
Esempio n. 30
0
class ZoneUpdateSchema(UpdateSchema):
    "Marshmallow schema for :class:`commercetools.types.ZoneUpdate`."
    actions = marshmallow.fields.List(
        helpers.Discriminator(
            discriminator_field=("action", "action"),
            discriminator_schemas={
                "addLocation":
                "commercetools.schemas._zone.ZoneAddLocationActionSchema",
                "changeName":
                "commercetools.schemas._zone.ZoneChangeNameActionSchema",
                "removeLocation":
                "commercetools.schemas._zone.ZoneRemoveLocationActionSchema",
                "setDescription":
                "commercetools.schemas._zone.ZoneSetDescriptionActionSchema",
                "setKey": "commercetools.schemas._zone.ZoneSetKeyActionSchema",
            },
            unknown=marshmallow.EXCLUDE,
            allow_none=True,
        ),
        allow_none=True,
    )

    class Meta:
        unknown = marshmallow.EXCLUDE

    @marshmallow.post_load
    def post_load(self, data):
        return types.ZoneUpdate(**data)