fix(medusa): Rounding issues on line item adjustments (#3446)

* chores(medusa): Attempt to fix discount rounding issues

* add migration

* update entities

* apply multipler factor properly

* fix discount service

* WIP

* fix rounding issues in discounts

* fix some tests

* Exclude raw_discount_total from responses

* fix adjustments

* cleanup response

* fix

* fix draft order integration

* fix order integration

* fix order integration

* address feedback

* fix test

* Create .changeset/polite-llamas-sit.md

* remove comment

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Adrien de Peretti
2023-03-29 11:04:41 +02:00
committed by GitHub
parent 577098a4db
commit d886430bf8
86 changed files with 720 additions and 175 deletions

View File

@@ -572,11 +572,10 @@ describe("/admin/draft-orders", () => {
(item) => item.variant_id === testVariant2Id
)
const lineItem1WeightInTotal = 0.444 // line item amount / amount
const lineItem2WeightInTotal = 0.556 // line item amount / amount
expect(draftOrder.cart.items).toHaveLength(2)
expect(lineItem1.adjustments).toHaveLength(1)
expect(lineItem1.adjustments[0].amount).toBeCloseTo(444, 0) // discountAmount * (line item amount / amount) = 444.4444444444
expect(lineItem1).toEqual(
expect.objectContaining({
variant_id: testVariantId,
@@ -585,7 +584,6 @@ describe("/admin/draft-orders", () => {
adjustments: expect.arrayContaining([
expect.objectContaining({
item_id: lineItem1.id,
amount: discountAmount * lineItem1WeightInTotal,
description: "discount",
discount_id: discount.id,
}),
@@ -593,6 +591,8 @@ describe("/admin/draft-orders", () => {
})
)
expect(lineItem2.adjustments).toHaveLength(1)
expect(lineItem2.adjustments[0].amount).toBeCloseTo(556, 0) // discountAmount * (line item amount / amount) = 555.5555555555
expect(lineItem2).toEqual(
expect.objectContaining({
variant_id: testVariant2Id,
@@ -601,7 +601,6 @@ describe("/admin/draft-orders", () => {
adjustments: expect.arrayContaining([
expect.objectContaining({
item_id: lineItem2.id,
amount: discountAmount * lineItem2WeightInTotal,
description: "discount",
discount_id: discount.id,
}),