| @@ -224,6 +224,22 @@ open class ItemUomService( | |||||
| return stockQty.setScale(0, RoundingMode.DOWN) | return stockQty.setScale(0, RoundingMode.DOWN) | ||||
| } | } | ||||
| /** | |||||
| * Stock UOM code [PCS/CTN]* denotes pieces-per-carton; displayed stock qty should be whole cartons (integer). | |||||
| */ | |||||
| private fun isPiecesPerCartonStockUomCode(stockUnit: ItemUom?): Boolean { | |||||
| val code = stockUnit?.uom?.code?.trim() ?: return false | |||||
| return code.startsWith("PCS/CTN", ignoreCase = true) | |||||
| } | |||||
| /** After ratio math: 2 decimals, or integer when stock unit is PCS/CTN… */ | |||||
| private fun finalizePreciseStockQty(stockUnit: ItemUom?, stockQty: BigDecimal): BigDecimal { | |||||
| if (isPiecesPerCartonStockUomCode(stockUnit)) { | |||||
| return stockQty.setScale(0, RoundingMode.HALF_UP) | |||||
| } | |||||
| return stockQty.setScale(2, RoundingMode.HALF_UP) | |||||
| } | |||||
| /** | /** | ||||
| * Convert purchase qty -> stock qty and keep decimal precision. | * Convert purchase qty -> stock qty and keep decimal precision. | ||||
| * Used for PO flows where decimal quantity must be preserved. | * Used for PO flows where decimal quantity must be preserved. | ||||
| @@ -242,7 +258,7 @@ open class ItemUomService( | |||||
| .multiply(stockUnit.ratioD ?: one) | .multiply(stockUnit.ratioD ?: one) | ||||
| .divide(stockUnit.ratioN ?: one, calcScale, RoundingMode.HALF_UP) | .divide(stockUnit.ratioN ?: one, calcScale, RoundingMode.HALF_UP) | ||||
| return stockQty.setScale(2, RoundingMode.HALF_UP) | |||||
| return finalizePreciseStockQty(stockUnit, stockQty) | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -263,7 +279,7 @@ open class ItemUomService( | |||||
| .multiply(stockUnit.ratioD ?: one) | .multiply(stockUnit.ratioD ?: one) | ||||
| .divide(stockUnit.ratioN ?: one, calcScale, RoundingMode.HALF_UP) | .divide(stockUnit.ratioN ?: one, calcScale, RoundingMode.HALF_UP) | ||||
| return stockQty.setScale(2, RoundingMode.HALF_UP) | |||||
| return finalizePreciseStockQty(stockUnit, stockQty) | |||||
| } | } | ||||
| // See if need to update the response | // See if need to update the response | ||||