单位转换

单据数量计算中,常用使用单位转换后的数值。列一个公用的小Demo,供参考:

 public Qty unitConverter(UnitOfMeasureSymbol _fromUnit, UnitOfMeasureSymbol _toUnit, InventTable _inventTable, Qty _qty)
    {
        Qty           convertedQty = _qty;// 转换前源数量
        UnitOfMeasure formUnit   = UnitOfMeasure::findBySymbol(_fromUnit);// FromUnit: 源单位
        UnitOfMeasure toUnit     = UnitOfMeasure::findBySymbol(_toUnit);// ToUnit : 目标单位

        boolean       canBeConvert = UnitOfMeasureConverter::canBeConverted(formUnit.RecId, toUnit.RecId, _inventTable.Product);
            
        if (canBeConvert)
        {
            convertedQty = UnitOfMeasureConverter::convert(convertedQty,
                    formUnit.RecId,
                    toUnit.RecId,
                    NoYes::Yes,
        _inventTable.Product);
        }

        return convertedQty;// 转换后目标数量
    }
原文地址:https://www.cnblogs.com/sunny-technology/p/13367060.html