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

Bug: discounts field behaviour on CalculateTaxes event is inconsistent with docs #15531

Open
Cloud11PL opened this issue Mar 4, 2024 · 1 comment
Labels
bug merchant Merchant Experience team topics triage

Comments

@Cloud11PL
Copy link
Member

Cloud11PL commented Mar 4, 2024

What are you trying to achieve?

While working on tax app it became apparent that taxes and discounts are applied incorrectly when compared to the Avatax plugin. discounts field is returned when, according to the documentation, shouldn't.

Voucher types with the issue:

  • ENTIRE_ORDER voucher with applyOncePerOrder: true (cheapest item)
  • SPECIFIC_PRODUCT

Steps to reproduce the problem

Subscription query:

subscription CalculateTaxes {
  event {
    ...CalculateTaxesEvent
  }
}

fragment CalculateTaxesEvent on Event {
  __typename
  ... on CalculateTaxes {
    taxBase {
      ...TaxBase
    }
	...
  }
}

fragment TaxBase on TaxableObject {
  ...
  discounts {
    ...TaxDiscount
  }
  ...
  lines {
    ...TaxBaseLine
  }
  sourceObject {
    __typename
    ... on Checkout {
       ...
    }
    ... on Order {
      ...
    }
  }
}

fragment TaxDiscount on TaxableObjectDiscount {
  name
  amount {
    amount
  }
}

fragment TaxBaseLine on TaxableObjectLine {
  sourceLine {
    __typename
    ... on CheckoutLine {
      id
      checkoutProductVariant: variant {
        id
        product {
          taxClass {
            id
            name
          }
        }
      }
      undiscountedTotalPrice {
        amount
      }
    }
    ... on OrderLine {
      id
      orderProductVariant: variant {
        id
        product {
          taxClass {
            id
            name
          }
        }
      }
      undiscountedTotalPrice {
        net {
          amount
        }
      }
    }
  }
  quantity
  unitPrice {
    amount
  }
  totalPrice {
    amount
  }
}

Issue 1

  1. Create a voucher with either "Fixed amount" or "Percentage"
  2. Set applyOncePerOrder to true
  3. Create a checkout with few products that have different prices
  4. Trigger checkout taxes webhook with discounts query

Current result:
discounts field contains the discount applied to the cheapest item AND the cheapest line is discounted.

Issue 2

  1. Create a voucher with either "Fixed amount" or "Percentage"
  2. Set it to a specific product
  3. Create a checkout with the product
  4. Trigger checkout taxes webhook with discounts query

Current result:
discounts field contains the discount applied to the specific product AND the specific product line is discounted (totalPrice and unitPrice is reduced).

What did you expect to happen?

Issue 1:

Expected result:
Per documentation:

`discounts` - List of discounts assigned to checkout. (Those discounts should be applied by a tax App.)

The discounts field should be empty because the discount is already applied. The line should be still have discounted price.

Issue 2:

Expected result:
Per documentation:

`discounts` - List of discounts assigned to checkout. (Those discounts should be applied by a tax App.)

The discounts field should be empty because the discount is already applied. The line should be still have discounted price.

Expectation:

discounts should only contain the discount when the voucher is of type ENTIRE_ORDER and the discount is not applied to lines by Saleor.

Alternative solution:

If discounts field is the expected behaviour when above mentioned vouchers are applied then docs should be updated and TaxableObjectDiscount should have additional field type so that the app can calculate taxes and discounts properly without having to apply additional HANDLE_DISCOUNTS permission. Alternatively, voucher field in CheckoutLine and OrderLine should be able to be queried without the permission.

Logs

No response

Environment

Saleor version: v3.18, v3.20
OS and version: …

@Cloud11PL Cloud11PL added bug triage merchant Merchant Experience team topics labels Mar 4, 2024
@korycins
Copy link
Member

korycins commented Mar 4, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug merchant Merchant Experience team topics triage
Projects
None yet
Development

No branches or pull requests

2 participants