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

refactor: unify shipping line logic #1191

Closed
wants to merge 5 commits into from
Closed

refactor: unify shipping line logic #1191

wants to merge 5 commits into from

Conversation

peelar
Copy link
Member

@peelar peelar commented Feb 1, 2024

Context

A shipping app calculates taxes. It returns positive values. But when querying the shipping values, they are all 0s (not just the tax rate). We narrowed down the cause - it's the Taxes App.

We need to revisit the shipping calculations in the Taxes App and try to figure out why it returns 0s.

Scope of the PR

  • Unified the shipping line taxes/values calculation logic so it's all in the same place.

No cause was yet found, so it's WIP.

Checklist

Copy link

changeset-bot bot commented Feb 1, 2024

⚠️ No Changeset found

Latest commit: fb97d08

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Feb 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
saleor-app-cms ✅ Ready (Inspect) Visit Preview Feb 1, 2024 2:42pm
saleor-app-crm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 1, 2024 2:42pm
saleor-app-data-importer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 1, 2024 2:42pm
saleor-app-emails-and-messages ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 1, 2024 2:42pm
saleor-app-invoices ✅ Ready (Inspect) Visit Preview Feb 1, 2024 2:42pm
saleor-app-klaviyo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 1, 2024 2:42pm
saleor-app-products-feed ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 1, 2024 2:42pm
saleor-app-search ❌ Failed (Inspect) Feb 1, 2024 2:42pm
saleor-app-segment ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 1, 2024 2:42pm
saleor-app-slack ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 1, 2024 2:42pm
saleor-app-taxes ✅ Ready (Inspect) Visit Preview Feb 1, 2024 2:42pm

Copy link
Member

Choose a reason for hiding this comment

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

question: I don't see a point to why did we change it into a function instead of class? Is this purely stylistic reason?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, exactly. Initializing a class with no arguments in the constructor and executing its single method takes 2 lines instead of 1 (with function). I think it makes the code less readable.

taxCode: config.shippingTaxCode,
quantity: 1,
};
taxIncluded: true,
Copy link
Member

Choose a reason for hiding this comment

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

question: Is this a good assumption in general? Sometimes you need to calculate different VAT for shipping (e.g. you're selling books with lower VAT rate and shipping is included a as a separate line with higher tax rate)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but this is the OrderConfirmed event, when already all the taxes were calculated. We just need to pass the values to AvaTax. Otherwise, an extra tax gets charged.

const billingAddress = order.billingAddress;

if (!billingAddress) {
throw new Error("Billing address not found in OrderConfirmed subscription.");
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: I think we should use a ModernError subclass here instead of generic Error

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, but it hasn't been installed in the app, and I would rather not spend time on it. Feel free to pop it in

@peelar
Copy link
Member Author

peelar commented Feb 20, 2024

this can't be merged because it needs to be ported to AvaTax app

@peelar peelar closed this Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants