Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Replace MoneyScalar with PositiveDecimal scalar
IKarbowiaka0cde37d5c8c
diff --git a/saleor/graphql/core/scalars.py b/saleor/graphql/core/scalars.pyindex 6b9df69184..02e198d7a9 100644--- a/saleor/graphql/core/scalars.py+++ b/saleor/graphql/core/scalars.py@@ -1,8 +1,6 @@import decimalimport graphene-from django.conf import settings-from django_prices.utils.formatting import get_currency_fractionfrom graphql.error import GraphQLErrorfrom graphql.language import astfrom measurement.measures import Weight@@ -38,28 +36,20 @@ class Decimal(graphene.Float):return None-class MoneyScalar(Decimal):- """Money scalar implementation.+class PositiveDecimal(Decimal):+ """Positive Decimal scalar implementation.- Should be used in every price input field.- Contains validations that check if the money value is not lower than 0 and- if the value does not contain too many decimal values.+ Should be used in places where value must be positive."""@staticmethoddef parse_value(value):- value = super(MoneyScalar, MoneyScalar).parse_value(value)+ value = super(PositiveDecimal, PositiveDecimal).parse_value(value)if not value:return valueif value < 0:- raise GraphQLError("Money value cannot be lower than 0.")-- currency_fraction = get_currency_fraction(settings.DEFAULT_CURRENCY)- value = value.normalize()- if abs(value.as_tuple().exponent) > currency_fraction:raise GraphQLError(- "Ensure the provided money field value has no more than "- f"{currency_fraction} decimal places."+ f"Value cannot be lower than 0. Unsupported value: {value}")return valuediff --git a/saleor/graphql/core/tests/test_core.py b/saleor/graphql/core/tests/test_core.pyindex ddf006e079..4a6f45c5f4 100644--- a/saleor/graphql/core/tests/test_core.py+++ b/saleor/graphql/core/tests/test_core.py@@ -10,11 +10,7 @@ from graphene import InputFieldfrom ....product.models import Category, Productfrom ...product import types as product_types-from ...tests.utils import (- _get_graphql_content_from_response,- assert_too_many_decimal_places_in_amount,- get_graphql_content,-)+from ...tests.utils import _get_graphql_content_from_response, get_graphql_contentfrom ...utils import get_database_id, requestor_is_superuserfrom ...utils.filters import filter_range_field, reporting_period_to_datefrom ..enums import ReportingPeriod@@ -137,7 +133,9 @@ def test_mutation_money_scalar_input(staff_api_client, variant, stock, permission_manage_products):query = """- mutation moneyScalarInput($id: ID!, $cost: MoneyScalar, $price: MoneyScalar) {+ mutation PositiveDecimalInput(+ $id: ID!, $cost: PositiveDecimal, $price: PositiveDecimal+ ) {productVariantUpdate(id: $id, input: {costPrice: $cost, price: $price}) {errors {field@@ -170,7 +168,7 @@ def test_mutation_money_scalar_input_without_arguments():query = """mutation ProductVariantUpdate(- $id: ID!, $price: MoneyScalar, $costPrice: MoneyScalar+ $id: ID!, $price: PositiveDecimal, $costPrice: PositiveDecimal) {productVariantUpdate(id: $id, input: {costPrice: $costPrice, price: $price}) {errors {@@ -198,72 +196,6 @@ def test_mutation_money_scalar_input_without_arguments(assert data["errors"] == []-def test_mutation_money_scalar_to_many_decimal_places(- staff_api_client, variant, permission_manage_products-):- # given- query = """- mutation testMoneyScalar($id: ID!, $price: MoneyScalar, $costPrice: MoneyScalar) {- productVariantUpdate(id: $id,- input: {costPrice: $costPrice, price: $price}) {- errors {- field- message- }- productVariant {- id- }- }- }- """- staff_api_client.user.user_permissions.add(permission_manage_products)- variables = {- "id": graphene.Node.to_global_id("ProductVariant", variant.id),- "price": 15,- "costPrice": 12.1234,- }-- # when- response = staff_api_client.post_graphql(query, variables)-- # then- assert_too_many_decimal_places_in_amount(response)---def test_mutation_money_scalar_with_to_many_0_decimal_places(- staff_api_client, variant, permission_manage_products-):- # given- query = """- mutation testMoneyScalar($id: ID!, $price: MoneyScalar, $costPrice: MoneyScalar) {- productVariantUpdate(id: $id,- input: {costPrice: $costPrice, price: $price}) {- errors {- field- message- }- productVariant {- id- }- }- }- """- staff_api_client.user.user_permissions.add(permission_manage_products)- variables = {- "id": graphene.Node.to_global_id("ProductVariant", variant.id),- "price": 15,- "costPrice": 12.1200,- }-- # when- response = staff_api_client.post_graphql(query, variables)-- # then- content = get_graphql_content(response)- data = content["data"]["productVariantUpdate"]- assert not data["errors"]--def test_filter_input():class CreatedEnum(graphene.Enum):WEEK = "week"diff --git a/saleor/graphql/discount/mutations.py b/saleor/graphql/discount/mutations.pyindex 90f1558733..fcc2f2d335 100644--- a/saleor/graphql/discount/mutations.py+++ b/saleor/graphql/discount/mutations.py@@ -10,7 +10,7 @@ from ...product.tasks import (update_products_minimal_variant_prices_of_discount_task,)from ..core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation-from ..core.scalars import Decimal, MoneyScalar+from ..core.scalars import PositiveDecimalfrom ..core.types.common import DiscountErrorfrom ..product.types import Category, Collection, Productfrom .enums import DiscountValueTypeEnum, VoucherTypeEnum@@ -95,7 +95,7 @@ class VoucherInput(graphene.InputObjectType):discount_value_type = DiscountValueTypeEnum(description="Choices: fixed or percentage.")- discount_value = Decimal(description="Value of the voucher.")+ discount_value = PositiveDecimal(description="Value of the voucher.")products = graphene.List(graphene.ID, description="Products discounted by the voucher.", name="products")@@ -109,7 +109,7 @@ class VoucherInput(graphene.InputObjectType):description="Categories discounted by the voucher.",name="categories",)- min_amount_spent = MoneyScalar(+ min_amount_spent = PositiveDecimal(description="Min purchase amount required to apply the voucher.")min_checkout_items_quantity = graphene.Int(@@ -243,7 +243,7 @@ class VoucherRemoveCatalogues(VoucherBaseCatalogueMutation):class SaleInput(graphene.InputObjectType):name = graphene.String(description="Voucher name.")type = DiscountValueTypeEnum(description="Fixed or percentage.")- value = Decimal(description="Value of the voucher.")+ value = PositiveDecimal(description="Value of the voucher.")products = graphene.List(graphene.ID, description="Products related to the discount.", name="products")diff --git a/saleor/graphql/discount/tests/test_discount.py b/saleor/graphql/discount/tests/test_discount.pyindex 81fd99e536..ef5c7c52c2 100644--- a/saleor/graphql/discount/tests/test_discount.py+++ b/saleor/graphql/discount/tests/test_discount.py@@ -143,8 +143,8 @@ CREATE_VOUCHER_MUTATION = """mutation voucherCreate($type: VoucherTypeEnum, $name: String, $code: String,$discountValueType: DiscountValueTypeEnum, $usageLimit: Int,- $discountValue: Decimal,- $minAmountSpent: MoneyScalar, $minCheckoutItemsQuantity: Int,+ $discountValue: PositiveDecimal,+ $minAmountSpent: PositiveDecimal, $minCheckoutItemsQuantity: Int,$startDate: DateTime, $endDate: DateTime, $applyOncePerOrder: Boolean,$applyOncePerCustomer: Boolean) {voucherCreate(input: {@@ -533,7 +533,7 @@ def test_voucher_remove_no_catalogues(def test_create_sale(staff_api_client, permission_manage_discounts):query = """mutation saleCreate(- $type: DiscountValueTypeEnum, $name: String, $value: Decimal,+ $type: DiscountValueTypeEnum, $name: String, $value: PositiveDecimal,$startDate: DateTime, $endDate: DateTime) {saleCreate(input: {name: $name, type: $type, value: $value,diff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.pyindex 7674750098..bf304fa74d 100644--- a/saleor/graphql/giftcard/mutations.py+++ b/saleor/graphql/giftcard/mutations.py@@ -12,7 +12,7 @@ from ...giftcard import modelsfrom ...giftcard.error_codes import GiftCardErrorCodefrom ...giftcard.utils import activate_gift_card, deactivate_gift_cardfrom ..core.mutations import BaseMutation, ModelMutation-from ..core.scalars import MoneyScalar+from ..core.scalars import PositiveDecimalfrom ..core.types.common import GiftCardErrorfrom .types import GiftCard@@ -24,7 +24,7 @@ class GiftCardUpdateInput(graphene.InputObjectType):end_date = graphene.types.datetime.Date(description="End date of the gift card in ISO 8601 format.")- balance = MoneyScalar(description="Value of the gift card.")+ balance = PositiveDecimal(description="Value of the gift card.")user_email = graphene.String(required=False, description="The customer's email of the gift card buyer.")diff --git a/saleor/graphql/giftcard/tests/test_gift_card.py b/saleor/graphql/giftcard/tests/test_gift_card.pyindex 5a4f5974bb..41d1ccd97b 100644--- a/saleor/graphql/giftcard/tests/test_gift_card.py+++ b/saleor/graphql/giftcard/tests/test_gift_card.py@@ -234,7 +234,7 @@ def test_query_gift_card_by_app_without_premissions(CREATE_GIFT_CARD_MUTATION = """mutation giftCardCreate($code: String, $startDate: Date, $endDate: Date,- $balance: MoneyScalar!, $userEmail: String) {+ $balance: PositiveDecimal!, $userEmail: String) {giftCardCreate(input: {code: $code, startDate: $startDate,endDate: $endDate,@@ -476,7 +476,7 @@ def test_create_gift_card_without_premissions(staff_api_client):UPDATE_GIFT_CARD_MUTATION = """mutation giftCardUpdate($id: ID!, $startDate: Date, $endDate: Date,- $balance: MoneyScalar, $userEmail: String!) {+ $balance: PositiveDecimal, $userEmail: String!) {giftCardUpdate(id: $id, input: {startDate: $startDate,endDate: $endDate,balance: $balance, userEmail: $userEmail}) {diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.pyindex f06eda8acb..531714c944 100644--- a/saleor/graphql/order/mutations/draft_orders.py+++ b/saleor/graphql/order/mutations/draft_orders.py@@ -21,7 +21,7 @@ from ....warehouse.management import allocate_stockfrom ...account.i18n import I18nMixinfrom ...account.types import AddressInputfrom ...core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation-from ...core.scalars import MoneyScalar+from ...core.scalars import PositiveDecimalfrom ...core.types.common import OrderErrorfrom ...product.types import ProductVariantfrom ..types import Order, OrderLine@@ -46,7 +46,7 @@ class DraftOrderInput(InputObjectType):descripton="Customer associated with the draft order.", name="user")user_email = graphene.String(description="Email address of the customer.")- discount = MoneyScalar(description="Discount amount for the order.")+ discount = PositiveDecimal(description="Discount amount for the order.")shipping_address = AddressInput(description="Shipping address of the customer.")shipping_method = graphene.ID(description="ID of a selected shipping method.", name="shippingMethod"diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.pyindex 5d03f931dd..a3f81d3bcf 100644--- a/saleor/graphql/order/mutations/orders.py+++ b/saleor/graphql/order/mutations/orders.py@@ -19,7 +19,7 @@ from ....order.utils import get_valid_shipping_methods_for_orderfrom ....payment import CustomPaymentChoices, PaymentError, TransactionKind, gatewayfrom ...account.types import AddressInputfrom ...core.mutations import BaseMutation-from ...core.scalars import UUID, MoneyScalar+from ...core.scalars import UUID, PositiveDecimalfrom ...core.types.common import OrderErrorfrom ...core.utils import validate_required_string_fieldfrom ...meta.deprecated.mutations import ClearMetaBaseMutation, UpdateMetaBaseMutation@@ -362,7 +362,9 @@ class OrderCapture(BaseMutation):class Arguments:id = graphene.ID(required=True, description="ID of the order to capture.")- amount = MoneyScalar(required=True, description="Amount of money to capture.")+ amount = PositiveDecimal(+ required=True, description="Amount of money to capture."+ )class Meta:description = "Capture an order."@@ -429,7 +431,9 @@ class OrderRefund(BaseMutation):class Arguments:id = graphene.ID(required=True, description="ID of the order to refund.")- amount = MoneyScalar(required=True, description="Amount of money to refund.")+ amount = PositiveDecimal(+ required=True, description="Amount of money to refund."+ )class Meta:description = "Refund an order."diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.pyindex 0bd110960c..079a2e7640 100644--- a/saleor/graphql/order/tests/test_order.py+++ b/saleor/graphql/order/tests/test_order.py@@ -572,7 +572,7 @@ def test_draft_order_create(variant_0 = variantquery = """mutation draftCreate(- $user: ID, $discount: MoneyScalar, $lines: [OrderLineCreateInput],+ $user: ID, $discount: PositiveDecimal, $lines: [OrderLineCreateInput],$shippingAddress: AddressInput, $shippingMethod: ID, $voucher: ID,$customerNote: String) {draftOrderCreate(@@ -1666,7 +1666,7 @@ def test_order_capture():order = payment_txn_preauth.orderquery = """- mutation captureOrder($id: ID!, $amount: MoneyScalar!) {+ mutation captureOrder($id: ID!, $amount: PositiveDecimal!) {orderCapture(id: $id, amount: $amount) {order {paymentStatus@@ -1873,7 +1873,7 @@ def test_order_void_payment_error(def test_order_refund(staff_api_client, permission_manage_orders, payment_txn_captured):order = payment_txn_captured.orderquery = """- mutation refundOrder($id: ID!, $amount: MoneyScalar!) {+ mutation refundOrder($id: ID!, $amount: PositiveDecimal!) {orderRefund(id: $id, amount: $amount) {order {paymentStatusdiff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex d6f8d3ec9a..3b7a42aab6 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -15,7 +15,7 @@ from ..account.i18n import I18nMixinfrom ..account.types import AddressInputfrom ..checkout.types import Checkoutfrom ..core.mutations import BaseMutation-from ..core.scalars import MoneyScalar+from ..core.scalars import PositiveDecimalfrom ..core.types import common as common_typesfrom ..core.utils import from_global_id_strict_typefrom .types import Payment@@ -34,7 +34,7 @@ class PaymentInput(graphene.InputObjectType):"billing data in a secure manner."),)- amount = MoneyScalar(+ amount = PositiveDecimal(required=False,description=("Total amount of the transaction, including "@@ -190,7 +190,7 @@ class PaymentCapture(BaseMutation):class Arguments:payment_id = graphene.ID(required=True, description="Payment ID.")- amount = MoneyScalar(description="Transaction amount.")+ amount = PositiveDecimal(description="Transaction amount.")class Meta:description = "Captures the authorized payment amount."diff --git a/saleor/graphql/payment/tests/test_payment.py b/saleor/graphql/payment/tests/test_payment.pyindex b39b5e66d2..6019a87a9b 100644--- a/saleor/graphql/payment/tests/test_payment.py+++ b/saleor/graphql/payment/tests/test_payment.py@@ -398,7 +398,7 @@ def test_create_payment_for_checkout_with_active_payments(CAPTURE_QUERY = """- mutation PaymentCapture($paymentId: ID!, $amount: MoneyScalar!) {+ mutation PaymentCapture($paymentId: ID!, $amount: PositiveDecimal!) {paymentCapture(paymentId: $paymentId, amount: $amount) {payment {id,@@ -547,7 +547,7 @@ def test_payment_capture_gateway_dummy_credit_card_error(REFUND_QUERY = """- mutation PaymentRefund($paymentId: ID!, $amount: MoneyScalar!) {+ mutation PaymentRefund($paymentId: ID!, $amount: PositiveDecimal!) {paymentRefund(paymentId: $paymentId, amount: $amount) {payment {id,diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 77029319bb..45e41e5d31 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -30,7 +30,7 @@ from ....product.utils.attributes import (generate_name_for_variant,)from ...core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation-from ...core.scalars import MoneyScalar, WeightScalar+from ...core.scalars import PositiveDecimal, WeightScalarfrom ...core.types import SeoInput, Uploadfrom ...core.types.common import ProductErrorfrom ...core.utils import (@@ -535,7 +535,7 @@ class ProductInput(graphene.InputObjectType):"is only used if a product doesn't use variants."))- base_price = MoneyScalar(+ base_price = PositiveDecimal(description=("Default price for product variant. ""Note: this field is only used if a product doesn't use variants."@@ -1104,8 +1104,8 @@ class ProductVariantInput(graphene.InputObjectType):required=False,description="List of attributes specific to this variant.",)- cost_price = MoneyScalar(description="Cost price of the variant.")- price = MoneyScalar(description="Price of the particular variant.")+ cost_price = PositiveDecimal(description="Cost price of the variant.")+ price = PositiveDecimal(description="Price of the particular variant.")sku = graphene.String(description="Stock keeping unit.")track_inventory = graphene.Boolean(description=(diff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.pyindex 04f814685e..35c8ce90d7 100644--- a/saleor/graphql/product/tests/test_product.py+++ b/saleor/graphql/product/tests/test_product.py@@ -33,7 +33,7 @@ from ....product.utils.attributes import associate_attribute_values_to_instancefrom ....warehouse.models import Allocation, Stock, Warehousefrom ...core.enums import ReportingPeriodfrom ...tests.utils import (- assert_negative_price_amount,+ assert_negative_positive_decimal_value,assert_no_permission,get_graphql_content,get_multipart_request_body,@@ -1566,7 +1566,7 @@ def test_create_product_with_negative_base_price(response = staff_api_client.post_graphql(query, variables)- assert_negative_price_amount(response)+ assert_negative_positive_decimal_value(response)def test_create_product_with_unicode_in_slug_and_name(@@ -1610,7 +1610,7 @@ QUERY_CREATE_PRODUCT_WITHOUT_VARIANTS = """$productTypeId: ID!,$categoryId: ID!$name: String!,- $basePrice: MoneyScalar!,+ $basePrice: PositiveDecimal!,$sku: String,$trackInventory: Boolean){@@ -1905,7 +1905,7 @@ def test_update_product($visibleInListings: Boolean!,$chargeTaxes: Boolean!,$taxCode: String!,- $basePrice: MoneyScalar!,+ $basePrice: PositiveDecimal!,$attributes: [AttributeValueInput!]) {productUpdate(id: $productId,@@ -2472,7 +2472,7 @@ def test_update_product_with_negative_base_price(query = """mutation updateProduct($productId: ID!,- $basePrice: MoneyScalar)+ $basePrice: PositiveDecimal){productUpdate(id: $productId,@@ -2499,7 +2499,7 @@ def test_update_product_with_negative_base_price(response = staff_api_client.post_graphql(query, variables)- assert_negative_price_amount(response)+ assert_negative_positive_decimal_value(response)def test_update_product_without_category_and_true_is_published_value(@@ -4361,7 +4361,7 @@ mutation createProduct($name: String!,$sku: String,$stocks: [StockInput!],- $basePrice: MoneyScalar!+ $basePrice: PositiveDecimal!$trackInventory: Boolean){productCreate(@@ -4551,7 +4551,7 @@ mutation createProduct($category: ID!$name: String!,$sku: String,- $basePrice: MoneyScalar!,+ $basePrice: PositiveDecimal!,$weight: WeightScalar){productCreate(@@ -4656,7 +4656,7 @@ def test_create_product_with_weight_input($category: ID!,$name: String!,$sku: String,- $basePrice: MoneyScalar!)+ $basePrice: PositiveDecimal!){{productCreate(input: {{diff --git a/saleor/graphql/product/tests/test_product_minimal_variant_price.py b/saleor/graphql/product/tests/test_product_minimal_variant_price.pyindex 0b44241bb3..916bb9d5c1 100644--- a/saleor/graphql/product/tests/test_product_minimal_variant_price.py+++ b/saleor/graphql/product/tests/test_product_minimal_variant_price.py@@ -5,7 +5,7 @@ from freezegun import freeze_timefrom graphql_relay import from_global_id, to_global_idfrom ...discount.enums import DiscountValueTypeEnum-from ...tests.utils import assert_negative_price_amount, get_graphql_content+from ...tests.utils import assert_negative_positive_decimal_value, get_graphql_content@patch(@@ -22,7 +22,7 @@ def test_product_variant_create_updates_minimal_variant_price(mutation ProductVariantCreate($productId: ID!,$sku: String!,- $price: MoneyScalar,+ $price: PositiveDecimal,$attributes: [AttributeValueInput]!,) {productVariantCreate(@@ -83,7 +83,7 @@ def test_product_variant_update_updates_minimal_variant_price(query = """mutation ProductVariantUpdate($id: ID!,- $price: MoneyScalar,+ $price: PositiveDecimal,) {productVariantUpdate(id: $id,@@ -132,7 +132,7 @@ def test_product_variant_update_updates_invalid_variant_price(query = """mutation ProductVariantUpdate($id: ID!,- $price: MoneyScalar,+ $price: PositiveDecimal,) {productVariantUpdate(id: $id,@@ -159,7 +159,7 @@ def test_product_variant_update_updates_invalid_variant_price(response = staff_api_client.post_graphql(query, variables)- assert_negative_price_amount(response)+ assert_negative_positive_decimal_value(response)@patch(@@ -175,7 +175,7 @@ def test_product_variant_update_updates_invalid_cost_price(query = """mutation ProductVariantUpdate($id: ID!,- $costPrice: MoneyScalar,+ $costPrice: PositiveDecimal,) {productVariantUpdate(id: $id,@@ -202,7 +202,7 @@ def test_product_variant_update_updates_invalid_cost_price(response = staff_api_client.post_graphql(query, variables)- assert_negative_price_amount(response)+ assert_negative_positive_decimal_value(response)@patch(@@ -390,7 +390,7 @@ def test_sale_create_updates_products_minimal_variant_prices(mutation SaleCreate($name: String,$type: DiscountValueTypeEnum,- $value: Decimal,+ $value: PositiveDecimal,$products: [ID]) {saleCreate(input: {@@ -439,7 +439,7 @@ def test_sale_update_updates_products_minimal_variant_prices(permission_manage_discounts,):query = """- mutation SaleUpdate($id: ID!, $value: Decimal) {+ mutation SaleUpdate($id: ID!, $value: PositiveDecimal) {saleUpdate(id: $id, input: {value: $value}) {sale {iddiff --git a/saleor/graphql/product/tests/test_variant.py b/saleor/graphql/product/tests/test_variant.pyindex 835bf50819..d61685ed4f 100644--- a/saleor/graphql/product/tests/test_variant.py+++ b/saleor/graphql/product/tests/test_variant.py@@ -12,7 +12,7 @@ from ....product.utils.attributes import associate_attribute_values_to_instancefrom ....warehouse.error_codes import StockErrorCodefrom ....warehouse.models import Stock, Warehousefrom ...core.enums import WeightUnitsEnum-from ...tests.utils import assert_negative_price_amount, get_graphql_content+from ...tests.utils import assert_negative_positive_decimal_value, get_graphql_contentdef test_fetch_variant(@@ -96,8 +96,8 @@ def test_create_variant($productId: ID!,$sku: String!,$stocks: [StockInput!],- $price: MoneyScalar,- $costPrice: MoneyScalar,+ $price: PositiveDecimal,+ $costPrice: PositiveDecimal,$attributes: [AttributeValueInput]!,$weight: WeightScalar,$trackInventory: Boolean!) {@@ -284,7 +284,7 @@ def test_create_product_variant_not_all_attributes(query = """mutation createVariant ($productId: ID!,- $price: MoneyScalar,+ $price: PositiveDecimal,$sku: String!,$attributes: [AttributeValueInput]!) {productVariantCreate(@@ -340,7 +340,7 @@ def test_create_product_variant_duplicated_attributes(query = """mutation createVariant ($productId: ID!,- $price: MoneyScalar,+ $price: PositiveDecimal,$sku: String!,$attributes: [AttributeValueInput]!) {@@ -393,8 +393,8 @@ def test_create_product_variant_update_with_new_attributes(mutation VariantUpdate($id: ID!$attributes: [AttributeValueInput]- $costPrice: MoneyScalar- $price: MoneyScalar+ $costPrice: PositiveDecimal+ $price: PositiveDecimal$sku: String$trackInventory: Boolean!) {@@ -466,8 +466,8 @@ def test_update_product_variant(staff_api_client, product, permission_manage_promutation updateVariant ($id: ID!,$sku: String!,- $price: MoneyScalar,- $costPrice: MoneyScalar,+ $price: PositiveDecimal,+ $costPrice: PositiveDecimal,$trackInventory: Boolean!) {productVariantUpdate(id: $id,@@ -525,7 +525,7 @@ def test_update_product_variant_with_negative_weight(query = """mutation updateVariant ($id: ID!,- $price: MoneyScalar,+ $price: PositiveDecimal,$weight: WeightScalar) {productVariantUpdate(@@ -570,8 +570,8 @@ def test_update_product_variant_unset_cost_price(mutation updateVariant ($id: ID!,$sku: String!,- $price: MoneyScalar,- $costPrice: MoneyScalar) {+ $price: PositiveDecimal,+ $costPrice: PositiveDecimal) {productVariantUpdate(id: $id,input: {@@ -615,7 +615,7 @@ QUERY_UPDATE_VARIANT_ATTRIBUTES = """mutation updateVariant ($id: ID!,$sku: String,- $price: MoneyScalar,+ $price: PositiveDecimal,$attributes: [AttributeValueInput]!) {productVariantUpdate(id: $id,@@ -1214,7 +1214,7 @@ def test_product_variant_bulk_create_by_attribute_id_with_invalid_price()# then- assert_negative_price_amount(response)+ assert_negative_positive_decimal_value(response)def test_product_variant_bulk_create_empty_attribute(diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 3f8f1968d6..e2953571b5 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -1630,8 +1630,6 @@ type DeactivateAllUserTokens {accountErrors: [AccountError!]!}-scalar Decimal-type DeleteMetadata {errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")metadataErrors: [MetadataError!]!@@ -1778,7 +1776,7 @@ input DraftOrderCreateInput {billingAddress: AddressInputuser: IDuserEmail: String- discount: MoneyScalar+ discount: PositiveDecimalshippingAddress: AddressInputshippingMethod: IDvoucher: ID@@ -1796,7 +1794,7 @@ input DraftOrderInput {billingAddress: AddressInputuser: IDuserEmail: String- discount: MoneyScalar+ discount: PositiveDecimalshippingAddress: AddressInputshippingMethod: IDvoucher: ID@@ -2064,7 +2062,7 @@ type GiftCardCreate {input GiftCardCreateInput {startDate: DateendDate: Date- balance: MoneyScalar+ balance: PositiveDecimaluserEmail: Stringcode: String}@@ -2099,7 +2097,7 @@ type GiftCardUpdate {input GiftCardUpdateInput {startDate: DateendDate: Date- balance: MoneyScalar+ balance: PositiveDecimaluserEmail: String}@@ -2557,8 +2555,6 @@ type MoneyRange {stop: Money}-scalar MoneyScalar-input MoveProductInput {productId: ID!sortOrder: Int@@ -2676,8 +2672,8 @@ type Mutation {productVariantClearPrivateMetadata(id: ID!, input: MetaPath!): ProductVariantClearPrivateMeta @deprecated(reason: "Use the `deletePrivateMetadata` mutation instead. This field will be removed after 2020-07-31.")variantImageAssign(imageId: ID!, variantId: ID!): VariantImageAssignvariantImageUnassign(imageId: ID!, variantId: ID!): VariantImageUnassign- paymentCapture(amount: MoneyScalar, paymentId: ID!): PaymentCapture- paymentRefund(amount: MoneyScalar, paymentId: ID!): PaymentRefund+ paymentCapture(amount: PositiveDecimal, paymentId: ID!): PaymentCapture+ paymentRefund(amount: PositiveDecimal, paymentId: ID!): PaymentRefundpaymentVoid(paymentId: ID!): PaymentVoidpageCreate(input: PageInput!): PageCreatepageDelete(id: ID!): PageDelete@@ -2696,7 +2692,7 @@ type Mutation {draftOrderUpdate(id: ID!, input: DraftOrderInput!): DraftOrderUpdateorderAddNote(order: ID!, input: OrderAddNoteInput!): OrderAddNoteorderCancel(id: ID!): OrderCancel- orderCapture(amount: MoneyScalar!, id: ID!): OrderCapture+ orderCapture(amount: PositiveDecimal!, id: ID!): OrderCaptureorderClearPrivateMeta(id: ID!, input: MetaPath!): OrderClearPrivateMeta @deprecated(reason: "Use the `deletePrivateMetadata` mutation instead. This field will be removed after 2020-07-31.")orderClearMeta(input: MetaPath!, token: UUID!): OrderClearMeta @deprecated(reason: "Use the `deleteMetadata` mutation instead. This field will be removed after 2020-07-31.")orderFulfill(input: OrderFulfillInput!, order: ID): OrderFulfill@@ -2707,7 +2703,7 @@ type Mutation {orderFulfillmentUpdateMeta(id: ID!, input: MetaInput!): FulfillmentUpdateMeta @deprecated(reason: "Use the `updateMetadata` mutation instead. This field will be removed after 2020-07-31.")orderFulfillmentUpdatePrivateMeta(id: ID!, input: MetaInput!): FulfillmentUpdatePrivateMeta @deprecated(reason: "Use the `updatePrivateMetadata` mutation instead. This field will be removed after 2020-07-31.")orderMarkAsPaid(id: ID!): OrderMarkAsPaid- orderRefund(amount: MoneyScalar!, id: ID!): OrderRefund+ orderRefund(amount: PositiveDecimal!, id: ID!): OrderRefundorderUpdate(id: ID!, input: OrderUpdateInput!): OrderUpdateorderUpdateMeta(input: MetaInput!, token: UUID!): OrderUpdateMeta @deprecated(reason: "Use the `updateMetadata` mutation instead. This field will be removed after 2020-07-31.")orderUpdatePrivateMeta(id: ID!, input: MetaInput!): OrderUpdatePrivateMeta @deprecated(reason: "Use the `updatePrivateMetadata` mutation instead. This field will be removed after 2020-07-31.")@@ -3450,7 +3446,7 @@ type PaymentGateway {input PaymentInput {gateway: String!token: String- amount: MoneyScalar+ amount: PositiveDecimalbillingAddress: AddressInputreturnUrl: String}@@ -3619,6 +3615,8 @@ input PluginUpdateInput {configuration: [ConfigurationItemInput]}+scalar PositiveDecimal+input PriceRangeInput {gte: Floatlte: Float@@ -3726,7 +3724,7 @@ input ProductCreateInput {weight: WeightScalarsku: StringtrackInventory: Boolean- basePrice: MoneyScalar+ basePrice: PositiveDecimalvisibleInListings: BooleanproductType: ID!stocks: [StockInput!]@@ -3860,7 +3858,7 @@ input ProductInput {weight: WeightScalarsku: StringtrackInventory: Boolean- basePrice: MoneyScalar+ basePrice: PositiveDecimalvisibleInListings: Boolean}@@ -4107,8 +4105,8 @@ type ProductVariantBulkCreate {input ProductVariantBulkCreateInput {attributes: [AttributeValueInput]!- costPrice: MoneyScalar- price: MoneyScalar+ costPrice: PositiveDecimal+ price: PositiveDecimalsku: String!trackInventory: Booleanweight: WeightScalar@@ -4152,8 +4150,8 @@ type ProductVariantCreate {input ProductVariantCreateInput {attributes: [AttributeValueInput]!- costPrice: MoneyScalar- price: MoneyScalar+ costPrice: PositiveDecimal+ price: PositiveDecimalsku: StringtrackInventory: Booleanweight: WeightScalar@@ -4169,8 +4167,8 @@ type ProductVariantDelete {input ProductVariantInput {attributes: [AttributeValueInput]- costPrice: MoneyScalar- price: MoneyScalar+ costPrice: PositiveDecimal+ price: PositiveDecimalsku: StringtrackInventory: Booleanweight: WeightScalar@@ -4397,7 +4395,7 @@ input SaleFilterInput {input SaleInput {name: Stringtype: DiscountValueTypeEnum- value: Decimal+ value: PositiveDecimalproducts: [ID]categories: [ID]collections: [ID]@@ -4643,9 +4641,9 @@ type ShippingPriceDelete {input ShippingPriceInput {name: String- price: MoneyScalar- minimumOrderPrice: MoneyScalar- maximumOrderPrice: MoneyScalar+ price: PositiveDecimal+ minimumOrderPrice: PositiveDecimal+ maximumOrderPrice: PositiveDecimalminimumOrderWeight: WeightScalarmaximumOrderWeight: WeightScalartype: ShippingMethodTypeEnum@@ -5355,11 +5353,11 @@ input VoucherInput {startDate: DateTimeendDate: DateTimediscountValueType: DiscountValueTypeEnum- discountValue: Decimal+ discountValue: PositiveDecimalproducts: [ID]collections: [ID]categories: [ID]- minAmountSpent: MoneyScalar+ minAmountSpent: PositiveDecimalminCheckoutItemsQuantity: Intcountries: [String]applyOncePerOrder: Booleandiff --git a/saleor/graphql/shipping/mutations.py b/saleor/graphql/shipping/mutations.pyindex 3e973c4dfd..aba39cf4d8 100644--- a/saleor/graphql/shipping/mutations.py+++ b/saleor/graphql/shipping/mutations.py@@ -10,7 +10,7 @@ from ...shipping.utils import (get_countries_without_shipping_zone,)from ..core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation-from ..core.scalars import MoneyScalar, WeightScalar+from ..core.scalars import PositiveDecimal, WeightScalarfrom ..core.types.common import ShippingErrorfrom ..core.utils import get_duplicates_idsfrom .enums import ShippingMethodTypeEnum@@ -19,11 +19,11 @@ from .types import ShippingMethod, ShippingZoneclass ShippingPriceInput(graphene.InputObjectType):name = graphene.String(description="Name of the shipping method.")- price = MoneyScalar(description="Shipping price of the shipping method.")- minimum_order_price = MoneyScalar(+ price = PositiveDecimal(description="Shipping price of the shipping method.")+ minimum_order_price = PositiveDecimal(description="Minimum order price to use this shipping method.")- maximum_order_price = MoneyScalar(+ maximum_order_price = PositiveDecimal(description="Maximum order price to use this shipping method.")minimum_order_weight = WeightScalar(diff --git a/saleor/graphql/shipping/tests/test_shipping_method.py b/saleor/graphql/shipping/tests/test_shipping_method.pyindex 646747fefa..7724e3af83 100644--- a/saleor/graphql/shipping/tests/test_shipping_method.py+++ b/saleor/graphql/shipping/tests/test_shipping_method.py@@ -6,7 +6,7 @@ from ....core.weight import WeightUnitsfrom ....shipping.error_codes import ShippingErrorCodefrom ....shipping.utils import get_countries_without_shipping_zonefrom ...core.enums import WeightUnitsEnum-from ...tests.utils import assert_negative_price_amount, get_graphql_content+from ...tests.utils import assert_negative_positive_decimal_value, get_graphql_contentfrom ..types import ShippingMethodTypeEnumSHIPPING_ZONE_QUERY = """@@ -523,9 +523,9 @@ def test_delete_shipping_zone(PRICE_BASED_SHIPPING_QUERY = """mutation createShippingPrice(- $type: ShippingMethodTypeEnum, $name: String!, $price: MoneyScalar,- $shippingZone: ID!, $minimumOrderPrice: MoneyScalar,- $maximumOrderPrice: MoneyScalar) {+ $type: ShippingMethodTypeEnum, $name: String!, $price: PositiveDecimal,+ $shippingZone: ID!, $minimumOrderPrice: PositiveDecimal,+ $maximumOrderPrice: PositiveDecimal) {shippingPriceCreate(input: {name: $name, price: $price, shippingZone: $shippingZone,minimumOrderPrice: $minimumOrderPrice,@@ -619,7 +619,7 @@ def test_create_shipping_method_with_invalid_price(response = staff_api_client.post_graphql(query, variables)- assert_negative_price_amount(response)+ assert_negative_positive_decimal_value(response)def test_create_price_shipping_method_errors(@@ -644,7 +644,7 @@ def test_create_price_shipping_method_errors(WEIGHT_BASED_SHIPPING_QUERY = """mutation createShippingPrice(- $type: ShippingMethodTypeEnum, $name: String!, $price: MoneyScalar,+ $type: ShippingMethodTypeEnum, $name: String!, $price: PositiveDecimal,$shippingZone: ID!, $maximumOrderWeight: WeightScalar,$minimumOrderWeight: WeightScalar) {shippingPriceCreate(@@ -781,8 +781,8 @@ def test_update_shipping_method():query = """mutation updateShippingPrice(- $id: ID!, $price: MoneyScalar, $shippingZone: ID!,- $type: ShippingMethodTypeEnum!, $minimumOrderPrice: MoneyScalar) {+ $id: ID!, $price: PositiveDecimal, $shippingZone: ID!,+ $type: ShippingMethodTypeEnum!, $minimumOrderPrice: PositiveDecimal) {shippingPriceUpdate(id: $id, input: {price: $price, shippingZone: $shippingZone,diff --git a/saleor/graphql/tests/utils.py b/saleor/graphql/tests/utils.pyindex 95b06ab8a5..429478be41 100644--- a/saleor/graphql/tests/utils.py+++ b/saleor/graphql/tests/utils.py@@ -26,12 +26,12 @@ def assert_no_permission(response):), content["errors"]-def assert_negative_price_amount(response):+def assert_negative_positive_decimal_value(response):content = _get_graphql_content_from_response(response)assert "errors" in content, content- assert content["errors"][0]["message"] == (- "Money value cannot be lower than 0."- ), content["errors"]+ assert "Value cannot be lower than 0." in content["errors"][0]["message"], content[+ "errors"+ ]def assert_too_many_decimal_places_in_amount(response):diff --git a/saleor/product/tests/test_product_minimal_variant_price.py b/saleor/product/tests/test_product_minimal_variant_price.pyindex 4e40973caa..09a98f8d4e 100644--- a/saleor/product/tests/test_product_minimal_variant_price.py+++ b/saleor/product/tests/test_product_minimal_variant_price.py@@ -81,7 +81,7 @@ def test_product_update_updates_minimal_variant_price(query = """mutation ProductUpdate($productId: ID!,- $basePrice: MoneyScalar!,+ $basePrice: PositiveDecimal!,) {productUpdate(id: $productId