PurchLine Inventory Picking with X++ - AX 2012
时间: 2024-03-21 11:39:00 浏览: 122
在 AX 2012 中,可以使用 X++ 代码实现采购单行项目的库存拣货。下面是一个示例代码,用于从采购单行项目中拣货:
```
// 获取采购单行项目
PurchLine purchLine = PurchLine::findRecId(purchLineRecId);
// 获取库存管理参数
InventParameters inventParameters = InventParameters::find();
// 获取仓库管理程序集
InventDimCtrl_InventLocation inventDimCtrl_InventLocation = new InventDimCtrl_InventLocation();
// 创建库存维度
InventDim inventDim;
inventDim.InventLocationId = inventDimCtrl_InventLocation.inventLocationId(purchLine.InventLocationId, purchLine.InventSiteId);
inventDim.InventSiteId = purchLine.InventSiteId;
// 获取库存数量
InventQty inventQty = InventQty::newInventQty(inventDim, purchLine.ItemId, inventParameters.inventInventoryOnHand);
// 获取拣货数量
Real qty = inventQty.specQty(purchLine.OrderQty);
// 执行拣货
InventTrans inventTrans;
inventTrans.clear();
inventTrans.TransDate = systemDateGet();
inventTrans.ItemId = purchLine.ItemId;
inventTrans.Qty = qty;
inventTrans.InventLocationId = inventDim.InventLocationId;
inventTrans.InventSiteId = inventDim.InventSiteId;
inventTrans.InventTransId = inventTransId::findOrCreate(inventTrans.TransDate, inventTrans.TransType, inventTrans.Posting, inventTrans.Voucher, inventTrans.RefCompanyId, inventTrans.RefRecId, inventTrans.RefRelationId, inventTrans.RefTableId);
inventTrans.InventTransId = InventTransId::findOrCreate(inventTrans.TransDate, inventTrans.TransType, inventTrans.Posting, inventTrans.Voucher, inventTrans.RefCompanyId, inventTrans.RefRecId, inventTrans.RefRelationId, inventTrans.RefTableId);
inventTrans.InventTransPosting::initFromInventTrans(inventTrans, inventParameters);
inventTrans.insert();
```
需要注意的是,上述代码中的 `purchLineRecId`、`purchLine.ItemId`、`purchLine.OrderQty`、`purchLine.InventLocationId` 和 `purchLine.InventSiteId` 都需要根据实际业务场景进行替换或设置。此外,还需要确保拣货数量 `qty` 大于 0,才能执行拣货操作。
阅读全文