Repository: inventree/InvenTree

Issue:
Decimal Values: Server Error (500)

When I try to add a stock with decimal value quantity i get a Server Error (500) when i submit the form. (received stock and add stock)

I purchase and build parts with decimal value.

**Eg**.
- I purchase 230.34KG of salt
- I build a part with 1.21kg of Salt

**Screenshots**
If applicable, add screenshots to help explain your problem.
--->
![Screenshot-20220115210315-1558x385](https://user-images.githubusercontent.com/76049382/149617988-a0498a9a-1f55-4c8b-b8a7-91a87f3bc51e.png)

**Deployment Method**
- [ ] Docker

**Version Information**
- [ ] 0.5.4
<!---
You can get this by going to the "About InvenTree" section in the upper right corner and clicking on to the "copy version information"
--->



Discussion:
Also played with the https://demo.inventree.org/order/purchase-order/3/, it doesn't let you receive items in decimal value

![image](https://user-images.githubusercontent.com/76049382/149618428-2e33a30d-282f-4086-be5a-43fc3c2fc52a.png)

However I could add 12, the form accepts the submission.

On the remaining 0.56, i get this form with over 12 digits after decimal.
![image](https://user-images.githubusercontent.com/76049382/149618521-d18f1b66-59b8-4959-adc5-1e32baf0d342.png)

after manually removing the excess amount of digits, still same error appears: when i submit
![image](https://user-images.githubusercontent.com/76049382/149618552-0db58ec6-9486-46e3-8b43-24338501a922.png)


Hi ther @huseyinkogo 
In general quantities should support fractals, although it is not a regular testing scenario.
Without the error message it is quite difficult / impossible to find out more without reproducing everything. I would suggest including the error message as error 5** is almost everything that can happen serverside.
Hey @matmair

I have included the error code of Server error (500) however that was all i received. When i submitted the form with a whole it succeed.

All the recent comments were from the demo page.  https://demo.inventree.org/order/purchase-order/3/
@huseyinkogo the demo instance resets daily, so examples from there are not really working.

I can reproduce the error, the API seems to block receiving of fractal parts.

We are very shortly before the next release so I tag the next version for it.
@matmair 

Roughly how many weeks are saying to resolve this bug. 

Resolving patch:
diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py
--- a/InvenTree/order/models.py
+++ b/InvenTree/order/models.py
@@ -27,6 +27,7 @@
 from company.models import Company, SupplierPart
 from plugin.events import trigger_event
 
+import InvenTree.helpers
 from InvenTree.fields import InvenTreeModelMoneyField, RoundingDecimalField
 from InvenTree.helpers import decimal2string, increment, getSetting
 from InvenTree.status_codes import PurchaseOrderStatus, SalesOrderStatus, StockStatus, StockHistoryCode
@@ -414,16 +415,12 @@ def receive_line_item(self, line, location, quantity, user, status=StockStatus.O
             )
 
         try:
-            if not (quantity % 1 == 0):
-                raise ValidationError({
-                    "quantity": _("Quantity must be an integer")
-                })
             if quantity < 0:
                 raise ValidationError({
                     "quantity": _("Quantity must be a positive number")
                 })
-            quantity = int(quantity)
-        except (ValueError, TypeError):
+            quantity = InvenTree.helpers.clean_decimal(quantity)
+        except TypeError:
             raise ValidationError({
                 "quantity": _("Invalid quantity provided")
             })


Test patch: