TecMikro Posted November 12, 2021 Share Posted November 12, 2021 (edited) When editing an order that is In Preparation to modify the price of the products in the order, or to add new products with custom prices, the total values (without taxes) are calculated erroneously which leads to the invoice having inconsistencies. In this example, the first row should be $34.00 (0.85*40), the second row should be $56.00 (1.12*50). Apparently, the error occurs because at the time of order edition the totals are calculated with taxes included first, and then the total without taxes is calculated based on that value. The third row ($28.14) is ok because the price was not changed. This invoice no longer works because the rest of the calculations carry these errors. The only way I have found to overcome this problem is to cancel the order and recreate a new one by entering the new prices before placing the order. Edited October 31, 2022 by TecMikro (see edit history) Link to comment Share on other sites More sharing options...
SliderFlash Posted November 12, 2021 Share Posted November 12, 2021 (edited) That's right, you can choose whether to round the amount up or down. shop / setting Edited November 12, 2021 by SliderFlash (see edit history) Link to comment Share on other sites More sharing options...
TecMikro Posted November 12, 2021 Author Share Posted November 12, 2021 (edited) Hello, thanks for the answer. The error has nothing to do with rounding, when I make a new order from the BO, and I put the prices (without taxes), the invoice is calculated correctly. The error only occurs when editing the order. Apparently, the error occurs because at the time of order edition the totals are calculated with taxes included first, and then the total without taxes is calculated based on that value.This is the invoice calculated correctly when creating the order from scratch: Edited November 12, 2021 by TecMikro (see edit history) 1 Link to comment Share on other sites More sharing options...
apositivo Posted November 17, 2021 Share Posted November 17, 2021 On 11/12/2021 at 8:34 AM, TecMikro said: Hello, thanks for the answer. The error has nothing to do with rounding, when I make a new order from the BO, and I put the prices (without taxes), the invoice is calculated correctly. The error only occurs when editing the order. Apparently, the error occurs because at the time of order edition the totals are calculated with taxes included first, and then the total without taxes is calculated based on that value.This is the invoice calculated correctly when creating the order from scratch: hi @TecMikro, any solution for this issue ? we have this issue in prestashop 1.7.6.8 when edit order in backoffice Link to comment Share on other sites More sharing options...
TecMikro Posted November 17, 2021 Author Share Posted November 17, 2021 (edited) Hello, this problem still has no solution. We continue working the same. A possible "solution" is to configure the currency with 4 decimal places, that way the calculations have greater precision and it seems that the errors are corrected. The problem is that the prices in the BO and FO would be shown with 4 decimal places (and in our country only 2 decimal places are used). This way of calculating taxes in prestashop is one of the disadvantages that I have found and that has not yet been improved. In case I do not receive here a response that solves this problem, what I will do is report it as a bug on GitHub Edited November 17, 2021 by TecMikro (see edit history) Link to comment Share on other sites More sharing options...
apositivo Posted November 17, 2021 Share Posted November 17, 2021 18 minutes ago, TecMikro said: Hello, this problem still has no solution. We continue working the same. A possible "solution" is to configure the currency with 4 decimal places, that way the calculations have greater precision and it seems that the errors are corrected. The problem is that the prices in the BO and FO would be shown with 4 decimal places (and in our country only 2 decimal places are used). This way of calculating taxes in prestashop is one of the disadvantages that I have found and that has not yet been improved. In case I do not receive here a response that solves this problem, what I will do is report it as a bug on GitHub did you try to do a clean installation of your prestashop version and make a new test ? Link to comment Share on other sites More sharing options...
TecMikro Posted November 17, 2021 Author Share Posted November 17, 2021 The error also remains in prestashop 1.7.8.1 (it is a clean installation that I have for testing). The indicated values are in error.: Link to comment Share on other sites More sharing options...
apositivo Posted November 17, 2021 Share Posted November 17, 2021 do you have this configuration ? https://www.templatetrip.com/help/prestashop-1-7-x-how-to-configure-product-price-decimals/ Link to comment Share on other sites More sharing options...
TecMikro Posted November 18, 2021 Author Share Posted November 18, 2021 20 hours ago, apositivo said: do you have this configuration ? https://www.templatetrip.com/help/prestashop-1-7-x-how-to-configure-product-price-decimals/ Hi, yes, I have this configuration. Round up away from zero, when it is halfway there (recommended). Currency: USD with 2 decimals. Tested with Round on each item (error at Total tax and Total): Round on each line: Round on the total: The correct values are: $0.85...40...$34.00 $1.12....50...$56.00 Total (tax excluded): $90.00 Total tax (12%): $10.80 Total: $100.80 Link to comment Share on other sites More sharing options...
TecMikro Posted October 31, 2022 Author Share Posted October 31, 2022 (edited) The solution consists of 2 steps: 1. Improve the accuracy of calculations by working with 4 decimal places or more if necessary. To do this, go to International / Localization / Currencies. Edit the currency and set the number of decimals to 4. 2. Format prices for display to 2 decimal places. For this, the /src/Core/Localization/Number/Formatter.php file must be edited as follows: On line 103, within the format function, add the code "my code" as below to round prices to 2 decimal places: public function format($number, NumberSpecification $specification) { // my code $number=round($number,2); // my code ... On line 138, comment out the following statement to override it //return $formattedNumber; And add this code to remove the last 2 decimal places on the right "00", since otherwise the prices are rounded but with 4 decimal places: // my code return substr($formattedNumber,0,-2); //Remove the last 2 digits ("00") // my code Edited October 31, 2022 by TecMikro (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now