medusa icon indicating copy to clipboard operation
medusa copied to clipboard

Tax lines must be joined to calculate taxes

Open alessioacella opened this issue 11 months ago • 8 comments

Bug report

The error message indicates a failure due to tax lines needing to be joined to calculate taxes, pointing to a deeper issue within the cart total calculation logic, particularly when handling deleted products with applied discounts.

System information

Medusa version (including plugins): 1.20.3 Node.js version: v18.19.1 Database: postgresql Operating system: ubuntu-server

Steps to reproduce the behavior

  1. Create a cart
  2. Add a product
  3. Apply discount to that product
  4. Delete product from admin
  5. See error from retrieving cart with totals using cartService
api-1          | Error: Tax Lines must be joined to calculate taxes
api-1          |     at NewTotalsService.<anonymous> (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:213:39)
api-1          |     at step (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:59:23)
api-1          |     at Object.next (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:40:53)
api-1          |     at /usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:34:71
api-1          |     at new Promise (<anonymous>)
api-1          |     at __awaiter (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:30:12)
api-1          |     at NewTotalsService.getLineItemTotals_ (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:184:16)
api-1          |     at NewTotalsService.<anonymous> (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:142:46)
api-1          |     at step (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:59:23)
api-1          |     at Object.next (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:40:53)
api-1          |     at fulfilled (/usr/src/app/node_modules/@medusajs/medusa/dist/services/new-totals.js:31:58)
api-1          |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Expected behavior

Deleted product should be deleted from an uncompleted cart, totals should automatically works in any cases without throwing exceptions.

Screenshots

Screenshot 2024-03-20 alle 12 31 56

Code snippets

// Use cart service to retrieve cart WithTotals
const cart = await cartService.retrieveWithTotals(
    cart_id,
    {
      relations: [
        "region",
        "customer",
        "payment_sessions",
        "items.variant",
        "shipping_address",
      ],
    }
  );

alessioacella avatar Mar 20 '24 11:03 alessioacella

Update: I realise something else might be at play here. I will dig into this one and get back to you.

olivermrbl avatar Mar 20 '24 11:03 olivermrbl

@olivermrbl, thank you for your support. I want to confirm that the issue still occurs even when "items.tax_lines" is added to the relations array.

alessioacella avatar Mar 20 '24 13:03 alessioacella

Here are two more Sentry screenshots of the cart error happening in our production environment. Our current front-end workaround, which applies to creating, updating, deleting, and editing cart items following a 500 error, is far from a long-term solution. Additionally, we have implemented a "pre-check" to validate discounts, gift vouchers, price lists, etc. before transactions.

Our environment is particularly challenging due to the high volume of daily product changes, including new additions, drafts, and deletions. This dynamism highlights the need for a backend that can automatically maintain and adjust cart contents to ensure uninterrupted functionality.

I welcome any suggestions or insights on developing a more robust solution. I am ready to help in any way to deal with this problem more effectively. sentry-error-details sentry-errors

alessioacella avatar Mar 21 '24 09:03 alessioacella

@olivermrbl Any news on this?

alessioacella avatar Mar 26 '24 14:03 alessioacella

Hi @olivermrbl, following up on this. Any news? If there's anything I can do to help, please let me know.

alessioacella avatar Apr 08 '24 10:04 alessioacella