Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add tax rates

dominik-zeglen3c34269edecd
diff --git a/saleor/static/dashboard-next/gql-types.ts b/saleor/static/dashboard-next/gql-types.ts
index 910838316b..7ae0e528e6 100644
--- a/saleor/static/dashboard-next/gql-types.ts
+++ b/saleor/static/dashboard-next/gql-types.ts
@@ -17,7 +17,41 @@ export interface ProductTypeInput {
// Determines if shipping is required for products
// of this variant.
isShippingRequired?: boolean | null,
-};
+ // Weight of the ProductType items.
+ weight?: string | null,
+ // A type of goods.
+ taxRate?: TaxRateType | null,
+};
+
+// An enumeration.
+export enum TaxRateType {
+ ACCOMODATION = "ACCOMODATION",
+ ADMISSION_TO_CULTURAL_EVENTS = "ADMISSION_TO_CULTURAL_EVENTS",
+ ADMISSION_TO_ENTERAINMENT_EVENTS = "ADMISSION_TO_ENTERAINMENT_EVENTS",
+ ADMISSION_TO_SPORTING_EVENTS = "ADMISSION_TO_SPORTING_EVENTS",
+ ADVERTISING = "ADVERTISING",
+ AGRICULTURAL_SUPPLIES = "AGRICULTURAL_SUPPLIES",
+ BABY_FOODSTUFFS = "BABY_FOODSTUFFS",
+ BIKES = "BIKES",
+ BOOKS = "BOOKS",
+ CHILDRENDS_CLOTHING = "CHILDRENDS_CLOTHING",
+ DOMESTIC_FUEL = "DOMESTIC_FUEL",
+ DOMESTIC_SERVICES = "DOMESTIC_SERVICES",
+ E_BOOKS = "E_BOOKS",
+ FOODSTUFFS = "FOODSTUFFS",
+ HOTELS = "HOTELS",
+ MEDICAL = "MEDICAL",
+ NEWSPAPERS = "NEWSPAPERS",
+ PASSENGER_TRANSPORT = "PASSENGER_TRANSPORT",
+ PHARMACEUTICALS = "PHARMACEUTICALS",
+ PROPERTY_RENOVATIONS = "PROPERTY_RENOVATIONS",
+ RESTAURANTS = "RESTAURANTS",
+ SOCIAL_HOUSING = "SOCIAL_HOUSING",
+ STANDARD = "STANDARD",
+ WATER = "WATER",
+ WINE = "WINE",
+}
+
export interface AttributeValueInput {
// Slug of an attribute.
@@ -456,6 +490,8 @@ export interface ProductTypeUpdateMutation {
id: string,
name: string,
hasVariants: boolean,
+ // A type of tax rate.
+ taxRate: TaxRateType | null,
productAttributes: {
edges: Array< {
// The item at the end of the edge
@@ -630,38 +666,21 @@ export interface ProductTypeDetailsQuery {
} >,
} | null,
isShippingRequired: boolean,
- taxRate: string,
+ // A type of tax rate.
+ taxRate: TaxRateType | null,
} | null,
- // Represents a shop resources.
- shop: {
- // VAT tax rates for a specific country.
- taxRate: {
- // Standard VAT rate in percent.
- standardRate: number | null,
- //
- // Country's VAT rate exceptions for specific types of goods.
- reducedRates: Array< {
- // A type of goods.
- rateType: string,
- } | null > | null,
- },
+ __type: {
+ enumValues: Array< {
+ name: string,
+ } > | null,
} | null,
};
export interface ProductTypeCreateDataQuery {
- // Represents a shop resources.
- shop: {
- // VAT tax rates for a specific country.
- taxRate: {
- // Standard VAT rate in percent.
- standardRate: number | null,
- //
- // Country's VAT rate exceptions for specific types of goods.
- reducedRates: Array< {
- // A type of goods.
- rateType: string,
- } | null > | null,
- },
+ __type: {
+ enumValues: Array< {
+ name: string,
+ } > | null,
} | null,
};
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
index 1a468da7ea..68575dab99 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
@@ -10,6 +10,7 @@ import SaveButtonBar, {
SaveButtonBarState
} from "../../../components/SaveButtonBar";
import Toggle from "../../../components/Toggle";
+import { TaxRateType } from "../../../gql-types";
import i18n from "../../../i18n";
import ProductTypeDetails from "../ProductTypeDetails/ProductTypeDetails";
import ProductTypeProperties from "../ProductTypeProperties/ProductTypeProperties";
@@ -22,7 +23,7 @@ export interface ProductTypeForm {
name: string;
hasVariants: boolean;
isShippingRequired: boolean;
- taxRate: string;
+ taxRate: TaxRateType;
productAttributes: ChoiceType[];
variantAttributes: ChoiceType[];
}
@@ -36,7 +37,7 @@ interface ProductTypeDetailsPageProps {
name?: string;
hasVariants?: boolean;
isShippingRequired?: boolean;
- taxRate?: string;
+ taxRate?: TaxRateType;
};
productAttributes?: Array<{
id: string;
@@ -54,7 +55,7 @@ interface ProductTypeDetailsPageProps {
id: string;
name: string;
}>;
- taxRates: string[];
+ taxRates: TaxRateType[];
onAttributeSearch: (name: string) => void;
onBack: () => void;
onDelete?: () => void;
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeProperties/ProductTypeProperties.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeProperties/ProductTypeProperties.tsx
index 643c957eba..d2f8835166 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeProperties/ProductTypeProperties.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeProperties/ProductTypeProperties.tsx
@@ -41,10 +41,7 @@ const ProductTypeProperties: React.StatelessComponent<
/>
<FormSpacer />
<SingleSelectField
- choices={[
- { label: "no tax rate", value: null },
- ...taxRates.map(t => ({ label: t, value: t }))
- ]}
+ choices={taxRates.map(t => ({ label: i18n.t(t), value: t }))}
hint={i18n.t("Optional")}
label={i18n.t("Tax rate")}
name="taxRate"
diff --git a/saleor/static/dashboard-next/productTypes/mutations.ts b/saleor/static/dashboard-next/productTypes/mutations.ts
index ecf9314f89..4b94b779a1 100644
--- a/saleor/static/dashboard-next/productTypes/mutations.ts
+++ b/saleor/static/dashboard-next/productTypes/mutations.ts
@@ -39,6 +39,7 @@ export const productTypeUpdateMutation = gql`
id
name
hasVariants
+ taxRate
productAttributes {
edges {
node {
diff --git a/saleor/static/dashboard-next/productTypes/queries.ts b/saleor/static/dashboard-next/productTypes/queries.ts
index f8343990a2..3a9b18af5e 100644
--- a/saleor/static/dashboard-next/productTypes/queries.ts
+++ b/saleor/static/dashboard-next/productTypes/queries.ts
@@ -85,12 +85,9 @@ export const productTypeDetailsQuery = gql`
isShippingRequired
taxRate
}
- shop {
- taxRate(countryCode: "PL") {
- standardRate
- reducedRates {
- rateType
- }
+ __type(name: "TaxRateType") {
+ enumValues {
+ name
}
}
}
@@ -99,15 +96,11 @@ export const productTypeDetailsQuery = gql`
export const TypedProductTypeCreateDataQuery = Query as React.ComponentType<
QueryProps<ProductTypeCreateDataQuery>
>;
-// FIXME: Country code should be supplied from API, not hardcoded
export const productTypeCreateQuery = gql`
query ProductTypeCreateData {
- shop {
- taxRate(countryCode: "PL") {
- standardRate
- reducedRates {
- rateType
- }
+ __type(name: "TaxRateType") {
+ enumValues {
+ name
}
}
}
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
index 03c42e28c2..f200965b3b 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
@@ -3,7 +3,7 @@ import Navigator from "../../components/Navigator";
import { productTypeDetailsUrl, productTypeListUrl } from "..";
import Messages from "../../components/messages";
-import { ProductTypeCreateMutation } from "../../gql-types";
+import { ProductTypeCreateMutation, TaxRateType } from "../../gql-types";
import i18n from "../../i18n";
import ProductTypeDetailsPage, {
ProductTypeForm
@@ -59,9 +59,7 @@ export const ProductTypeCreate: React.StatelessComponent = () => (
createProductType({
variables: {
input: {
- hasVariants: formData.hasVariants,
- isShippingRequired: formData.isShippingRequired,
- name: formData.name,
+ ...formData,
productAttributes: formData.productAttributes.map(
choice => choice.value
),
@@ -101,14 +99,11 @@ export const ProductTypeCreate: React.StatelessComponent = () => (
: []
}
taxRates={
- createData.data &&
- createData.data.shop &&
- createData.data.shop.taxRate &&
- createData.data.shop.taxRate.reducedRates
- ? createData.data.shop.taxRate.reducedRates
- .map(rate => rate.rateType)
- .concat(["standard"])
- : ["standard"]
+ createData.data && createData.data.__type
+ ? createData.data.__type.enumValues.map(
+ value => value.name as TaxRateType
+ )
+ : []
}
onAttributeSearch={searchAttribute}
onBack={() => navigate(productTypeListUrl)}
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
index 5b9b611a40..11415ad590 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
@@ -6,7 +6,8 @@ import ErrorMessageCard from "../../components/ErrorMessageCard";
import Messages from "../../components/messages";
import {
ProductTypeDeleteMutation,
- ProductTypeUpdateMutation
+ ProductTypeUpdateMutation,
+ TaxRateType
} from "../../gql-types";
import i18n from "../../i18n";
import ProductTypeDetailsPage, {
@@ -72,6 +73,7 @@ export const ProductTypeUpdate: React.StatelessComponent<
>
{({
deleteProductType,
+ errors,
loading: mutationLoading,
updateProductType
}) => {
@@ -81,9 +83,7 @@ export const ProductTypeUpdate: React.StatelessComponent<
updateProductType.mutate({
id,
input: {
- hasVariants: formData.hasVariants,
- isShippingRequired: formData.isShippingRequired,
- name: formData.name,
+ ...formData,
productAttributes: formData.productAttributes.map(
choice => choice.value
),
@@ -97,6 +97,7 @@ export const ProductTypeUpdate: React.StatelessComponent<
return (
<ProductTypeDetailsPage
disabled={loading}
+ errors={errors}
pageTitle={
data && data.productType
? data.productType.name
@@ -139,14 +140,11 @@ export const ProductTypeUpdate: React.StatelessComponent<
: []
}
taxRates={
- data &&
- data.shop &&
- data.shop.taxRate &&
- data.shop.taxRate.reducedRates
- ? data.shop.taxRate.reducedRates
- .map(rate => rate.rateType)
- .concat(["standard"])
- : ["standard"]
+ data && data.__type && data.__type.enumValues
+ ? data.__type.enumValues.map(
+ value => value.name as TaxRateType
+ )
+ : []
}
onAttributeSearch={searchAttribute}
onBack={() => navigate(productTypeListUrl)}