二开单据到生产订单或者委外订单设置最高版本BOM的问题
以上游单据到委外订单为例:
具体实现代码如下:
public class DBSQD2SubReqEKDJZH : BaseBillConvertServicePlugIn
{
public override void OnAfterFieldMapping(AfterFieldMappingEventArgs e)
{
base.OnAfterFieldMapping(e);
ExtendedDataEntity[] entryData = e.TargetExtendDataEntitySet.FindByEntityKey(CONST_SUB_SUBREQORDER.CONST_FTreeEntity.ENTITY_FTreeEntity);
this.SetDefaultBom(entryData);
}
/// <summary>
/// 获取物料的默认BOM版本
/// </summary>
/// <param name="entryData"></param>
private void SetDefaultBom(ExtendedDataEntity[] entryData)
{
DynamicObject bomObj;
Dictionary<long, DynamicObject> bomList = new Dictionary<long, DynamicObject>();
FormMetadata bomFormMetadata = (FormMetadata)AppServiceContext.MetadataService.Load(this.Context, MFGFormIdConst.SubSys_ENG.BomBill);
foreach (ExtendedDataEntity extendedDataEntity in entryData)
{
long BomId = 0;
DynamicObject rowData = extendedDataEntity.DataEntity;
BomId = Convert.ToInt64(rowData[CONST_SUB_SUBREQORDER.CONST_FTreeEntity.ORM_BomId + "_Id"]);
//若调拨申请单上没有设置bom,则获取物料的默认BOM
if (BomId <= 0) //如果不管上游单据是否有BOm版本 下推都要携带最高的BOM版本这个条件可以拿掉 直接获取最高BOM版本
{
long OrgId = Convert.ToInt64(((DynamicObject)rowData.Parent)[CONST_SUB_SUBREQORDER.CONST_FBillHead.ORM_SubOrgId_Id]);
DynamicObject materialId = (DynamicObject)rowData[CONST_SUB_SUBREQORDER.CONST_FTreeEntity.ORM_MaterialId];
long auxpropId = rowData.GetDynamicValue<long>(CONST_SUB_SUBREQORDER.CONST_FTreeEntity.ORM_AuxPropID + "_Id", 0);
//获取最高BOM版本
long defaultBomId = AppServiceContext.GetMFGService<IBOMService>().GetHightVersionBomKey(this.Context, materialId.GetDynamicObjectItemValue<long>("MsterId"), OrgId, auxpropId);
if (defaultBomId > 0)
{
if (bomList.Keys.Contains(defaultBomId))
{
bomObj = bomList[defaultBomId];
}
else
{
bomObj = AppServiceContext.ViewService.LoadSingle(this.Context, defaultBomId, bomFormMetadata.BusinessInfo.GetDynamicObjectType());
bomList.Add(defaultBomId, bomObj);
}
rowData.SetDynamicObjectItemValue(CONST_SUB_SUBREQORDER.CONST_FTreeEntity.ORM_BomId, bomObj);
rowData[CONST_SUB_SUBREQORDER.CONST_FTreeEntity.ORM_BomId + "_Id"] = defaultBomId;
rowData[CONST_SUB_SUBREQORDER.CONST_FTreeEntity.ORM_YieldRate] = bomObj.GetDynamicObjectItemValue<decimal>(Consts_ENG_BomBill.Orm_YieldRate, 100);
bomObj = null;
}
}
}
}
}
二开单据到生产订单或者委外订单设置最高版本BOM的问题
本文2024-09-23 03:25:04发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-158722.html