fix(utils,core-flows): subtotal calculation and returns location (#13497)
* fix(utils,core-flows): subtotal calculation and returns location * changeset * fix test * var * rm extra field from test * fix original total * fix partial refunds and pending difference * fix test * fix test * test * extract to util * original total and update payment when receive return * original_subtotal * default fields * test * calculate pending difference * revert claims test * pending difference * creadit line fix * if
This commit is contained in:
committed by
GitHub
parent
4736c58da5
commit
9563ee446f
@@ -2934,6 +2934,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
||||
subtotal: 100,
|
||||
total: 0,
|
||||
original_total: 100,
|
||||
original_subtotal: 100,
|
||||
discount_total: 100,
|
||||
discount_subtotal: 100,
|
||||
discount_tax_total: 0,
|
||||
@@ -2951,6 +2952,10 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
||||
value: "100",
|
||||
precision: 20,
|
||||
},
|
||||
raw_original_subtotal: {
|
||||
value: "100",
|
||||
precision: 20,
|
||||
},
|
||||
raw_discount_total: {
|
||||
value: "100",
|
||||
precision: 20,
|
||||
@@ -3042,6 +3047,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
||||
subtotal: 400,
|
||||
total: 200,
|
||||
original_total: 400,
|
||||
original_subtotal: 400,
|
||||
discount_total: 200,
|
||||
discount_subtotal: 200,
|
||||
discount_tax_total: 0,
|
||||
@@ -3059,6 +3065,10 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
||||
value: "400",
|
||||
precision: 20,
|
||||
},
|
||||
raw_original_subtotal: {
|
||||
value: "400",
|
||||
precision: 20,
|
||||
},
|
||||
raw_discount_total: {
|
||||
value: "200",
|
||||
precision: 20,
|
||||
@@ -3104,6 +3114,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
||||
subtotal: 10,
|
||||
total: 10,
|
||||
original_total: 10,
|
||||
original_subtotal: 10,
|
||||
discount_total: 0,
|
||||
discount_subtotal: 0,
|
||||
discount_tax_total: 0,
|
||||
@@ -3121,6 +3132,10 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
||||
value: "10",
|
||||
precision: 20,
|
||||
},
|
||||
raw_original_subtotal: {
|
||||
value: "10",
|
||||
precision: 20,
|
||||
},
|
||||
raw_discount_total: {
|
||||
value: "0",
|
||||
precision: 20,
|
||||
@@ -3166,6 +3181,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
||||
discount_subtotal: 300,
|
||||
discount_tax_total: 0,
|
||||
original_total: 510,
|
||||
original_subtotal: 510,
|
||||
original_tax_total: 0,
|
||||
item_total: 200,
|
||||
item_subtotal: 500,
|
||||
@@ -3217,6 +3233,10 @@ moduleIntegrationTestRunner<ICartModuleService>({
|
||||
value: "510",
|
||||
precision: 20,
|
||||
},
|
||||
raw_original_subtotal: {
|
||||
value: "510",
|
||||
precision: 20,
|
||||
},
|
||||
raw_original_tax_total: {
|
||||
value: "0",
|
||||
precision: 20,
|
||||
|
||||
@@ -227,7 +227,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
const serializedOrder = JSON.parse(
|
||||
JSON.stringify(
|
||||
await service.retrieveOrder(created.id, {
|
||||
select: ["id", "summary"],
|
||||
select: ["id", "summary", "total"],
|
||||
})
|
||||
)
|
||||
)
|
||||
@@ -246,7 +246,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
const serializedOrder2 = JSON.parse(
|
||||
JSON.stringify(
|
||||
await service.retrieveOrder(created.id, {
|
||||
select: ["id", "summary"],
|
||||
select: ["id", "summary", "total"],
|
||||
})
|
||||
)
|
||||
)
|
||||
@@ -271,7 +271,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
const serializedOrder3 = JSON.parse(
|
||||
JSON.stringify(
|
||||
await service.retrieveOrder(created.id, {
|
||||
select: ["id", "summary"],
|
||||
select: ["id", "summary", "total"],
|
||||
})
|
||||
)
|
||||
)
|
||||
@@ -290,7 +290,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
const serializedOrder4 = JSON.parse(
|
||||
JSON.stringify(
|
||||
await service.retrieveOrder(created.id, {
|
||||
select: ["id", "summary"],
|
||||
select: ["id", "summary", "total"],
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
@@ -414,7 +414,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
})
|
||||
|
||||
const changedOrder = await service.retrieveOrder(createdOrder.id, {
|
||||
select: ["total", "items.detail", "summary"],
|
||||
select: ["total", "items.detail", "summary", "total"],
|
||||
relations: ["items"],
|
||||
})
|
||||
|
||||
@@ -492,7 +492,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
|
||||
})
|
||||
|
||||
const modified = await service.retrieveOrder(createdOrder.id, {
|
||||
select: ["total", "items.detail", "summary"],
|
||||
select: ["total", "items.detail", "summary", "total"],
|
||||
relations: ["items"],
|
||||
})
|
||||
|
||||
|
||||
@@ -358,6 +358,7 @@ export default class OrderModuleService
|
||||
"discount_tax_total",
|
||||
"original_total",
|
||||
"original_tax_total",
|
||||
"pending_difference",
|
||||
"item_total",
|
||||
"item_subtotal",
|
||||
"item_tax_total",
|
||||
@@ -370,9 +371,13 @@ export default class OrderModuleService
|
||||
"original_shipping_tax_total",
|
||||
"original_shipping_subtotal",
|
||||
"original_shipping_total",
|
||||
"original_total",
|
||||
"original_subtotal",
|
||||
"original_tax_total",
|
||||
"credit_line_total",
|
||||
"credit_line_tax_total",
|
||||
"credit_line_subtotal",
|
||||
"refundable_amount",
|
||||
]
|
||||
|
||||
const includeTotals = (config?.select ?? []).some((field) =>
|
||||
|
||||
@@ -224,7 +224,7 @@ export class OrderChangeProcessing {
|
||||
return orderSummary
|
||||
}
|
||||
|
||||
// Calculate the order summary from a calculated order including taxes
|
||||
// Returns the order summary from a calculated order including taxes
|
||||
public getSummaryFromOrder(order: OrderDTO): OrderSummaryDTO {
|
||||
const summary_ = this.summary
|
||||
const total = order.total
|
||||
@@ -241,35 +241,6 @@ export class OrderChangeProcessing {
|
||||
|
||||
orderSummary.accounting_total = orderSummary.current_order_total
|
||||
|
||||
orderSummary.pending_difference = MathBN.sub(
|
||||
orderSummary.current_order_total,
|
||||
orderSummary.transaction_total
|
||||
)
|
||||
|
||||
// return total becomes pending difference
|
||||
for (const item of order.items ?? []) {
|
||||
const item_ = item as any
|
||||
|
||||
;[
|
||||
"return_requested_total",
|
||||
"return_received_total",
|
||||
// TODO: revisit this when we settle on which dismissed items need to be refunded
|
||||
// "return_dismissed_total",
|
||||
].forEach((returnTotalKey) => {
|
||||
const returnTotal = item_[returnTotalKey]
|
||||
|
||||
if (MathBN.gt(returnTotal, 0)) {
|
||||
orderSummary.pending_difference = MathBN.sub(
|
||||
orderSummary.pending_difference,
|
||||
returnTotal
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
orderSummary.pending_difference = new BigNumber(
|
||||
orderSummary.pending_difference
|
||||
)
|
||||
|
||||
return orderSummary
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user