Skip to content

[221] Don't send cancelled or returned line items #236

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

Merged
merged 4 commits into from
Aug 14, 2023

Conversation

Noah-Silvera
Copy link
Member

@Noah-Silvera Noah-Silvera commented Jun 26, 2023

Prior to this change, each request to TaxJar sent all line items. We
should exclude line items that have been returned or cancelled so the
total of the line items still adds up to the order's payment total.

@Noah-Silvera Noah-Silvera changed the base branch from master to 221-create-sync-logs-for-replace-transaction-jobs June 26, 2023 21:38
@nvandoorn nvandoorn force-pushed the 221-handle-multiple-refunds-in-a-row branch from 9be7fc4 to 564efe5 Compare July 17, 2023 20:53
@nvandoorn nvandoorn changed the base branch from 221-create-sync-logs-for-replace-transaction-jobs to master July 17, 2023 20:53
@nvandoorn nvandoorn force-pushed the 221-handle-multiple-refunds-in-a-row branch from 564efe5 to 58df5d3 Compare July 17, 2023 20:59
@nvandoorn nvandoorn changed the title [221]-Handle multiple refunds in a row [221] Don't send cancelled or returned line items Jul 24, 2023
@nvandoorn nvandoorn force-pushed the 221-handle-multiple-refunds-in-a-row branch from 58df5d3 to 6877c9a Compare July 24, 2023 21:26
@nvandoorn nvandoorn marked this pull request as ready for review July 24, 2023 21:27
@@ -146,7 +146,8 @@ def valid_line_items(line_items)
# The API appears to error when sent line items with no quantity...
# but why would you do that anyway.
line_items.reject do |line_item|
line_item.quantity.zero?
line_item.quantity.zero? ||
!line_item.inventory_units.where.not(state: 'returned').exists?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we write this as

line_item.inventory_units.returned.any?

@@ -116,7 +116,7 @@ def line_items_params(line_items)
line_items: valid_line_items(line_items).map do |line_item|
{
id: line_item.id,
quantity: line_item.quantity,
quantity: line_item.inventory_units.where.not(state: ['returned', 'canceled']).count,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we're doing this a few times, should we consider pulling it into a helper so we don't have to repeat it?

Copy link
Member

@benjaminwil benjaminwil left a comment

Choose a reason for hiding this comment

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

I'll add: I like both of Chris's comments.

nvandoorn and others added 3 commits August 10, 2023 14:54
Prior to this commit, all line items would be reported to TaxJar,
including returned line items. To fix this, we check that a line item
has at least one inventory unit with a state other than 'returned'.

Co-authored-by: Alistair Norman <[email protected]>
Prior to this change, each request to TaxJar sent all line items. We
should exclude line items that have been returned or cancelled so the
total of the line items still adds up to the order's payment total.

Co-authored-by: Noah Silvera <[email protected]>
Prior to this change, the query for inventory units that are not
cancelled or returned was repeated three times so we move the query into
a private method.

Co-authored-by: Alistair Norman <[email protected]>
@nvandoorn nvandoorn force-pushed the 221-handle-multiple-refunds-in-a-row branch from 6877c9a to 3128fb8 Compare August 10, 2023 22:12
@nvandoorn
Copy link
Contributor

Latest revision rebases this on-top of master and moves the repeated query into a private method.

Copy link
Collaborator

@forkata forkata left a comment

Choose a reason for hiding this comment

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

Thanks for the clean-up here @nvandoorn 🚀

@nvandoorn nvandoorn merged commit c1d0a54 into master Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants