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

Rounding issues with refunds/returns #6226

Closed
niedfelj opened this issue Mar 25, 2015 · 2 comments
Closed

Rounding issues with refunds/returns #6226

niedfelj opened this issue Mar 25, 2015 · 2 comments

Comments

@niedfelj
Copy link

It seems like in this pull request, the field precision/scale was changed for returns:

#5043

This can't be changed like that without changing the scale on ALL db amount fields (or properly figuring out how to round everywhere), as calculations now after a refund will show an order total of something like, $50.1348 with payments of $50.13 and then the order updater says that a balance is due. If spree is going to switch to a scale of 4, it needs to be coordinated across the system/db.

@JDutil
Copy link
Member

JDutil commented Mar 25, 2015

I believe there was also a related tax calculation rounding issue as well:
#6137

I think the proper solution here would be to change scale to 4 everywhere, and ensure we properly round for display methods.

@niedfelj
Copy link
Author

Well, I guess the problem with changing to scale 4 everywhere, still requires that rounding to 2 is figured out for payments/totals etc, since we can't really charge to 4 decimals. I think the bigger problem, as it relates to the refund code, is mainly in the default calculator being used. It's trying to figure out refunds based on dividing line item counts, total items in order, adjustments etc. The longer term fix, IMO, would be to have every inventory_unit know its tax amounts, adjustments etc, because then refunds don't need to be "calculated" in the sense that the calculations should have been done already. This has primarily been a problem for us in applying some sort of editor/employee discount on an order that is not uniform (say one item is 40% off, one is 10% off) and the system has no way to "reverse" it. The simple solution for us right now has been to change the scale back to 2 and then added a round(2, :down) on the DefaultRefundAmount calculator so at least the "in memory" calculations align with the db:

    (weighted_order_adjustment_amount(return_item.inventory_unit) + weighted_line_item_pre_tax_amount(return_item.inventory_unit)).round(2, :down)

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

No branches or pull requests

4 participants