feat(medusa): Add item and shipping tax totals to order (#5385)
* Expose item tax total and shipping tax total in order totals * Added changeset * Fixes to tests * Fixes to integration tests * Fixes to integration tests * Fixes to integration tests * Change changeset to patch
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Expose item tax total and shipping tax total
|
||||||
@@ -1616,7 +1616,9 @@ describe("/admin/orders", () => {
|
|||||||
first_name: "lebron",
|
first_name: "lebron",
|
||||||
}),
|
}),
|
||||||
shipping_total: expect.any(Number),
|
shipping_total: expect.any(Number),
|
||||||
|
shipping_tax_total: expect.any(Number),
|
||||||
discount_total: expect.any(Number),
|
discount_total: expect.any(Number),
|
||||||
|
item_tax_total: expect.any(Number),
|
||||||
tax_total: expect.any(Number),
|
tax_total: expect.any(Number),
|
||||||
refunded_total: expect.any(Number),
|
refunded_total: expect.any(Number),
|
||||||
total: expect.any(Number),
|
total: expect.any(Number),
|
||||||
@@ -2448,7 +2450,9 @@ describe("/admin/orders", () => {
|
|||||||
id: "test-order",
|
id: "test-order",
|
||||||
region: expect.any(Object),
|
region: expect.any(Object),
|
||||||
shipping_total: 1000,
|
shipping_total: 1000,
|
||||||
|
shipping_tax_total: 0,
|
||||||
discount_total: 800,
|
discount_total: 800,
|
||||||
|
item_tax_total: 0,
|
||||||
tax_total: 0,
|
tax_total: 0,
|
||||||
refunded_total: 0,
|
refunded_total: 0,
|
||||||
total: 8200,
|
total: 8200,
|
||||||
@@ -2491,7 +2495,9 @@ describe("/admin/orders", () => {
|
|||||||
sales_channel_id: null,
|
sales_channel_id: null,
|
||||||
returnable_items: expect.any(Array),
|
returnable_items: expect.any(Array),
|
||||||
shipping_total: 1000,
|
shipping_total: 1000,
|
||||||
|
shipping_tax_total: 0,
|
||||||
discount_total: 800,
|
discount_total: 800,
|
||||||
|
item_tax_total: 0,
|
||||||
tax_total: 0,
|
tax_total: 0,
|
||||||
refunded_total: 0,
|
refunded_total: 0,
|
||||||
total: 8200,
|
total: 8200,
|
||||||
@@ -2517,7 +2523,9 @@ describe("/admin/orders", () => {
|
|||||||
id: "test-order",
|
id: "test-order",
|
||||||
returnable_items: expect.any(Array),
|
returnable_items: expect.any(Array),
|
||||||
shipping_total: 1000,
|
shipping_total: 1000,
|
||||||
|
shipping_tax_total: 0,
|
||||||
discount_total: 800,
|
discount_total: 800,
|
||||||
|
item_tax_total: 0,
|
||||||
tax_total: 0,
|
tax_total: 0,
|
||||||
refunded_total: 0,
|
refunded_total: 0,
|
||||||
total: 8200,
|
total: 8200,
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ describe("/store/carts", () => {
|
|||||||
"/store/orders?display_id=111&email=test@email.com&fields=status,email"
|
"/store/orders?display_id=111&email=test@email.com&fields=status,email"
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(Object.keys(response.data.order)).toHaveLength(20)
|
expect(Object.keys(response.data.order)).toHaveLength(22)
|
||||||
expect(Object.keys(response.data.order)).toEqual(
|
expect(Object.keys(response.data.order)).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
// fields
|
// fields
|
||||||
@@ -252,7 +252,7 @@ describe("/store/carts", () => {
|
|||||||
|
|
||||||
const response = await api.get("/store/orders/order_test?fields=status")
|
const response = await api.get("/store/orders/order_test?fields=status")
|
||||||
|
|
||||||
expect(Object.keys(response.data.order)).toHaveLength(19)
|
expect(Object.keys(response.data.order)).toHaveLength(21)
|
||||||
expect(Object.keys(response.data.order)).toEqual(
|
expect(Object.keys(response.data.order)).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
// fields
|
// fields
|
||||||
@@ -308,6 +308,8 @@ describe("/store/carts", () => {
|
|||||||
"refundable_amount",
|
"refundable_amount",
|
||||||
"gift_card_total",
|
"gift_card_total",
|
||||||
"gift_card_tax_total",
|
"gift_card_tax_total",
|
||||||
|
"item_tax_total",
|
||||||
|
"shipping_tax_total",
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -240,8 +240,10 @@ export class Order extends BaseEntity {
|
|||||||
|
|
||||||
// Total fields
|
// Total fields
|
||||||
shipping_total: number
|
shipping_total: number
|
||||||
|
shipping_tax_total: number | null
|
||||||
discount_total: number
|
discount_total: number
|
||||||
raw_discount_total: number
|
raw_discount_total: number
|
||||||
|
item_tax_total: number | null
|
||||||
tax_total: number | null
|
tax_total: number | null
|
||||||
refunded_total: number
|
refunded_total: number
|
||||||
total: number
|
total: number
|
||||||
|
|||||||
@@ -1353,6 +1353,7 @@ describe("OrderService", () => {
|
|||||||
gift_card_total: 0,
|
gift_card_total: 0,
|
||||||
id: IdMap.getId("order"),
|
id: IdMap.getId("order"),
|
||||||
items: [],
|
items: [],
|
||||||
|
item_tax_total: 0,
|
||||||
paid_total: 0,
|
paid_total: 0,
|
||||||
raw_discount_total: 0,
|
raw_discount_total: 0,
|
||||||
refundable_amount: 0,
|
refundable_amount: 0,
|
||||||
@@ -1365,6 +1366,7 @@ describe("OrderService", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
shipping_total: 0,
|
shipping_total: 0,
|
||||||
|
shipping_tax_total: 0,
|
||||||
subtotal: 0,
|
subtotal: 0,
|
||||||
tax_total: 0,
|
tax_total: 0,
|
||||||
total: 0,
|
total: 0,
|
||||||
@@ -1393,6 +1395,7 @@ describe("OrderService", () => {
|
|||||||
gift_card_total: 0,
|
gift_card_total: 0,
|
||||||
id: IdMap.getId("order"),
|
id: IdMap.getId("order"),
|
||||||
items: [],
|
items: [],
|
||||||
|
item_tax_total: 0,
|
||||||
paid_total: 0,
|
paid_total: 0,
|
||||||
raw_discount_total: 0,
|
raw_discount_total: 0,
|
||||||
refundable_amount: 0,
|
refundable_amount: 0,
|
||||||
@@ -1405,6 +1408,7 @@ describe("OrderService", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
shipping_total: 0,
|
shipping_total: 0,
|
||||||
|
shipping_tax_total: 0,
|
||||||
subtotal: 0,
|
subtotal: 0,
|
||||||
tax_total: 0,
|
tax_total: 0,
|
||||||
total: 0,
|
total: 0,
|
||||||
|
|||||||
@@ -1909,8 +1909,12 @@ class OrderService extends TransactionBaseService {
|
|||||||
order.gift_card_total = giftCardTotal.total || 0
|
order.gift_card_total = giftCardTotal.total || 0
|
||||||
order.gift_card_tax_total = giftCardTotal.tax_total || 0
|
order.gift_card_tax_total = giftCardTotal.tax_total || 0
|
||||||
|
|
||||||
|
order.item_tax_total = item_tax_total
|
||||||
|
order.shipping_tax_total = shipping_tax_total
|
||||||
order.tax_total =
|
order.tax_total =
|
||||||
item_tax_total + shipping_tax_total - order.gift_card_tax_total
|
order.item_tax_total +
|
||||||
|
order.shipping_tax_total -
|
||||||
|
order.gift_card_tax_total
|
||||||
|
|
||||||
for (const swap of order.swaps ?? []) {
|
for (const swap of order.swaps ?? []) {
|
||||||
swap.additional_items = swap.additional_items.map((item) => {
|
swap.additional_items = swap.additional_items.map((item) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user