通过插件将库存单位数量换算成辅助单位数量,具体代码如下:
DynamicObjectCollection materialStock = material["MaterialStock"] as DynamicObjectCollection;
DynamicObject auxUnitID = materialStock[0]["AuxUnitID"] as DynamicObject;//库存单位
decimal appQty = Convert.ToDecimal(item["MustQty"]);
if (auxUnitID != null)
{
newRow["SecUnitId"] = auxUnitID;
newRow["SecUnitId_Id"] = auxUnitID["Id"];
//获取单位换算率
GetUnitConvertRateArgs getUnitConvertRateArgs = new GetUnitConvertRateArgs();
getUnitConvertRateArgs.MasterId = Convert.ToInt32(material["Id"]);
getUnitConvertRateArgs.SourceUnitId = Convert.ToInt32(unitID["Id"]);
getUnitConvertRateArgs.DestUnitId = Convert.ToInt32(auxUnitID["Id"]);
GetUnitConvertRateArgs param = getUnitConvertRateArgs;
var rate = AppServiceContext.BDService.GetUnitConvertRate(this.Context, param);
var secQty = rate.ConvertQty(appQty);//换算辅助数量
newRow["FStockSecAppQty"] = secQty;
}