feat(core-flows,types,utils,medusa): Translate tax lines (#14359)

* Include locale field for traslations on tax line workflows

* Translate tax lines in getItemTaxLinesStep with new util

* Update tax calculation context, so that we pass locale to third party tax providers if they want to return translated tax rates

* Apply translations to tax lines on product and variant tax middlewares

* Cart management translations tests

* Update tax lines when order locale gets updated

* Add changeset

* Get tranlsated tax lines step

* Fix wording

* Mutate ref directly

* Update order tax lines translations upon order locale change

* Claims translations tests

* Update tax lines upon draft order locale update

* Exchange tests for tax lines translations

* Order edits test for tax line translation

* Add tests for shipping methods tax line translations on various order flows

* Returns shipping method translations tests

* Execute update in parallel

* Use TranslationFeatureFlag.key

* Fix feature flag import

* Add @medusajs/medusa dependency for feature flag usage

* Revert "Add @medusajs/medusa dependency for feature flag usage"

This reverts commit e8897aed0a88f83c1034ac73e817e4222250a2c9.

* Use feature flag string directly

* Fix test

* Parallelize tax line translations application
This commit is contained in:
Nicolas Gorga authored and GitHub committed 2026-01-13 15:12:42 -03:00
1 parent 28fae96cee
commit cec8b8e428
23 files changed
+2032 -164

No files matched your search

@@ -35,13 +35,16 @@ medusaIntegrationTestRunner({
let shippingOption: { id: string }
let additionalShippingOption: { id: string }
let inventoryItem: { id: string }
let taxRate: { id: string }
beforeAll(async () => {
appContainer = getContainer()
})
beforeEach(async () => {
await setupTaxStructure(appContainer.resolve(Modules.TAX))
const taxStructure = await setupTaxStructure(
appContainer.resolve(Modules.TAX)
)
await createAdminUser(dbConnection, adminHeaders, appContainer)
const publishableKey = await generatePublishableKey(appContainer)
storeHeaders = generateStoreHeaders({ publishableKey })
@@ -217,6 +220,13 @@ medusaIntegrationTestRunner({
adminHeaders
)
).data.shipping_option
const taxRatesResponse = await api.get(
`/admin/tax-rates?tax_region_id=${taxStructure.us.children.cal.province.id}`,
adminHeaders
)
taxRate = taxRatesResponse.data.tax_rates.find(
(rate: { code: string }) => rate.code === "CADEFAULT"
)
await api.post(
"/admin/translations/batch",
@@ -296,6 +306,22 @@ medusaIntegrationTestRunner({
name: "Zusätzliche Versandoption",
},
},
{
reference_id: taxRate.id,
reference: "tax_rate",
locale_code: "fr-FR",
translations: {
name: "Taux par défaut CA",
},
},
{
reference_id: taxRate.id,
reference: "tax_rate",
locale_code: "de-DE",
translations: {
name: "CA Standardsteuersatz",
},
},
],
},
adminHeaders
@@ -386,6 +412,12 @@ medusaIntegrationTestRunner({
variant_title: "Moyen",
})
)
expect(newItem.tax_lines.length).toBeGreaterThan(0)
const taxLine = newItem.tax_lines.find(
(tl) => tl.code === "CADEFAULT"
)
expect(taxLine.description).toEqual("Taux par défaut CA")
})
it("should have original values when order has no locale", async () => {
@@ -426,46 +458,12 @@ medusaIntegrationTestRunner({
variant_title: "Medium",
})
)
})
it("should translate items using German locale", async () => {
const order = await createOrderFromCart("de-DE")
await api.post(
"/admin/order-edits",
{ order_id: order.id },
adminHeaders
)
await api.post(
`/admin/order-edits/${order.id}/items`,
{
items: [{ variant_id: product.variants[1].id, quantity: 1 }],
},
adminHeaders
)
await api.post(
`/admin/order-edits/${order.id}/confirm`,
{},
adminHeaders
)
const updatedOrder = (
await api.get(`/admin/orders/${order.id}`, adminHeaders)
).data.order
const newItem = updatedOrder.items.find(
(item) => item.variant_id === product.variants[1].id
)
expect(newItem).toEqual(
expect.objectContaining({
product_title: "Medusa T-Shirt DE",
product_description: "Ein bequemes Baumwoll-T-Shirt",
variant_title: "Mittel",
})
expect(newItem.tax_lines.length).toBeGreaterThan(0)
const taxLine = newItem.tax_lines.find(
(tl) => tl.code === "CADEFAULT"
)
expect(taxLine.description).toEqual("CA Default Rate")
})
})
@@ -557,6 +555,78 @@ medusaIntegrationTestRunner({
])
)
})
it("should translate shipping method tax lines when adding to order edit with locale", async () => {
const order = await createOrderFromCart("fr-FR")
await api.post(
"/admin/order-edits",
{ order_id: order.id },
adminHeaders
)
await api.post(
`/admin/order-edits/${order.id}/shipping-method`,
{ shipping_option_id: shippingOption.id },
adminHeaders
)
await api.post(
`/admin/order-edits/${order.id}/confirm`,
{},
adminHeaders
)
const updatedOrder = (
await api.get(`/admin/orders/${order.id}`, adminHeaders)
).data.order
const newShippingMethod = updatedOrder.shipping_methods.find(
(sm) => sm.shipping_option_id === shippingOption.id
)
expect(newShippingMethod.tax_lines.length).toBeGreaterThan(0)
const taxLine = newShippingMethod.tax_lines.find(
(tl) => tl.code === "CADEFAULT"
)
expect(taxLine.description).toEqual("Taux par défaut CA")
})
it("should use original tax line description when order has no locale", async () => {
const order = await createOrderFromCart()
await api.post(
"/admin/order-edits",
{ order_id: order.id },
adminHeaders
)
await api.post(
`/admin/order-edits/${order.id}/shipping-method`,
{ shipping_option_id: shippingOption.id },
adminHeaders
)
await api.post(
`/admin/order-edits/${order.id}/confirm`,
{},
adminHeaders
)
const updatedOrder = (
await api.get(`/admin/orders/${order.id}`, adminHeaders)
).data.order
const newShippingMethod = updatedOrder.shipping_methods.find(
(sm) => sm.shipping_option_id === shippingOption.id
)
expect(newShippingMethod.tax_lines.length).toBeGreaterThan(0)
const taxLine = newShippingMethod.tax_lines.find(
(tl) => tl.code === "CADEFAULT"
)
expect(taxLine.description).toEqual("CA Default Rate")
})
})
})
},