单据数量计算中,常用使用单位转换后的数值。列一个公用的小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;// 转换后目标数量
    }

 

posted on 2020-07-23 16:28  Sunny_Li  阅读(340)  评论(0编辑  收藏  举报