Jump to content

[SOLVED] Error in calculating the total (tax excluded) when editing an order (PS 1.7.7.3)


TecMikro

Recommended Posts

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.  01.jpg.759a4287a87342aba497d18f7b4bf9a6.jpg

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 by TecMikro (see edit history)
Link to comment
Share on other sites

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:

022.thumb.jpg.eb7635ea3987aeef2a823221a775e279.jpg

Edited by TecMikro (see edit history)
  • Like 1
Link to comment
Share on other sites

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:

022.thumb.jpg.eb7635ea3987aeef2a823221a775e279.jpg

 

 

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

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 by TecMikro (see edit history)
Link to comment
Share on other sites

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

20 hours ago, apositivo said:

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-item.png.bfe34741dd4a34ece4f01a7834204223.png

Round on each line:

round-on-each-line.png.11a2be0e6a81db74c8091fd9eec40096.png

Round on the total:

round-on-the-total.png.1ca39033abffa56f3e0e4fadd7cb3917.png

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

  • 11 months later...

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 by TecMikro (see edit history)
Link to comment
Share on other sites

  • TecMikro changed the title to [SOLVED] Error in calculating the total (tax excluded) when editing an order (PS 1.7.7.3)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...