Python插件 - 保存单据跨单据触发值更新事件并保存

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:2

Python插件 - 保存单据跨单据触发值更新事件并保存

例子:采购入库单【保存/审核/提交】操作后 **(本文用保存操作来演示**) 采购入库保存后在(AfterExecuteOperationTransaction)事件触发采购订单的值更新事件 - 例子简单的判断 通过采购入库明细表分录查找link关系表,关系表存在则更新上有采购订单单据头的字段,并触发值更新事件。 - 采购订单的配置 ![image.webp](/download/0100c9c47cdc02244950814358066e9625a9.webp) # 源码 ``` python #作者: 老李头(Dean) #描述: 采购入库审核后修改采购订单字段并触发值更新 import clr clr.AddReference("System") clr.AddReference("System.Core") clr.AddReference("Kingdee.BOS") clr.AddReference("Kingdee.BOS.App") clr.AddReference("Kingdee.BOS.Core") clr.AddReference("Kingdee.BOS.Contracts") clr.AddReference("Kingdee.BOS.DataEntity") clr.AddReference("Kingdee.BOS.ServiceHelper") from Kingdee.BOS import * from Kingdee.BOS.Core import * from Kingdee.BOS.Core.Bill import * from Kingdee.BOS.Util import * from Kingdee.BOS.App.Data import * from Kingdee.BOS.Core.DynamicForm import * from Kingdee.BOS.Core.DynamicForm.PlugIn import * from Kingdee.BOS.Core.DynamicForm.PlugIn.Args import * from Kingdee.BOS.Core.Metadata import * from Kingdee.BOS.Core.Metadata.FormElement import * from Kingdee.BOS.Orm import * from Kingdee.BOS.Orm.DataEntity import * from Kingdee.BOS.ServiceHelper import * from Kingdee.BOS.Util import * from System import * from System.ComponentModel import * from System.Linq import * #字段预加载(演示) #def OnPreparePropertys(e): #e.FieldKeys.Add("F_GXDJ"); #事务结束后事件 def AfterExecuteOperationTransaction(e): billid=""; Billno = ""; formId = "PUR_PurchaseOrder"; this.OperationResult.IsShowMessage = True; #单据数据包对象 - 如果获取不到就在预加载事件增加字段(OnPreparePropertys) obj = e.DataEntitys; #raise NameError(JsonUtil.Serialize(obj)); for item in obj: billid = item["Id"].ToString(); Billno = item["BillNo"].ToString(); InStockEntry = item["InStockEntry"]; #明细表单据体 #不存在关联跳过 - 防止报错 【这里没有判断上游是否采购订单,只做了简单的判断】 if InStockEntry is None or InStockEntry.Count == 0: continue; for instock_item in InStockEntry: lk = instock_item["FInStockEntry_Link"]; #关联关系表 if lk is None or lk.Count == 0: continue; SBillId = lk[0]["SBillId"] #采购内码 #创建视图 billView = CreateBillView(formId,SBillId); #加载视图数据 billView.LoadData(); #赋值 billView.Model.SetItemValueByID("F_SMTO_Text_qtr", "老李头小伙子测试一下", -1); #触发值更新服务 billView.InvokeFieldUpdateService("F_SMTO_Text_qtr", 0); try: #调用保存操作 billView.InvokeFormOperation(FormOperationEnum.Save); except e: raise NameError("采购订单值更新失败!"+str(e)); finally: #关闭视图 - 防止页面冲突 billView.Close(); def CreateBillView(formId,pkValue): #读取作业的元数据 meta = MetaDataServiceHelper.Load(this.Context, formId) #as FormMetadata; form = meta.BusinessInfo.GetForm(); # 创建用于引入数据的单据view type = Type.GetType("Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web"); billView = Activator.CreateInstance(type); # 开始初始化billView: # 创建视图加载参数对象,指定各种参数,如FormId, 视图(LayoutId)等 openParam = CreateOpenParameter(meta,pkValue); #动态领域模型服务提供类,通过此类,构建MVC实例 provider = form.GetFormServiceProvider(); billView.Initialize(openParam, provider); return billView; def CreateOpenParameter(metaData,pkValue): form = metaData.BusinessInfo.GetForm(); openPara = BillOpenParameter(form.Id, metaData.GetLayoutInfo().Id); #openPara = BillOpenParameter(form.Id, ""); openPara.Context = this.Context; openPara.ServiceName = form.FormServiceName; openPara.PageId = Guid.NewGuid().ToString(); openPara.FormMetaData = metaData; openPara.LayoutId = metaData.GetLayoutInfo().Id; openPara.Status = OperationStatus.EDIT #编辑 openPara.PkValue = pkValue; #采购订单主键 openPara.CreateFrom = CreateFrom.Default; openPara.ParentId = 0; openPara.GroupId = ""; openPara.DefaultBillTypeId = None; openPara.DefaultBusinessFlowId = None; openPara.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", False); plugins = form.CreateFormPlugIns(); openPara.SetCustomParameter(FormConst.PlugIns, plugins); return openPara; ``` # 部署插件 ![image.webp](/download/0100b1ccde300767412f96aa5cf09fd530fe.webp) # 成果展示 ![-y8z5virr5pqc76hm.webp](/download/01006af4523c81ea443499b94cb7246d9eef.webp)


老师,这里是不是多了一行?

Python插件 - 保存单据跨单据触发值更新事件并保存

例子:采购入库单【保存/审核/提交】操作后 **(本文用保存操作来演示**) 采购入库保存后在(AfterExecuteOperationTransaction)事件触...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息