学习笔记-单据转换插件Python版原创
金蝶云社区-请输入昵称___
请输入昵称___
10人赞赏了该文章 1,154次浏览 未经作者许可,禁止转载编辑于2022年11月01日 13:30:10

场景 :单据A的单据体根据物料汇总下推单据B的单据体,单据A的单据体不汇总下推单据B的子单据体

①新增单据转换规则,A单据体分组合并汇总下推单据B的单据体

②插件策略中,注册Python插件

import clr 
clr.AddReference("System")
clr.AddReference("Kingdee.BOS")
clr.AddReference("Kingdee.BOS.Core")
clr.AddReference("Kingdee.BOS.App")
clr.AddReference('Kingdee.BOS.ServiceHelper')
clr.AddReference('Kingdee.BOS.DataEntity')
clr.AddReference("Kingdee.BOS.App.Core")
clr.AddReference('Kingdee.BOS.ServiceHelper')
clr.AddReference("Kingdee.BOS.Contracts")

from System import *
from System import StringComparison
from Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args import *
from Kingdee.BOS.App.Data import *
from System.Collections.Generic import *
from Kingdee.BOS.ServiceHelper import * 
from Kingdee.BOS.Core.Metadata import SelectorItemInfo 
from Kingdee.BOS.Core.SqlBuilder import QueryBuilderParemeter 
from Kingdee.BOS.Orm.DataEntity import *
from Kingdee.BOS.Contracts import *
from Kingdee.BOS.App.Core import *
global sfilter
def OnGetSourceData(e):
	fid=e.SourceData[0]["FId"];
	global sfilter
	sfilter="FID="+str(fid)
def AfterConvert(e):
	targetForm=e.TargetBusinessInfo.GetForm();
	headEntity=e.Result.FindByEntityKey("FBillHead");
	matIds=[]

	#sfilter="FID=100006"
	filter1=OQLFilter.CreateHeadEntityFilter(sfilter)
	viewService=ViewService()
	sourceBill=viewService.Load(this.Context,str(e.SourceBusinessInfo.GetForm().Id),None,filter1)[0];
	extendedEntities=e.Result.FindByEntityKey("FEntity");
	for dy1 in extendedEntities:
		matIds.append(dy1["MaterialID_Id"]);
	extEntity=headEntity[0];
	billDoj=extEntity.DataEntity;
	toEntry1=billDoj["ProductEntity"]
	tgtSecondEntity=e.TargetBusinessInfo.GetEntity("FSubEntity");
	sourceObjCollection=sourceBill["SAL_DELIVERYNOTICEENTRY"]
	for dym in sourceObjCollection:#循环处理
		sindex=matIds.index(dym["MaterialID_Id"])
		srcBillEntry1=extendedEntities[sindex]["STK_ASSEMBLYSUBITEM"]
		newRow=DynamicObject(tgtSecondEntity.DynamicObjectType);
		field=e.TargetBusinessInfo.GetField("FMaterialIDSETY")
		vendor=viewService.LoadSingle(this.Context,dym["MATERIALID_Id"], field.RefFormDynamicObjectType)
		#newRow["MaterialIDSETY"]=dym["MATERIALID"];
		newRow["MaterialIDSETY"]=vendor;
		newRow["MaterialIDSETY_Id"]=dym["MATERIALID_Id"];
		newRow["FUnitIDSETY"]=dym["UNITID"];
		newRow["FBaseUnitIDSETY"]=dym["BaseUnitID"];
		newRow["BaseQtySETY"]=dym["BASEUNITQTY"];
		field1=e.TargetBusinessInfo.GetField("FStockStatusIDSETY")
		
		vendor1=viewService.LoadSingle(this.Context,dym["StockStatusId_Id"], field1.RefFormDynamicObjectType)
		newRow["FStockStatusIDSETY"]=vendor1;
		#newRow["FStockStatusIDSETY"]=dym["StockStatusId"];
		newRow["FStockStatusIDSETY_Id"]=dym["StockStatusId_Id"];
		newRow["DescriptionSETY"]=dym["NoteEntry"];
		newRow["MTONOSETY"]=dym["MtoNo"];
		newRow["OwnerTypeIDSETY"]=dym["OwnerTypeID"];
		newRow["FOwnerIDSETY"]=dym["OwnerID"];
		newRow["BomIDSETY"]=dym["BomID"];
                
		newRow["FProduceDateSETY"]=dym["PRODUCEDATE"];
		newRow["FEXPIRYDATESETY"]=dym["FEXPIRYDATE"];
		newRow["AuxPropertyIDSETY"]=dym["AuxpropID"];
		newRow["ExtAuxUnitQtySETY"]=dym["F_ora_JSQty"];
		newRow["F_ora_KHHH"]=dym["F_ora_KHHH"];
		newRow["LotSETY"]=dym["Lot"];
		srcBillEntry1.Add(newRow);

注意:基础资料类型的字段,下游单据如果使用了引用属性,需要进行转换。

图标赞 10
10人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!