Prestashop: Recalculate totals on order change

Created on 20 Feb 2020  ·  6Comments  ·  Source: PrestaShop/PrestaShop

Hi guys, I was browsing the code for the migrated admin order page and there is still a lot of code that could (and does) cause trouble.

Whatever changes you do, add or remove products, add or remove discounts, it adds or subtracts the amounts from the order and invoice. But this creates room for errors, negative totals, rounding errors, because it works with rounded values. (Like https://github.com/PrestaShop/PrestaShop/issues/13809)

I don't know if you guys had a discussion about this, but I think it would be good (if there is time) to change to logic to completely recalculate the order every time something changes. This would eliminate all the trouble there is.

CO Improvement Order TBS waiting for PM waiting for dev

Most helpful comment

Second option is what we aim for but as you can imagine this is very complex. We have already started gathering all issues about rounding, you can find the Price & taxes epic here : https://github.com/PrestaShop/PrestaShop/issues/9703

Of course, this needs a deep functional and technical study before we can really start working on it.
This is a priority topic for 178.

All 6 comments

Hi @Hlavtox,

Thanks for your report.
Ping @PrestaShop/prestashop-product-team, @PrestaShop/prestashop-core-developers what do you think?

Thanks!

Hello,
I totally agree with you @Hlavtox.
I managed to reproduce #13809 and #11059, and they are caused by the rounded values. In fact, subtracting a rounded up value from an non-rounded value give negative result, which is invalid from Object point of view.
But I think this problem of rounding has already a ticket somewhere here in Github, I just don't find it.

Wdyt?

  • We use a workaround for the two mentioned issues? like round() or setting to zero totals that are negative?
    or
  • We gather all tickets about rounding, and have a better idea about the whole situation?

Thank you very much for your time guys :)

Second option is what we aim for but as you can imagine this is very complex. We have already started gathering all issues about rounding, you can find the Price & taxes epic here : https://github.com/PrestaShop/PrestaShop/issues/9703

Of course, this needs a deep functional and technical study before we can really start working on it.
This is a priority topic for 178.

@arouiadib @colinegin

Personally, I wouldn't rush it and settle for some “hackjobs”. Even if we temporarily fix it by (value < 0, then value = 0), it still does not solve the issue of rounding...

Better to think it through. It waited a few years, it can wait for some more time.

Proper tax and discount calculations in FO are more important. We (merchants) can always tell a customer: “Make a new order, we don't change them.” 👍

Perfect :), thank you very much @colinegin @Hlavtox

I suggest closing this issue and continuing discussion there in #9703. wdy?

Hi guys,

just for your information, I just created a new EPIC dedicated to rounding issues. You can find it here : https://github.com/PrestaShop/PrestaShop/issues/19445

Have a nice evening ;)

Was this page helpful?
0 / 5 - 0 ratings