Skip to content

Commit e481cf0

Browse files
discounts
1 parent d33e257 commit e481cf0

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ module.exports = defineConfig(
101101
> - The example above will use `PC040100` for each product. See [Advanced Usage](#advanced-usage) for assigning specific tax codes to individual products
102102
> - The plugin automatically syncs your Medusa stock locations with Avalara locations on startup for accurate tax calculations. However, since Medusa doesn't emit events for stock location changes, if you create or update a location after startup, you'll need to either restart the app or manually call `POST /admin/avalara-cache/feed` to refresh the cache
103103
> - The plugin fully supports tax-inclusive pricing and automatically respects the region's tax-inclusive preferences
104+
> - Discounts should be used with caution. Medusa does not use the exact tax amounts returned by Avalara but instead calculates taxes using the rates provided, which may lead to minor differences in final tax calculations when discounts are applied.
104105
105106
### 3. Run Database Migration
106107

src/workflows/create-avalara-transaction.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const fetchDataStep = createStep(
3030
const order = await orderService.retrieveOrder(orderId, {
3131
relations: [
3232
"items",
33+
"items.adjustments",
3334
"shipping_methods",
3435
"billing_address",
3536
"shipping_address",
@@ -78,7 +79,13 @@ const createAvalaraTransactionStep = createStep(
7879
line_item: {
7980
id: item.id,
8081
product_id: item.product_id || "",
81-
unit_price: item.unit_price,
82+
unit_price:
83+
item.unit_price -
84+
(item.adjustments?.reduce(
85+
(acc, adj) => acc + Number(adj.amount),
86+
0
87+
) || 0) /
88+
item.quantity,
8289
quantity: item.quantity,
8390
currency_code: order.currency_code,
8491
},

0 commit comments

Comments
 (0)