Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add address and customer metadata to tax calc context #10122

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
updateLineItemInCartWorkflow,
updateLineItemsStepId,
updatePaymentCollectionStepId,
updateTaxLinesWorkflow,
} from "@medusajs/core-flows"
import {
ICartModuleService,
Expand Down Expand Up @@ -2159,6 +2160,44 @@ medusaIntegrationTestRunner({
])
})
})

describe("updateTaxLinesWorkflow", () => {
it("should create a payment collection and link it to cart", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it("should create a payment collection and link it to cart", async () => {
it("should include shipping address metadata in tax calculation context", async () => {

const cart = await cartModuleService.createCarts({
currency_code: "dkk",
region_id: defaultRegion.id,
shipping_address: {
metadata: {
testing_tax: true,
},
},
items: [
{
quantity: 1,
unit_price: 5000,
title: "Test item",
},
],
})

const { transaction } = await updateTaxLinesWorkflow(
appContainer
).run({
input: {
cart_id: cart.id,
},
throwOnError: false,
})

expect(
// @ts-ignore
transaction.context.invoke["use-remote-query"].output.output
.shipping_address.metadata
).toEqual({
testing_tax: true,
})
})
})
})
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const cartFields = [
"shipping_methods.amount",
"customer.id",
"customer.email",
"customer.metadata",
"customer.groups.id",
"shipping_address.id",
"shipping_address.address_1",
Expand All @@ -56,6 +57,7 @@ const cartFields = [
"shipping_address.country_code",
"shipping_address.region_code",
"shipping_address.province",
"shipping_address.metadata",
]

export type UpdateTaxLinesWorkflowInput = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function normalizeTaxModuleContext(
id: orderOrCart.customer.id,
email: orderOrCart.customer.email,
customer_groups: orderOrCart.customer.groups?.map((g) => g.id) || [],
metadata: orderOrCart.customer.metadata,
}

return {
Expand All @@ -63,6 +64,7 @@ function normalizeTaxModuleContext(
address_2: address.address_2,
city: address.city,
postal_code: address.postal_code,
metadata: address.metadata,
},
customer,
is_return: isReturn ?? false,
Expand Down
10 changes: 10 additions & 0 deletions packages/core/types/src/tax/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ export interface TaxCalculationContext {
* The postal code.
*/
postal_code?: string

/**
* Address metadata.
*/
metadata?: Record<string, unknown> | null
}

/**
Expand All @@ -468,6 +473,11 @@ export interface TaxCalculationContext {
* The groups that the customer belongs to.
*/
customer_groups: string[]

/**
* Customer metadata.
*/
metadata?: Record<string, unknown> | null
}

/**
Expand Down
Loading