You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ofbiz.apache.org by "Anil K Patel (Jira)" <ji...@apache.org> on 2026/07/03 11:26:00 UTC

[jira] [Commented] (OFBIZ-3700) Convert WorkEffort (and related entities) quantities from Double -> BigDecimal

    [ https://issues.apache.org/jira/browse/OFBIZ-3700?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18093413#comment-18093413 ] 

Anil K Patel commented on OFBIZ-3700:
-------------------------------------

Picked this up on current trunk. Bob was right, and it is now partly done - the main WorkEffort quantities (quantityToProduce, quantityProduced, quantityRejected) were converted to fixed-point at some point, but three quantity fields were missed and are still floating-point:

- WorkEffortGoodStandard.estimatedQuantity (the one Bob hit via ProductionRun)
- WorkEffortFixedAssetStd.estimatedQuantity
- WorkEffortInventoryAssign.quantity

You can see it directly in the running database. In webtools, Entity SQL Processor:

{code:sql}
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, NUMERIC_PRECISION, NUMERIC_SCALE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE (TABLE_NAME='WORK_EFFORT_GOOD_STANDARD' AND COLUMN_NAME='ESTIMATED_QUANTITY')
   OR (TABLE_NAME='WORK_EFFORT' AND COLUMN_NAME='QUANTITY_TO_PRODUCE')
   OR (TABLE_NAME='WORK_EFFORT_INVENTORY_ASSIGN' AND COLUMN_NAME='QUANTITY');
{code}

gives (on the H2 demo database):

{noformat}
WORK_EFFORT_GOOD_STANDARD      ESTIMATED_QUANTITY    DOUBLE PRECISION   53
WORK_EFFORT                    QUANTITY_TO_PRODUCE   NUMERIC            18   6
WORK_EFFORT_INVENTORY_ASSIGN   QUANTITY              DOUBLE PRECISION   53
{noformat}

So the estimated and assigned quantities are stored as binary doubles, while the migrated quantities are NUMERIC(18,6). The difference shows up as soon as you do arithmetic with them, which the production run and MRP code does. In the double type the usual binary rounding applies:

{code:sql}
SELECT CASE WHEN CAST(0.1 AS DOUBLE PRECISION)+CAST(0.2 AS DOUBLE PRECISION)=CAST(0.3 AS DOUBLE PRECISION)
            THEN 'equal' ELSE 'NOT EQUAL' END AS double_eq,
       ((CAST(0.1 AS DOUBLE PRECISION)+CAST(0.2 AS DOUBLE PRECISION))-CAST(0.3 AS DOUBLE PRECISION))*1e18 AS double_error_e18;
{code}

returns NOT EQUAL with a residual of about 5.55e-17, where the same expression in NUMERIC(18,6) is exactly equal with a zero residual.

In fairness, the day-to-day impact is smaller than it first looks, and I want to be accurate about it. The entity engine converts the stored Double to BigDecimal with BigDecimal.valueOf, which uses the shortest round-trip representation, so a single stored value usually reads back looking clean - you will not see something like 2.9999999 on screen. Where it does bite is exact-equality and reconciliation: a sum of these double-sourced quantities will not always tie out to the last unit against the NUMERIC-based inventory quantities, and small errors accumulate across a lot of fractional arithmetic.

The bigger point is consistency. The code already treats these fields as BigDecimal everywhere - ProductionRun, ProductionRunServices and MrpServices all read estimatedQuantity via getBigDecimal - but the storage is still Double, and there are a couple of lossy leftovers from before the migration: ProductionRun stores the value with this.quantity.doubleValue(), and WorkEffortServices reads it with getDouble(). So the field type says one thing and the code means another.

I would suggest finishing the migration Bob pointed at: change these three fields from floating-point to fixed-point in workeffort-entitymodel.xml, and clean up the doubleValue()/getDouble() leftovers so the manufacturing path is BigDecimal end to end. It is a schema change (DOUBLE to NUMERIC(18,6)) that existing databases pick up through the check/update-database step, and it is a widening change so it is safe. I am happy to put up a patch.


> Convert WorkEffort (and related entities) quantities from Double -> BigDecimal
> ------------------------------------------------------------------------------
>
>                 Key: OFBIZ-3700
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-3700
>             Project: OFBiz
>          Issue Type: Bug
>          Components: workeffort
>    Affects Versions: Trunk, Upcoming Branch
>            Reporter: Bob Morley
>            Priority: Minor
>
> It appears that this entity was missed from the BigDecimal conversion.  Ran into this when ProductionRunServices was attempting to create a WorkEffort (it is passing the quantity to produce as a BigDecimal).  A different bug in OFBIZ-3699 was causing an auto-convert of the field from BigDecimal to Double (which was allowing ProductionRuns to be created).  At any rate, we should convert this entity and any other quantity related entities in the WorkEffort component.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)