Example #1
0
class PricefulSerializer(serializers.Serializer):
    base_price = FormattedDecimalField(source='base_price.value',
                                       coerce_to_string=False)
    price = FormattedDecimalField(source='price.value', coerce_to_string=False)
    discount_amount = FormattedDecimalField(source='discount_amount.value',
                                            required=False,
                                            coerce_to_string=False)
    discount_rate = FormattedDecimalField(required=False,
                                          coerce_to_string=False)
    discount_percentage = FormattedDecimalField(required=False,
                                                coerce_to_string=False)
    taxful_price = FormattedDecimalField(source='taxful_price.value',
                                         required=False,
                                         coerce_to_string=False)
    taxless_price = FormattedDecimalField(source='taxless_price.value',
                                          required=False,
                                          coerce_to_string=False)
    taxful_base_price = FormattedDecimalField(source='taxful_base_price.value',
                                              required=False,
                                              coerce_to_string=False)
    taxless_base_price = FormattedDecimalField(
        source='taxless_base_price.value',
        required=False,
        coerce_to_string=False)
    tax_amount = FormattedDecimalField(source='tax_amount.value',
                                       required=False,
                                       coerce_to_string=False)
    is_discounted = serializers.BooleanField()

    class Meta:
        fields = "__all__"
Example #2
0
class BaseLineSerializerMixin(serializers.Serializer):
    quantity = FormattedDecimalField()
    price = FormattedDecimalField()
    base_price = FormattedDecimalField()
    discount_amount = FormattedDecimalField()
    discounted_unit_price = FormattedDecimalField()
    is_discounted = serializers.BooleanField()
Example #3
0
class ProductStockStatusSerializer(serializers.Serializer):
    product = serializers.IntegerField(source="product_id")
    sku = serializers.CharField(source="product.sku")
    logical_count = FormattedDecimalField(coerce_to_string=False)
    physical_count = FormattedDecimalField(coerce_to_string=False)
    message = serializers.CharField()
    error = serializers.CharField()
    stock_managed = serializers.BooleanField()
Example #4
0
class TaxLineSerializerMixin(serializers.Serializer):
    taxful_base_unit_price = FormattedDecimalField()
    taxful_discount_amount = FormattedDecimalField()
    taxful_price = FormattedDecimalField()
    taxful_discounted_unit_price = FormattedDecimalField()

    taxless_base_unit_price = FormattedDecimalField()
    taxless_discount_amount = FormattedDecimalField()
    taxless_price = FormattedDecimalField()
    taxless_discounted_unit_price = FormattedDecimalField()

    tax_amount = FormattedDecimalField()
Example #5
0
class BaseProductAddBasketSerializer(serializers.Serializer):
    supplier = serializers.IntegerField(required=False)
    quantity = FormattedDecimalField(required=False)
    description = serializers.CharField(max_length=128,
                                        required=False,
                                        allow_null=True)
    force_new_line = serializers.BooleanField(required=False)
Example #6
0
class TaxSummarySerializer(serializers.Serializer):
    tax_id = serializers.CharField(required=False, allow_null=True)
    tax_code = serializers.CharField(required=False, allow_blank=True)
    tax_name = serializers.CharField(required=False)
    tax_rate = FormattedDecimalField(required=False)
    raw_based_on = FormattedDecimalField(required=False)
    based_on = FormattedDecimalField(required=False)
    tax_amount = FormattedDecimalField(required=False)
    taxful = FormattedDecimalField(required=False)

    def create(self, validated_data):
        from shuup.core.taxing._tax_summary import TaxSummaryLine
        return TaxSummaryLine(**validated_data)

    def update(self, instance, validated_data):
        for field, value in validated_data.items():
            setattr(instance, field, value)
        return instance
Example #7
0
class SourceLineTaxSerializer(serializers.Serializer):
    line_id = serializers.CharField(required=True)
    name = serializers.CharField(required=True)
    amount = FormattedDecimalField(required=True)
    base_amount = FormattedDecimalField(required=True)
    tax = TaxSerializer()
Example #8
0
class ProductCombinationSerializer(serializers.Serializer):
    combination = serializers.DictField()
    sku = serializers.CharField()
    price = FormattedDecimalField(required=False)
    stock_count = serializers.IntegerField(required=False)
Example #9
0
class RefundLineSerializer(serializers.Serializer):
    line = serializers.PrimaryKeyRelatedField(queryset=OrderLine.objects.all())
    quantity = FormattedDecimalField()
    amount = FormattedDecimalField()
    restock_products = serializers.BooleanField()
Example #10
0
class StockAdjustmentSerializer(serializers.Serializer):
    type = EnumField(StockAdjustmentType,
                     default=StockAdjustmentType.INVENTORY)
    product = serializers.PrimaryKeyRelatedField(
        queryset=Product.objects.all_except_deleted())
    delta = FormattedDecimalField()
Example #11
0
class BaseOrderTotalSerializerMixin(serializers.Serializer):
    taxful_total_price = FormattedDecimalField()
    taxless_total_price = FormattedDecimalField()
    prices_include_tax = serializers.BooleanField()
Example #12
0
class LineQuantitySerializer(serializers.Serializer):
    line_id = serializers.CharField()
    quantity = FormattedDecimalField()
Example #13
0
class BasketSerializer(BaseOrderTotalSerializerMixin, serializers.Serializer):
    shop = serializers.SerializerMethodField()
    key = serializers.CharField(max_length=32, min_length=32)
    items = serializers.SerializerMethodField()
    unorderable_items = serializers.SerializerMethodField()
    codes = serializers.ListField()
    shipping_address = serializers.SerializerMethodField()
    shipping_method = ShippingMethodSerializer()
    payment_method = PaymentMethodSerializer()
    available_shipping_methods = serializers.SerializerMethodField()
    available_payment_methods = serializers.SerializerMethodField()
    customer = serializers.SerializerMethodField()
    validation_errors = serializers.SerializerMethodField()
    customer_comment = serializers.SerializerMethodField()

    total_discount = FormattedDecimalField()
    total_price = FormattedDecimalField()
    taxful_total_discount = FormattedDecimalField()
    taxless_total_discount = FormattedDecimalField()
    total_price_of_products = FormattedDecimalField()
    taxful_total_price_of_products = FormattedDecimalField()
    taxless_total_price_of_products = FormattedDecimalField()

    prices_include_tax = serializers.BooleanField()
    currency = serializers.SerializerMethodField()

    def get_customer(self, basket):
        if basket.customer:
            return BasketCustomerSerializer(basket.customer).data

    def get_currency(self, basket):
        return CurrencySerializer(Currency.objects.get(code=basket.currency),
                                  context=self.context).data

    def get_shipping_address(self, basket):
        if basket._data.get("shipping_address_id"):
            address = MutableAddress.objects.filter(
                id=basket._data["shipping_address_id"]).first()
            return AddressSerializer(address, context=self.context).data

    def get_validation_errors(self, basket):
        return [{
            err.code: "%s" % err.message
        } for err in basket.get_validation_errors()]

    def get_items(self, basket):
        return BasketLineSerializer(basket.get_final_lines(with_taxes=True),
                                    many=True,
                                    context=self.context).data

    def get_unorderable_items(self, basket):
        return BasketUnorderableLineSerializer(basket.get_unorderable_lines(),
                                               many=True,
                                               context=self.context).data

    def get_shop(self, basket):
        return basket.shop.id

    def get_available_payment_methods(self, basket):
        return PaymentMethodSerializer(basket.get_available_payment_methods(),
                                       many=True,
                                       context=self.context).data

    def get_available_shipping_methods(self, basket):
        return ShippingMethodSerializer(
            basket.get_available_shipping_methods(),
            many=True,
            context=self.context).data

    def get_customer_comment(self, basket):
        return basket.customer_comment or ""