Fix refunded value calculation in order view (#1601)
* Fix refunded value calculation in order view * Fix orders price alignment to right * Update test snapshots
This commit is contained in:
parent
f9a090ee47
commit
057940c99a
8 changed files with 636 additions and 610 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { makeStyles, Typography, TypographyProps } from "@material-ui/core";
|
import { makeStyles, Typography, TypographyProps } from "@material-ui/core";
|
||||||
import HorizontalSpacer from "@saleor/apps/components/HorizontalSpacer";
|
import HorizontalSpacer from "@saleor/apps/components/HorizontalSpacer";
|
||||||
|
import classNames from "classnames";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
export interface IMoney {
|
export interface IMoney {
|
||||||
|
@ -16,6 +17,9 @@ const useStyles = makeStyles(
|
||||||
container: {
|
container: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "baseline"
|
alignItems: "baseline"
|
||||||
|
},
|
||||||
|
containerRight: {
|
||||||
|
justifyContent: "end"
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
{ name: "Money" }
|
{ name: "Money" }
|
||||||
|
@ -29,7 +33,11 @@ export const Money: React.FC<MoneyProps> = ({ money, ...rest }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.container}>
|
<div
|
||||||
|
className={classNames(classes.container, {
|
||||||
|
[classes.containerRight]: rest.align === "right"
|
||||||
|
})}
|
||||||
|
>
|
||||||
<Typography variant="caption" {...rest}>
|
<Typography variant="caption" {...rest}>
|
||||||
{money.currency}
|
{money.currency}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
|
@ -132,7 +132,7 @@ const CustomerOrders: React.FC<CustomerOrdersProps> = props => {
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className={classes.textRight}>
|
<TableCell className={classes.textRight}>
|
||||||
{maybe(() => order.total.gross) ? (
|
{maybe(() => order.total.gross) ? (
|
||||||
<Money money={order.total.gross} />
|
<Money money={order.total.gross} align="right" />
|
||||||
) : (
|
) : (
|
||||||
<Skeleton />
|
<Skeleton />
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -211,7 +211,7 @@ export const OrderDraftList: React.FC<OrderDraftListProps> = props => {
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className={classes.colTotal}>
|
<TableCell className={classes.colTotal}>
|
||||||
{maybe(() => order.total.gross) ? (
|
{maybe(() => order.total.gross) ? (
|
||||||
<Money money={order.total.gross} />
|
<Money money={order.total.gross} align="right" />
|
||||||
) : (
|
) : (
|
||||||
<Skeleton />
|
<Skeleton />
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -248,7 +248,7 @@ export const OrderList: React.FC<OrderListProps> = props => {
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className={classes.colTotal}>
|
<TableCell className={classes.colTotal}>
|
||||||
{maybe(() => order.total.gross) ? (
|
{maybe(() => order.total.gross) ? (
|
||||||
<Money money={order.total.gross} />
|
<Money money={order.total.gross} align="right" />
|
||||||
) : (
|
) : (
|
||||||
<Skeleton />
|
<Skeleton />
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Button, Card, CardActions, CardContent } from "@material-ui/core";
|
import { Button, Card, CardActions, CardContent } from "@material-ui/core";
|
||||||
import CardTitle from "@saleor/components/CardTitle";
|
import CardTitle from "@saleor/components/CardTitle";
|
||||||
import { Hr } from "@saleor/components/Hr";
|
import { Hr } from "@saleor/components/Hr";
|
||||||
import Money, { subtractMoney } from "@saleor/components/Money";
|
import Money from "@saleor/components/Money";
|
||||||
import Skeleton from "@saleor/components/Skeleton";
|
import Skeleton from "@saleor/components/Skeleton";
|
||||||
import StatusLabel from "@saleor/components/StatusLabel";
|
import StatusLabel from "@saleor/components/StatusLabel";
|
||||||
import { makeStyles } from "@saleor/macaw-ui";
|
import { makeStyles } from "@saleor/macaw-ui";
|
||||||
|
@ -16,7 +16,11 @@ import {
|
||||||
} from "../../../types/globalTypes";
|
} from "../../../types/globalTypes";
|
||||||
import { OrderDetails_order } from "../../types/OrderDetails";
|
import { OrderDetails_order } from "../../types/OrderDetails";
|
||||||
import messages from "./messages";
|
import messages from "./messages";
|
||||||
import { extractOrderGiftCardUsedAmount } from "./utils";
|
import {
|
||||||
|
extractOrderGiftCardUsedAmount,
|
||||||
|
extractOutstandingBalance,
|
||||||
|
extractRefundedAmount
|
||||||
|
} from "./utils";
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
const useStyles = makeStyles(
|
||||||
theme => ({
|
theme => ({
|
||||||
|
@ -26,7 +30,8 @@ const useStyles = makeStyles(
|
||||||
width: "100%"
|
width: "100%"
|
||||||
},
|
},
|
||||||
textRight: {
|
textRight: {
|
||||||
textAlign: "right"
|
display: "flex",
|
||||||
|
justifyContent: "end"
|
||||||
},
|
},
|
||||||
totalRow: {
|
totalRow: {
|
||||||
fontWeight: 600
|
fontWeight: 600
|
||||||
|
@ -61,10 +66,9 @@ const OrderPayment: React.FC<OrderPaymentProps> = props => {
|
||||||
maybe(() => order.paymentStatus),
|
maybe(() => order.paymentStatus),
|
||||||
intl
|
intl
|
||||||
);
|
);
|
||||||
const refundedAmount =
|
const refundedAmount = extractRefundedAmount(order);
|
||||||
order?.totalCaptured &&
|
const outstandingBalance = extractOutstandingBalance(order);
|
||||||
order?.total?.gross &&
|
const usedGiftCardAmount = extractOrderGiftCardUsedAmount(order);
|
||||||
subtractMoney(order.totalCaptured, order.total.gross);
|
|
||||||
|
|
||||||
const getDeliveryMethodName = order => {
|
const getDeliveryMethodName = order => {
|
||||||
if (
|
if (
|
||||||
|
@ -87,8 +91,6 @@ const OrderPayment: React.FC<OrderPaymentProps> = props => {
|
||||||
return order.shippingMethodName;
|
return order.shippingMethodName;
|
||||||
};
|
};
|
||||||
|
|
||||||
const usedGiftCardAmount = extractOrderGiftCardUsedAmount(order);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardTitle
|
<CardTitle
|
||||||
|
@ -297,17 +299,10 @@ const OrderPayment: React.FC<OrderPaymentProps> = props => {
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td className={classes.textRight}>
|
<td className={classes.textRight}>
|
||||||
{maybe(
|
{outstandingBalance?.amount === undefined ? (
|
||||||
() => order.total.gross.amount && order.totalCaptured.amount
|
|
||||||
) === undefined ? (
|
|
||||||
<Skeleton />
|
<Skeleton />
|
||||||
) : (
|
) : (
|
||||||
<Money
|
<Money money={outstandingBalance} />
|
||||||
money={subtractMoney(
|
|
||||||
order.totalCaptured,
|
|
||||||
order.total.gross
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
|
import { IMoney, subtractMoney } from "@saleor/components/Money";
|
||||||
import { OrderDetails_order } from "@saleor/orders/types/OrderDetails";
|
import { OrderDetails_order } from "@saleor/orders/types/OrderDetails";
|
||||||
import { GiftCardEventsEnum } from "@saleor/types/globalTypes";
|
import {
|
||||||
|
GiftCardEventsEnum,
|
||||||
|
PaymentChargeStatusEnum
|
||||||
|
} from "@saleor/types/globalTypes";
|
||||||
import compact from "lodash/compact";
|
import compact from "lodash/compact";
|
||||||
|
|
||||||
export const extractOrderGiftCardUsedAmount = (
|
export const extractOrderGiftCardUsedAmount = (
|
||||||
|
@ -32,3 +36,23 @@ export const extractOrderGiftCardUsedAmount = (
|
||||||
return resultAmount + amountToAdd;
|
return resultAmount + amountToAdd;
|
||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const extractOutstandingBalance = (order: OrderDetails_order): IMoney =>
|
||||||
|
order?.totalCaptured &&
|
||||||
|
order?.total?.gross &&
|
||||||
|
subtractMoney(order.total.gross, order.totalCaptured);
|
||||||
|
|
||||||
|
export const extractRefundedAmount = (order: OrderDetails_order): IMoney => {
|
||||||
|
if (order?.paymentStatus === PaymentChargeStatusEnum.FULLY_REFUNDED) {
|
||||||
|
return order?.total?.gross;
|
||||||
|
}
|
||||||
|
if (order?.paymentStatus === PaymentChargeStatusEnum.PARTIALLY_REFUNDED) {
|
||||||
|
return extractOutstandingBalance(order);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
order?.total?.gross && {
|
||||||
|
amount: 0,
|
||||||
|
currency: order.total.gross.currency
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -20,7 +20,6 @@ const useStyles = makeStyles(
|
||||||
marginLeft: AVATAR_MARGIN
|
marginLeft: AVATAR_MARGIN
|
||||||
},
|
},
|
||||||
colPrice: {
|
colPrice: {
|
||||||
textAlign: "right",
|
|
||||||
width: 120
|
width: 120
|
||||||
},
|
},
|
||||||
colQuantity: {
|
colQuantity: {
|
||||||
|
@ -33,7 +32,6 @@ const useStyles = makeStyles(
|
||||||
width: 120
|
width: 120
|
||||||
},
|
},
|
||||||
colTotal: {
|
colTotal: {
|
||||||
textAlign: "right",
|
|
||||||
width: 120
|
width: 120
|
||||||
},
|
},
|
||||||
infoLabel: {
|
infoLabel: {
|
||||||
|
@ -100,7 +98,7 @@ const TableLine: React.FC<TableLineProps> = ({
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className={classes.colPrice}>
|
<TableCell className={classes.colPrice}>
|
||||||
{maybe(() => line.orderLine.unitPrice.gross) ? (
|
{maybe(() => line.orderLine.unitPrice.gross) ? (
|
||||||
<Money money={line.orderLine.unitPrice.gross} />
|
<Money money={line.orderLine.unitPrice.gross} align="right" />
|
||||||
) : (
|
) : (
|
||||||
<Skeleton />
|
<Skeleton />
|
||||||
)}
|
)}
|
||||||
|
@ -111,6 +109,7 @@ const TableLine: React.FC<TableLineProps> = ({
|
||||||
amount: line.quantity * line.orderLine.unitPrice.gross.amount,
|
amount: line.quantity * line.orderLine.unitPrice.gross.amount,
|
||||||
currency: line.orderLine.unitPrice.gross.currency
|
currency: line.orderLine.unitPrice.gross.currency
|
||||||
}}
|
}}
|
||||||
|
align="right"
|
||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue