Python插件 - 保存单据跨单据触发值更新事件并保存--未验证
5人赞赏了该文章
106次浏览
编辑于2024年10月22日 22:11:11
##案例:采购入库审核后修改采购订单字段并触发值更新
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;
本文转载自:ython插件 - 保存单据跨单据触发值更新事件并保存
作者:https://vip.kingdee.com/article/566941276848037888?productLineId=1&lang=zh-CN
原文链接:https://vip.kingdee.com/article/566941276848037888?productLineId=1&lang=zh-CN
赞 5
5人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!