fix(utils,medusa,order,cart): fix totals when promotions are included (#9014)

* fix(utils): fix totals when promotions are included

* chore: update totals calc

* chore: ignore taxes when taxable amount is 0

* chore: use subtotals everywhere

* chore: fix shipping totals + tests
This commit is contained in:
Riqwan Thamir
2024-09-10 10:59:22 +02:00
committed by GitHub
parent 3244067ee4
commit afd0921326
12 changed files with 378 additions and 359 deletions
@@ -2548,6 +2548,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
total: 0,
original_total: 100,
discount_total: 100,
discount_subtotal: 100,
discount_tax_total: 0,
tax_total: 0,
original_tax_total: 0,
@@ -2567,6 +2568,10 @@ moduleIntegrationTestRunner<ICartModuleService>({
value: "100",
precision: 20,
},
raw_discount_subtotal: {
value: "100",
precision: 20,
},
raw_discount_tax_total: {
value: "0",
precision: 20,
@@ -2647,6 +2652,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
total: 200,
original_total: 400,
discount_total: 200,
discount_subtotal: 200,
discount_tax_total: 0,
tax_total: 0,
original_tax_total: 0,
@@ -2666,6 +2672,10 @@ moduleIntegrationTestRunner<ICartModuleService>({
value: "200",
precision: 20,
},
raw_discount_subtotal: {
value: "200",
precision: 20,
},
raw_discount_tax_total: {
value: "0",
precision: 20,
@@ -2704,6 +2714,7 @@ moduleIntegrationTestRunner<ICartModuleService>({
total: 10,
original_total: 10,
discount_total: 0,
discount_subtotal: 0,
discount_tax_total: 0,
tax_total: 0,
original_tax_total: 0,
@@ -2723,6 +2734,10 @@ moduleIntegrationTestRunner<ICartModuleService>({
value: "0",
precision: 20,
},
raw_discount_subtotal: {
value: "0",
precision: 20,
},
raw_discount_tax_total: {
value: "0",
precision: 20,
@@ -2741,8 +2756,9 @@ moduleIntegrationTestRunner<ICartModuleService>({
subtotal: 510,
tax_total: 0,
discount_total: 300,
discount_subtotal: 300,
discount_tax_total: 0,
original_total: 210,
original_total: 510,
original_tax_total: 0,
item_total: 200,
item_subtotal: 500,
@@ -2772,12 +2788,16 @@ moduleIntegrationTestRunner<ICartModuleService>({
value: "300",
precision: 20,
},
raw_discount_subtotal: {
value: "300",
precision: 20,
},
raw_discount_tax_total: {
value: "0",
precision: 20,
},
raw_original_total: {
value: "210",
value: "510",
precision: 20,
},
raw_original_tax_total: {
@@ -211,7 +211,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
expect(created.summary).toEqual(
expect.objectContaining({
transaction_total: 68,
pending_difference: -20.21999000999001,
pending_difference: -20.10799200799201,
paid_total: 68,
refunded_total: 0,
})
@@ -236,7 +236,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
expect(serializedOrder.summary).toEqual(
expect.objectContaining({
transaction_total: 48,
pending_difference: -0.21999000999001,
pending_difference: -0.10799200799201,
paid_total: 68,
refunded_total: 20,
})
@@ -255,7 +255,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
expect(serializedOrder2.summary).toEqual(
expect.objectContaining({
transaction_total: 68,
pending_difference: -20.21999000999001,
pending_difference: -20.10799200799201,
paid_total: 68,
refunded_total: 0,
})
@@ -282,7 +282,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
paid_total: 68,
refunded_total: 50,
transaction_total: 18,
pending_difference: 29.78000999000999,
pending_difference: 29.89200799200799,
})
)
@@ -301,7 +301,7 @@ moduleIntegrationTestRunner<IOrderModuleService>({
paid_total: 68,
refunded_total: 70,
transaction_total: -2,
pending_difference: 49.78000999000999,
pending_difference: 49.89200799200799,
})
)
})