【学习笔记】-运用Python进行单据变更原创
8人赞赏了该文章
727次浏览
编辑于2022年09月09日 13:48:03
单据中的一些字段变更形式,简单归纳了以下几种方式:1.直接单据修改,2.启用单据变更单,3.下游单据反写,4.执行计划,定时计算更新5二开插件执行。对于一些已结账的单据,需要变更时,就需要 插件进行处理(谨慎处理)
①列表菜单,新增自定义按钮,并注册python插件
#列表插件 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.ServiceHelper') #导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入) from Kingdee.BOS import * from Kingdee.BOS.Core import * from Kingdee.BOS.Core.Bill import * from Kingdee.BOS.Core.DynamicForm.PlugIn import * from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import * from Kingdee.BOS.Core.List import* from Kingdee.BOS.Core.List.PlugIn import * from Kingdee.BOS.Core.SqlBuilder import * from Kingdee.BOS.Core.Metadata import * from System import * from System.Data import * from Kingdee.BOS.App.Data import * from System.Collections.Generic import List from Kingdee.BOS.ServiceHelper import * def BarItemClick(e): key=e.BarItemKey.ToUpperInvariant(); if(key<>"UPMUTL".ToUpperInvariant()): return; selectedRowsInfo=this.ListView.SelectedRowsInfo;#列表勾选的数据集 billIDs=selectedRowsInfo.GetPrimaryKeyValues(); entryIDs=selectedRowsInfo.GetEntryPrimaryKeyValues(); datas = this.ListModel.GetData(selectedRowsInfo);#根据勾选的数据集获取数据包 pkfids="";pkid="";pkno=""; if (datas.Count <= 0): this.View.ShowWarnningMessage("未选择任何行!"); return; for row in datas: pkno+=","+row["FBILLNO"];#单据编号 pkfids+=","+str(row["FID"]);#单据ID for eid in entryIDs: if(str(eid)<>""): pkid+=","+str(eid); pkno=pkno[1:]; pkfids=pkfids[1:]; if(pkid<>""): pkid=pkid[1:]; dynamicFormShowParameter = DynamicFormShowParameter(); guid = str(Guid.NewGuid()); dynamicFormShowParameter.PageId=guid; dynamicFormShowParameter.FormId="ora_ScrkChange"; dynamicFormShowParameter.CustomComplexParams.Add("pkid", pkid);#将构建好的参数传入子页面,参数标识是"DIC" dynamicFormShowParameter.CustomComplexParams.Add("pkno", pkno); dynamicFormShowParameter.CustomComplexParams.Add("pkfids", pkfids); dynamicFormShowParameter.CustomComplexParams.Add("row", "0"); dynamicFormShowParameter.CustomComplexParams.Add("F_ora_Date", ""); dynamicFormShowParameter.CustomComplexParams.Add("F_ora_Text1", ""); dynamicFormShowParameter.CustomComplexParams.Add("F_ora_CheckBox", "0"); this.View.ShowForm(dynamicFormShowParameter);#弹出动态表单
②创建动态表单,根据需要修改的字段内容,创建对应字段
③注册动态表单python插件
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.ServiceHelper') #导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入) from Kingdee.BOS import * from Kingdee.BOS.Core import * from Kingdee.BOS.Core.Bill import * from Kingdee.BOS.Core.DynamicForm.PlugIn import * from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import * from System import * from System.Data import * from Kingdee.BOS.App.Data import * from System.Collections.Generic import List from Kingdee.BOS.ServiceHelper import * def OnLoad(e): pkno=str(this.View.OpenParameter.GetCustomParameter("pkno")); this.View.Model.SetValue("Fbillno", pkno); F_ora_Date=str(this.View.OpenParameter.GetCustomParameter("F_ora_Date")); #this.View.Model.SetValue("F_ora_Date", F_ora_Date)); this.View.Model.SetValue("F_ora_Text1", this.View.OpenParameter.GetCustomParameter("F_ora_Text1")); this.View.Model.SetValue("F_ora_CheckBox", str(this.View.OpenParameter.GetCustomParameter("F_ora_CheckBox"))); def ButtonClick(e): key=e.Key.ToUpper(); if(key=="F_ORA_UPDATE"): F_ora_CheckBox ="0";F_ora_Text1=""; if(this.Model.GetValue("F_ora_CheckBox").ToString()=="True"): F_ora_CheckBox="1"; ksql="/*dialect*/update T_PRD_INSTOCKENTRY SET F_ora_CheckBox="+F_ora_CheckBox; pkid=str(this.View.OpenParameter.GetCustomParameter("pkid")); pkfid=str(this.View.OpenParameter.GetCustomParameter("pkfids")); if(pkid=="None" and pkfid=="None"): this.View.ShowMessage("单据不存在!"); return; F_ora_Date = str(this.Model.GetValue("F_ora_Date")); if(F_ora_Date<>"None"): ksql+=",F_ora_Date=CAST('"+F_ora_Date+"' as datetime)"; F_ora_Text1= this.Model.GetValue("F_ora_Text1"); if(F_ora_Text1==None): F_ora_Text1=""; if(pkid<>"None" and pkid<>""): ksql+=",F_ORA_TEXT2='"+F_ora_Text1+"' where FENTRYID in ("+pkid+")"; else: ksql+=",F_ORA_TEXT2='"+F_ora_Text1+"' where FID in ("+pkfid+")"; DBServiceHelper.Execute(this.Context,ksql); this.View.ShowMessage("更新成功"); else: this.View.Close();
推荐阅读