Skip to content

Qty to ship and Qty to invoice are handling decimals poorly #14328

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

Closed
barbazul opened this issue Mar 24, 2018 · 12 comments
Closed

Qty to ship and Qty to invoice are handling decimals poorly #14328

barbazul opened this issue Mar 24, 2018 · 12 comments
Labels
Component: Sales Event: distributed-cd Distributed Contribution Day Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Release Line: 2.1 Release Line: 2.2 Release Line: 2.3 Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release

Comments

@barbazul
Copy link
Contributor

When working with products set up with is_qty_decimal, getQtyToShip and getQtyToInvoice sometimes return wrong values and cause orders to not be able to be completed

Preconditions

  1. Have a product setup to use decimal qty

Steps to reproduce

  1. Complete an order with a product using qty = 4.4
  2. Create an invoice for qty = 0.4
  3. Refund the invoice
  4. Create an invoice for qty = 4
  5. Create a shipment for qty = 4

Expected result

  1. Order is complete

Actual result

  1. Order is not complete because there is a qty = 3.3306690738755E-16 (that's 16 decimal positions) pending shipment

Overall float point numbers are handled poorly in all order qty operations

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Mar 24, 2018
@miguelbalparda miguelbalparda added Event: distributed-cd Distributed Contribution Day and removed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed labels Mar 24, 2018
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Mar 24, 2018
@barbazul
Copy link
Contributor Author

#distributed-cd

@magento-engcom-team
Copy link
Contributor

@barbazul thank you for joining. Please accept team invitation here and self-assign the issue.

@barbazul
Copy link
Contributor Author

barbazul commented Mar 24, 2018

I am uncertain at the moment if I should go with a simple round()

I'll probably do that but use a larger than usual precision (like 8 decimals) which should prove enough to deal with extremely small decimal numbers

@orlangur
Copy link
Contributor

@barbazul rounding is not a good idea in general as error can accumulate. What should be really avoided is strict comparisons of float.

Order is not complete because there is a qty = 3.3306690738755E-16 (that's 16 decimal positions) pending shipment

Looks like somewhere in Magento there is a check qty == 0 which should actually be qty < EPS, where EPS is some small number like 1e-8.

@barbazul
Copy link
Contributor Author

@orlangur That would require a much larger change. Becase both getSimpleQtyToShip and getQtyToInvoice are being in several places.

Changing each of the comparissions would hide the underlying problem and is not future proof as some new functionality might use those public methods and repeat the error

@magento-engcom-team
Copy link
Contributor

Hi @barbazul. Thank you for your report.
The issue has been fixed in #14346 by @barbazul in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Apr 4, 2018
@Top-CMS
Copy link

Top-CMS commented Apr 16, 2018

Is the fix available so we can fix this for M2.2.3?
We don't know how long to wait for M2.3, so a quick fix should be great
otherwise it is not possible to invoice with decimals

@barbazul
Copy link
Contributor Author

It should be relatively simple to build a module with plugins for the 2 affected methods.

Just check the committed code.

@ghost ghost self-assigned this Sep 4, 2018
@ghost ghost added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Component: Sales labels Sep 4, 2018
@ghost
Copy link

ghost commented Sep 4, 2018

@barbazul, thank you for your report.
We've acknowledged the issue and added to our backlog.

@ghost ghost removed their assignment Sep 4, 2018
@barbazul
Copy link
Contributor Author

Hey @Top-CMS finally got around to building a module out of this: https://github.com/SemExpert/SemExpert_FixSalesDecimals

Enjoy

@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented Nov 16, 2018

Hi @TomashKhamlai. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

@TomashKhamlai
Copy link
Contributor

The issue was re-tested and we can confirm that it was fixed on the 2.3 release branch. We closing this issue as fixed due to upcoming 2.3 release that will be available soon.

@TomashKhamlai TomashKhamlai removed their assignment Nov 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Sales Event: distributed-cd Distributed Contribution Day Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Release Line: 2.1 Release Line: 2.2 Release Line: 2.3 Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release
Projects
None yet
Development

No branches or pull requests

6 participants