-
Notifications
You must be signed in to change notification settings - Fork 12
[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
Conversation
9be7fc4
to
564efe5
Compare
564efe5
to
58df5d3
Compare
58df5d3
to
6877c9a
Compare
@@ -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? |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
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]>
6877c9a
to
3128fb8
Compare
Latest revision rebases this on-top of master and moves the repeated query into a private method. |
There was a problem hiding this 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 🚀
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.