单据转换多个单据体转换Python实现案例原创
金蝶云社区-Zenos
Zenos
36人赞赏了该文章 1,080次浏览 未经作者许可,禁止转载编辑于2023年03月15日 11:47:41

业务需求:一个单据有多个个单据体,想在单据转换中配置多个单据体下推,可是不支持多单据体字段转换映射的配置

示例:将收料通知单明细信息下推到检验单上的二开单据体上。

1678850248.jpg

image.png



#引入clr运行库

import clr

#添加对cloud插件开发的常用组件的引用

clr.AddReference('System')

clr.AddReference('System.Data')

clr.AddReference('Kingdee.BOS')

clr.AddReference('Kingdee.BOS.Core')

clr.AddReference('Kingdee.BOS.App')

clr.AddReference("Kingdee.BOS.App.Core")

clr.AddReference('Kingdee.BOS.Contracts')

clr.AddReference('Kingdee.BOS.DataEntity')

clr.AddReference('Kingdee.BOS.ServiceHelper')

#导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入)

from Kingdee.BOS import *

from Kingdee.BOS.Core import *

from Kingdee.BOS.Core.Bill import *

from Kingdee.BOS.Orm.DataEntity import *

from Kingdee.BOS.Contracts import *

from Kingdee.BOS.App import *

from Kingdee.BOS.Core.DynamicForm.PlugIn import *

from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import *

from System import *

from System.Data import *

from System.Text import *

from System.Collections import *

from System import StringComparison

from Kingdee.BOS.App.Data import *

from System.Collections.Generic import List

from Kingdee.BOS.ServiceHelper import *

from Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args import *

from Kingdee.BOS.Core.Metadata import SelectorItemInfo 

from Kingdee.BOS.Core.SqlBuilder import QueryBuilderParemeter 

from Kingdee.BOS.Contracts import *

from Kingdee.BOS.App.Core import *


global FBillNo

def OnGetSourceData(e):

global FBillNo

sourceData = e.SourceData;

FBillNo =  List[str]()

for row in sourceData:

FBillNo.Add(Convert.ToString(row["FID"]));

FBillNo = set(FBillNo)#定义变量,获取源单ID


def AfterConvert(e):

global FBillNo

mainEntity = e.TargetBusinessInfo.GetEntity("F_SHUU_Entity");

billDataEntitys = e.Result.FindByEntityKey("FBillHead");

obj = e.TargetBusinessInfo.GetEntryEntity("F_SHUU_Entity");

viewService = ViewService()

for item in billDataEntitys:

dataObject = item.DataEntity;

secondEntryRows = mainEntity.DynamicProperty.GetValue(dataObject)

secondEntryRows.Remove(secondEntryRows[0]);


for i in FBillNo:

sql = "/*dialect*/select * from T_PUR_ReceiveEntry where F_ZL_CheckBox='1' and fid in ('{0}')".format(i)#自行用SQL查找需要的字段

doc = DBServiceHelper.ExecuteDynamicObject(this.Context, sql,None)

for  OB in doc:

newRow =  DynamicObject(obj.DynamicObjectType)

Service = ServiceHelper.GetService<IViewService>()

FPAYMATERIALIDz = Convert.ToString(OB["FMaterialId"]);

if FPAYMATERIALIDz is not None and Convert.ToInt64(FPAYMATERIALIDz) > 0:

baseDataField = e.TargetBusinessInfo.GetField("F_SHUU_Base1")

vendor = viewService.LoadSingle(this.Context, OB["FMaterialId"], baseDataField.RefFormDynamicObjectType)

newRow["F_SHUU_Base1_Id"] = OB["FMaterialId"]#物料

newRow["F_SHUU_Base1"] = vendor

FPAYMATERIALID = Convert.ToString(OB["FAuxPropId"]);

if FPAYMATERIALID is not None and Convert.ToInt64(FPAYMATERIALID) > 0:

baseDataField1 = e.TargetBusinessInfo.GetField("F_SHUU_Flex")

vendor1 = viewService.LoadSingle(this.Context, OB["FAuxPropId"], baseDataField1.RefFormDynamicObjectType)

newRow["F_SHUU_Flex_Id"] =  OB["FAuxPropId"]#辅助属性

newRow["F_SHUU_Flex"] =  vendor1

FPAYMATERIALID1 = Convert.ToString(OB["FUnitId"]);

if FPAYMATERIALID1 is not None and Convert.ToInt64(FPAYMATERIALID1) > 0:

baseDataField2 = e.TargetBusinessInfo.GetField("F_SHUU_UnitID")

vendor2 = viewService.LoadSingle(this.Context, OB["FUnitId"], baseDataField2.RefFormDynamicObjectType)

newRow["F_SHUU_UnitID_Id"] =  OB["FUnitId"]#单位

newRow["F_SHUU_UnitID"] =  vendor2


FPAYMATERIALID2 = Convert.ToString(OB["FSTOCKID"]);

if FPAYMATERIALID2 is not None and Convert.ToInt64(FPAYMATERIALID2) > 0:

baseDataField3 = e.TargetBusinessInfo.GetField("F_SHUU_Base2")

vendor3 = viewService.LoadSingle(this.Context, OB["FSTOCKID"], baseDataField3.RefFormDynamicObjectType)

newRow["F_SHUU_Base2_Id"] =  OB["FSTOCKID"]#仓库

newRow["F_SHUU_Base2"] =  vendor3


newRow["F_SHUU_Lot_Id"] =  OB["FLot"]#批号

newRow["F_SHUU_Lot_Text"] =  OB["FLot_Text"]#批号文本


newRow["F_SHUU_Qty"] = Convert.ToString(OB["FActReceiveQty"]);

#newRow["F_SHUU_Base1"] = material;

secondEntryRows.Add(newRow);


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