Skip to content

Commit

Permalink
fix(order): calculate taxes on order edit flows (#11518)
Browse files Browse the repository at this point in the history
* fix(order): calcualte taxes on order edit flows

* merge summary

* tests

* fix pending difference

* comments

* claim test

* revert method
  • Loading branch information
carlos-r-l-rodrigues authored Feb 21, 2025
1 parent 065df75 commit 0c95735
Show file tree
Hide file tree
Showing 19 changed files with 500 additions and 441 deletions.
6 changes: 6 additions & 0 deletions .changeset/silent-tables-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/order": patch
"@medusajs/types": patch
---

fix(order): order edit flows with calculated taxes
11 changes: 5 additions & 6 deletions integration-tests/http/__tests__/claims/claims.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ medusaIntegrationTestRunner({
expect(orderResult.summary).toEqual(
expect.objectContaining({
paid_total: 61,
difference_sum: 0,
refunded_total: 0,
transaction_total: 61,
pending_difference: 0,
Expand Down Expand Up @@ -732,7 +731,7 @@ medusaIntegrationTestRunner({
expect(paymentCollections[0]).toEqual(
expect.objectContaining({
status: "not_paid",
amount: 109.5,
amount: 113.21,
currency_code: "usd",
})
)
Expand Down Expand Up @@ -776,7 +775,7 @@ medusaIntegrationTestRunner({
})

it("should create a payment collection successfully & mark as paid", async () => {
const paymentDelta = 109.5
const paymentDelta = 113.21
const orderForPayment = (
await api.get(`/admin/orders/${order.id}`, adminHeaders)
).data.order
Expand Down Expand Up @@ -1182,9 +1181,9 @@ medusaIntegrationTestRunner({

expect(orderCheck.summary).toEqual(
expect.objectContaining({
pending_difference: -11,
current_order_total: 50,
original_order_total: 60,
pending_difference: -9.7,
current_order_total: 76.3,
original_order_total: 61,
})
)

Expand Down
12 changes: 6 additions & 6 deletions integration-tests/http/__tests__/order-edits/order-edits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ medusaIntegrationTestRunner({
)
).data.order_preview

expect(result.summary.current_order_total).toEqual(84)
expect(result.summary.current_order_total).toEqual(86.4)
expect(result.summary.original_order_total).toEqual(60)

// Update item quantity and unit_price with the same amount as we have originally should not change totals
Expand All @@ -383,7 +383,7 @@ medusaIntegrationTestRunner({
)
).data.order_preview

expect(result.summary.current_order_total).toEqual(84)
expect(result.summary.current_order_total).toEqual(86.4)
expect(result.summary.original_order_total).toEqual(60)

// Update item quantity, but keep the price as it was originally, should add + 25 to previous amount
Expand All @@ -398,7 +398,7 @@ medusaIntegrationTestRunner({
)
).data.order_preview

expect(result.summary.current_order_total).toEqual(109)
expect(result.summary.current_order_total).toEqual(111.4)
expect(result.summary.original_order_total).toEqual(60)

// Update item quantity, with a new price
Expand All @@ -417,7 +417,7 @@ medusaIntegrationTestRunner({
)
).data.order_preview

expect(result.summary.current_order_total).toEqual(124)
expect(result.summary.current_order_total).toEqual(126.4)
expect(result.summary.original_order_total).toEqual(60)

const updatedItem = result.items.find((i) => i.id === item.id)
Expand Down Expand Up @@ -456,7 +456,7 @@ medusaIntegrationTestRunner({
)
).data.order_preview

expect(result.summary.current_order_total).toEqual(34)
expect(result.summary.current_order_total).toEqual(36.4)
expect(result.summary.original_order_total).toEqual(60)
expect(result.items.length).toEqual(2)

Expand All @@ -469,7 +469,7 @@ medusaIntegrationTestRunner({
).data.order_preview

expect(result.order_change.status).toEqual(OrderChangeStatus.REQUESTED)
expect(result.summary.current_order_total).toEqual(34)
expect(result.summary.current_order_total).toEqual(36.4)
expect(result.summary.original_order_total).toEqual(60)
expect(result.items.length).toEqual(2)

Expand Down
3 changes: 0 additions & 3 deletions integration-tests/http/__tests__/order/admin/order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ medusaIntegrationTestRunner({
status: "canceled",

summary: expect.objectContaining({
credit_line_total: 106,
current_order_total: 0,
accounting_total: 0,
}),
Expand Down Expand Up @@ -448,7 +447,6 @@ medusaIntegrationTestRunner({
status: "canceled",

summary: expect.objectContaining({
credit_line_total: 106,
current_order_total: 0,
accounting_total: 0,
}),
Expand Down Expand Up @@ -518,7 +516,6 @@ medusaIntegrationTestRunner({
status: "canceled",

summary: expect.objectContaining({
credit_line_total: 106,
current_order_total: 0,
accounting_total: 0,
}),
Expand Down
Loading

0 comments on commit 0c95735

Please sign in to comment.