Skip to content

Commit

Permalink
feat(core): Split taxes from adjustments
Browse files Browse the repository at this point in the history
Relates to #573

BREAKING CHANGE: The `OrderLine.pendingAdjustments` field has been renamed to `adjustments`, tax
adjustments are now stored in a new field, `taxLines`. This will require a DB migration to
preserve data from existing Orders (see guide in release blog post)
  • Loading branch information
michaelbromley committed Dec 1, 2020
1 parent 079a7ae commit 2c71a82
Show file tree
Hide file tree
Showing 25 changed files with 221 additions and 134 deletions.
17 changes: 10 additions & 7 deletions packages/admin-ui/src/lib/core/src/common/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2000,13 +2000,7 @@ export enum GlobalFlag {
}

export enum AdjustmentType {
TAX = 'TAX',
PROMOTION = 'PROMOTION',
SHIPPING = 'SHIPPING',
REFUND = 'REFUND',
TAX_REFUND = 'TAX_REFUND',
PROMOTION_REFUND = 'PROMOTION_REFUND',
SHIPPING_REFUND = 'SHIPPING_REFUND'
PROMOTION = 'PROMOTION'
}

export type Adjustment = {
Expand All @@ -2017,6 +2011,13 @@ export type Adjustment = {
amount: Scalars['Int'];
};

export type TaxLine = {
__typename?: 'TaxLine';
description: Scalars['String'];
amount: Scalars['Int'];
taxRate: Scalars['Float'];
};

export type ConfigArg = {
__typename?: 'ConfigArg';
name: Scalars['String'];
Expand Down Expand Up @@ -3432,6 +3433,7 @@ export type OrderItem = Node & {
unitPriceIncludesTax: Scalars['Boolean'];
taxRate: Scalars['Float'];
adjustments: Array<Adjustment>;
taxLines: Array<TaxLine>;
fulfillment?: Maybe<Fulfillment>;
refundId?: Maybe<Scalars['ID']>;
};
Expand All @@ -3457,6 +3459,7 @@ export type OrderLine = Node & {
/** The total price of the line including tax */
linePriceWithTax: Scalars['Int'];
adjustments: Array<Adjustment>;
taxLines: Array<TaxLine>;
order: Order;
customFields?: Maybe<Scalars['JSON']>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1817,13 +1817,7 @@ export enum GlobalFlag {
}

export enum AdjustmentType {
TAX = 'TAX',
PROMOTION = 'PROMOTION',
SHIPPING = 'SHIPPING',
REFUND = 'REFUND',
TAX_REFUND = 'TAX_REFUND',
PROMOTION_REFUND = 'PROMOTION_REFUND',
SHIPPING_REFUND = 'SHIPPING_REFUND',
}

export type Adjustment = {
Expand All @@ -1833,6 +1827,12 @@ export type Adjustment = {
amount: Scalars['Int'];
};

export type TaxLine = {
description: Scalars['String'];
amount: Scalars['Int'];
taxRate: Scalars['Float'];
};

export type ConfigArg = {
name: Scalars['String'];
value: Scalars['String'];
Expand Down Expand Up @@ -3200,6 +3200,7 @@ export type OrderItem = Node & {
unitPriceIncludesTax: Scalars['Boolean'];
taxRate: Scalars['Float'];
adjustments: Array<Adjustment>;
taxLines: Array<TaxLine>;
fulfillment?: Maybe<Fulfillment>;
refundId?: Maybe<Scalars['ID']>;
};
Expand All @@ -3224,6 +3225,7 @@ export type OrderLine = Node & {
/** The total price of the line including tax */
linePriceWithTax: Scalars['Int'];
adjustments: Array<Adjustment>;
taxLines: Array<TaxLine>;
order: Order;
customFields?: Maybe<Scalars['JSON']>;
};
Expand Down
15 changes: 9 additions & 6 deletions packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,7 @@ export enum GlobalFlag {
}

export enum AdjustmentType {
TAX = 'TAX',
PROMOTION = 'PROMOTION',
SHIPPING = 'SHIPPING',
REFUND = 'REFUND',
TAX_REFUND = 'TAX_REFUND',
PROMOTION_REFUND = 'PROMOTION_REFUND',
SHIPPING_REFUND = 'SHIPPING_REFUND',
}

export type Adjustment = {
Expand All @@ -315,6 +309,13 @@ export type Adjustment = {
amount: Scalars['Int'];
};

export type TaxLine = {
__typename?: 'TaxLine';
description: Scalars['String'];
amount: Scalars['Int'];
taxRate: Scalars['Float'];
};

export type ConfigArg = {
__typename?: 'ConfigArg';
name: Scalars['String'];
Expand Down Expand Up @@ -2113,6 +2114,7 @@ export type OrderItem = Node & {
unitPriceIncludesTax: Scalars['Boolean'];
taxRate: Scalars['Float'];
adjustments: Array<Adjustment>;
taxLines: Array<TaxLine>;
fulfillment?: Maybe<Fulfillment>;
refundId?: Maybe<Scalars['ID']>;
};
Expand All @@ -2138,6 +2140,7 @@ export type OrderLine = Node & {
/** The total price of the line including tax */
linePriceWithTax: Scalars['Int'];
adjustments: Array<Adjustment>;
taxLines: Array<TaxLine>;
order: Order;
customFields?: Maybe<Scalars['JSON']>;
};
Expand Down
17 changes: 10 additions & 7 deletions packages/common/src/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1969,13 +1969,7 @@ export enum GlobalFlag {
}

export enum AdjustmentType {
TAX = 'TAX',
PROMOTION = 'PROMOTION',
SHIPPING = 'SHIPPING',
REFUND = 'REFUND',
TAX_REFUND = 'TAX_REFUND',
PROMOTION_REFUND = 'PROMOTION_REFUND',
SHIPPING_REFUND = 'SHIPPING_REFUND'
PROMOTION = 'PROMOTION'
}

export type Adjustment = {
Expand All @@ -1986,6 +1980,13 @@ export type Adjustment = {
amount: Scalars['Int'];
};

export type TaxLine = {
__typename?: 'TaxLine';
description: Scalars['String'];
amount: Scalars['Int'];
taxRate: Scalars['Float'];
};

export type ConfigArg = {
__typename?: 'ConfigArg';
name: Scalars['String'];
Expand Down Expand Up @@ -3400,6 +3401,7 @@ export type OrderItem = Node & {
unitPriceIncludesTax: Scalars['Boolean'];
taxRate: Scalars['Float'];
adjustments: Array<Adjustment>;
taxLines: Array<TaxLine>;
fulfillment?: Maybe<Fulfillment>;
refundId?: Maybe<Scalars['ID']>;
};
Expand All @@ -3425,6 +3427,7 @@ export type OrderLine = Node & {
/** The total price of the line including tax */
linePriceWithTax: Scalars['Int'];
adjustments: Array<Adjustment>;
taxLines: Array<TaxLine>;
order: Order;
customFields?: Maybe<Scalars['JSON']>;
};
Expand Down
14 changes: 8 additions & 6 deletions packages/core/e2e/graphql/generated-e2e-admin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1817,13 +1817,7 @@ export enum GlobalFlag {
}

export enum AdjustmentType {
TAX = 'TAX',
PROMOTION = 'PROMOTION',
SHIPPING = 'SHIPPING',
REFUND = 'REFUND',
TAX_REFUND = 'TAX_REFUND',
PROMOTION_REFUND = 'PROMOTION_REFUND',
SHIPPING_REFUND = 'SHIPPING_REFUND',
}

export type Adjustment = {
Expand All @@ -1833,6 +1827,12 @@ export type Adjustment = {
amount: Scalars['Int'];
};

export type TaxLine = {
description: Scalars['String'];
amount: Scalars['Int'];
taxRate: Scalars['Float'];
};

export type ConfigArg = {
name: Scalars['String'];
value: Scalars['String'];
Expand Down Expand Up @@ -3200,6 +3200,7 @@ export type OrderItem = Node & {
unitPriceIncludesTax: Scalars['Boolean'];
taxRate: Scalars['Float'];
adjustments: Array<Adjustment>;
taxLines: Array<TaxLine>;
fulfillment?: Maybe<Fulfillment>;
refundId?: Maybe<Scalars['ID']>;
};
Expand All @@ -3224,6 +3225,7 @@ export type OrderLine = Node & {
/** The total price of the line including tax */
linePriceWithTax: Scalars['Int'];
adjustments: Array<Adjustment>;
taxLines: Array<TaxLine>;
order: Order;
customFields?: Maybe<Scalars['JSON']>;
};
Expand Down
26 changes: 18 additions & 8 deletions packages/core/e2e/graphql/generated-e2e-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,7 @@ export enum GlobalFlag {
}

export enum AdjustmentType {
TAX = 'TAX',
PROMOTION = 'PROMOTION',
SHIPPING = 'SHIPPING',
REFUND = 'REFUND',
TAX_REFUND = 'TAX_REFUND',
PROMOTION_REFUND = 'PROMOTION_REFUND',
SHIPPING_REFUND = 'SHIPPING_REFUND',
}

export type Adjustment = {
Expand All @@ -312,6 +306,12 @@ export type Adjustment = {
amount: Scalars['Int'];
};

export type TaxLine = {
description: Scalars['String'];
amount: Scalars['Int'];
taxRate: Scalars['Float'];
};

export type ConfigArg = {
name: Scalars['String'];
value: Scalars['String'];
Expand Down Expand Up @@ -2033,6 +2033,7 @@ export type OrderItem = Node & {
unitPriceIncludesTax: Scalars['Boolean'];
taxRate: Scalars['Float'];
adjustments: Array<Adjustment>;
taxLines: Array<TaxLine>;
fulfillment?: Maybe<Fulfillment>;
refundId?: Maybe<Scalars['ID']>;
};
Expand All @@ -2057,6 +2058,7 @@ export type OrderLine = Node & {
/** The total price of the line including tax */
linePriceWithTax: Scalars['Int'];
adjustments: Array<Adjustment>;
taxLines: Array<TaxLine>;
order: Order;
customFields?: Maybe<Scalars['JSON']>;
};
Expand Down Expand Up @@ -2687,11 +2689,11 @@ export type NativeAuthInput = {

export type TestOrderFragmentFragment = Pick<
Order,
'id' | 'code' | 'state' | 'active' | 'total' | 'couponCodes' | 'shipping'
'id' | 'code' | 'state' | 'active' | 'totalBeforeTax' | 'total' | 'couponCodes' | 'shipping'
> & {
adjustments: Array<Pick<Adjustment, 'adjustmentSource' | 'amount' | 'description' | 'type'>>;
lines: Array<
Pick<OrderLine, 'id' | 'quantity'> & {
Pick<OrderLine, 'id' | 'quantity' | 'linePrice' | 'linePriceWithTax'> & {
productVariant: Pick<ProductVariant, 'id'>;
adjustments: Array<Pick<Adjustment, 'adjustmentSource' | 'amount' | 'description' | 'type'>>;
}
Expand Down Expand Up @@ -2903,6 +2905,7 @@ export type GetActiveOrderWithPriceDataQuery = {
> & {
items: Array<Pick<OrderItem, 'id' | 'unitPrice' | 'unitPriceWithTax' | 'taxRate'>>;
adjustments: Array<Pick<Adjustment, 'amount' | 'type'>>;
taxLines: Array<Pick<TaxLine, 'amount' | 'taxRate' | 'description'>>;
}
>;
taxSummary: Array<Pick<OrderTaxSummary, 'taxRate' | 'taxBase' | 'taxTotal'>>;
Expand Down Expand Up @@ -3390,6 +3393,13 @@ export namespace GetActiveOrderWithPriceData {
>['adjustments']
>[number]
>;
export type TaxLines = NonNullable<
NonNullable<
NonNullable<
NonNullable<NonNullable<GetActiveOrderWithPriceDataQuery['activeOrder']>['lines']>[number]
>['taxLines']
>[number]
>;
export type TaxSummary = NonNullable<
NonNullable<NonNullable<GetActiveOrderWithPriceDataQuery['activeOrder']>['taxSummary']>[number]
>;
Expand Down
8 changes: 8 additions & 0 deletions packages/core/e2e/graphql/shop-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const TEST_ORDER_FRAGMENT = gql`
code
state
active
totalBeforeTax
total
couponCodes
adjustments {
Expand All @@ -17,6 +18,8 @@ export const TEST_ORDER_FRAGMENT = gql`
lines {
id
quantity
linePrice
linePriceWithTax
productVariant {
id
}
Expand Down Expand Up @@ -322,6 +325,11 @@ export const GET_ACTIVE_ORDER_WITH_PRICE_DATA = gql`
amount
type
}
taxLines {
amount
taxRate
description
}
}
taxSummary {
taxRate
Expand Down
Loading

0 comments on commit 2c71a82

Please sign in to comment.