-
Notifications
You must be signed in to change notification settings - Fork 1
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 error "Total Summa med Skatt är inte lika med Total Summa Exklusive Moms, Total Skatt och Avrundning" #146
Comments
Based on the last screenshot I posted, the calculation for the sums in the error message is the following.
Adding the price ex VAT for each above line: The "Beräknat totalt" is 172,08 in the error message, which means that it probably is rounded down via floor(). The "Tillhandahållet totalt" is using round(). So my theory is that Billmate is flooring the numbers on their end and the plugin is instead rounding them. Edit: This ONLY happens when the third decimal is 5. |
Final update with proposed solutionHow to reproduce
Why is this happening?In class-bco-cart-articles-helper.php, the function get_without_tax is not rounding up if the line_total is X.XX5. If the line_total would be 125.235, it would be rounded to 125.23. The Billmate API seems to round these numbers up instead, so it'd expect 125.24. This ONLY happens if the third decimal of the order price sum without tax is 5. Proposed fixWhile searching around I found the answer in the top voted user contributed notes: Basically we want to force always rounding up on the third decimal, so it can handle 0.005 floats.
The fix seems to work fine with all different type of carts:
|
I've temporarily implemented the above fix in our production environment. No issues have been reported by customers so far and orders look correct. It has been live for approximately 12 hours. Usually we would've gotten around a lot of e-mails regarding this issue in that timeframe. I do recommend that you test it yourselves too. I haven't tried it with 6% MOMS/VAT products, but it shouldn't in theory be any different. Update: Still no issues as of 12:00 today. |
Update on proposed fix & more debuggingThe above fix works fine when the third decimal is 5, but we've now run into cases where even later decimals are at 5 – so the proposed fix isn't working in those cases. I've been discussing with Paul at Billmate regarding this and one of the things we wanted to try was updating classes/requests/helpers/order/class-bco-order-cart-helper.php row 49. Original:
Modified:
Result: |
Could you take a look at this @NiklasHogefjord? |
@DanielMarklund, I have tried to recreate the issue but it is working without any problems for me. I have followed your instructions (1 x 39 kr incl 12% VAT + 3 x 39 kr incl 12% VAT + shipping 29 kr incl 25% VAT + invoice fee 12 kr incl 25% VAT) and this is what is being sent in to Billmate:
What is your Rounding option set to in the --> WooCommerce --> Settings --> Tax tab? Mine looks like this: |
Closing this since we haven't heard back from @DanielMarklund. Please feel free to re-open the issue it you still are experiencing issues with this. |
Customer reported that they were greeted with the following alert upon opening the checkout:
I received a list of which products the customer had in the cart and I could reproduce it myself, as seen in the image below. Why is this happening? We have 2 decimals setup in WooCommerce.
FYI, there is a mix of 12% and 25% moms/VAT products in the cart.
The text was updated successfully, but these errors were encountered: