需求:配套材料采购申请选bom展开将物料清单子项明细自定义字段携带到采购申请
具体实现:
物料清单子项明细增加自定义字段,假设字段标识、字段名称、属性为FText_123,字段类型为文本
BOM正向展开模型展开结果明细增加自定义字段,假设字段标识、字段名称、属性为FText_123,字段类型为文本
设置制造字段映射模型,物料明细的自定义字段映射到正向展开模型的自定义字段
编写插件,插件继承Kingdee.K3.SCM.Purchase.Business.PlugIn.AssortReqEdit
参考代码如下:
using Kingdee.BOS;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.BusinessService;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.K3.BD.ServiceHelper;
using Kingdee.K3.Core.BD;
using Kingdee.K3.Core.BD.ServiceArgs;
using Kingdee.K3.Core.MFG.ENG.BomExpand;
using Kingdee.K3.Core.MFG.ENG.ParamOption;
using Kingdee.K3.Core.SCM;
using Kingdee.K3.Core.SCM.Args;
using Kingdee.K3.Core.SCM.PUR;
using Kingdee.K3.SCM.ServiceHelper;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Kingdee.BOS.Util;
using Kingdee.K3.SCM.Business;
using Kingdee.K3.SCM.Core.PUR;
using Kingdee.BOS.Core.SqlBuilder;
namespace XXXNameSpace
{
/// <summary>
/// 实现配套材料采购申请按bom展开后,携带物料清单子项明细上的自定义字段到采购申请物料明细自定义字段上。
/// 这里实现是按子项物料记录对应关系。
/// 前提:bom子项上不能有重复物料。
/// </summary>
public class PTTest : Kingdee.K3.SCM.Purchase.Business.PlugIn.AssortReqEdit
{
//存放物料和自定义字段值 字典
Dictionary<long, string> MatMasterToCustomerValueDic = new Dictionary<long, string>();
//重写bom展开后相关数据转换
public override List<BomDataNode> ConvertBomExpandResultToNodes(DynamicObject bomExpandDataObject)
{
//调用父类方法
var rsts= base.ConvertBomExpandResultToNodes(bomExpandDataObject);
if (bomExpandDataObject == null)
{
return rsts;
}
//bom展开结果
DynamicObjectCollection rets = bomExpandDataObject["BomExpandResult"] as DynamicObjectCollection;
if (rets == null || rets.Count <= 0)
{
return rsts;
}
foreach (DynamicObject dyCurRow in rets)
{
DynamicObject mat = dyCurRow["MaterialId"] as DynamicObject;
//物料masterid
var key_m = Convert.ToInt64(mat["msterId"]);
//自定义字段值 FText_123
string value_c = Convert.ToString(dyCurRow["FText_123"]);
//记录 物料masterid和自定义字段值 字典
MatMasterToCustomerValueDic[key_m] = value_c;
}
return rsts;
}
//重写生成采购申请数据后事件,将自定义字段数据写入采购申请单
public override void AfterGenerateReqs(List<DynamicObject> reqDatas)
{
base.AfterGenerateReqs(reqDatas);
if (reqDatas == null || reqDatas.Count == 0)
{
return;
}
foreach (var billItem in reqDatas)
{
var entrys = billItem["ReqEntry"] as DynamicObjectCollection;
foreach (var entryItem in entrys)
{
DynamicObject mat = entryItem["MaterialId"] as DynamicObject;
//物料masterid
var key_m = Convert.ToInt64(mat["msterId"]);
//写入值。
if (MatMasterToCustomerValueDic.ContainsKey(key_m))
{
entryItem["FText_123"] = MatMasterToCustomerValueDic[key_m];
}
}
}
}
}
}
6.编译插件后,在bos找到配套材料采购申请动态表单,打开表单插件,反启用原标准产品Kingdee.K3.SCM.Purchase.Business.PlugIn.AssortReqEdit插件,注册使用新二开插件。
推荐阅读