二开实现序列号单据备注保存写入序列号主档(Python实现)原创
16人赞赏了该文章
1,941次浏览
编辑于2022年03月08日 14:39:47
业务需求和C#的插件实现,参考文章:【二开实现单据录入携带序列号主档备注信息】,重写一个Python版本的实现,供参考。
import clr clr.AddReference('System') clr.AddReference('System.Data') clr.AddReference('Kingdee.BOS') clr.AddReference('Kingdee.BOS.Core') clr.AddReference('Kingdee.BOS.App.Core') clr.AddReference('Kingdee.BOS.App') clr.AddReference('Kingdee.BOS.DataEntity') clr.AddReference('Kingdee.BOS.Business.DynamicForm') clr.AddReference('Kingdee.BOS.ServiceHelper') clr.AddReference('Kingdee.BOS.Contracts') from Kingdee.BOS.Log import Logger from Kingdee.BOS import * from Kingdee.BOS.Core import * from Kingdee.BOS.Contracts import * from System.Data import * from System import * from System.Collections import * from Kingdee.BOS.App.Data import * from System.Collections.Generic import List from System.Collections.Generic import Dictionary from Kingdee.BOS.Core.DynamicForm.PlugIn import * from System import StringComparison from Kingdee.BOS.ServiceHelper import * from Kingdee.BOS.Core.Metadata.EntityElement import * def AfterExecuteOperationTransaction(e): if(this.OperationResult.IsSuccess == False): return if len(e.DataEntitys) == 0 or e.DataEntitys == None: return snEntryName = ""; entryName = ""; for entity in this.BusinessInfo.Entrys: if type(entity) is SNSubEntryEntity: snEntryName = entity.EntryName parentEntity = this.BusinessInfo.GetEntity(entity.ParentEntityKey) entryName = parentEntity.EntryName; if snEntryName == "": return; havaUpdateSerials = Dictionary[str,str]() for bill in e.DataEntitys: billEntry = bill[entryName] for entry in billEntry: snEntrys = entry[snEntryName] for sn in snEntrys: serialId = Convert.ToString(sn["SerialId_Id"]) serialNote = Convert.ToString(sn["SerialNote"]) if serialNote != "": havaUpdateSerials[serialId] = serialNote if havaUpdateSerials.Count > 0: lstSqlObj = List[SqlObject]() serialTmpTable = DBServiceHelper.CreateTemporaryTableName(this.Context) BuildUpdateDestSerialTmpTable(this.Context, serialTmpTable) serialDt = DataTable(serialTmpTable) otColumn1 = DataColumn() otColumn1.ColumnName = "FSERIALID" serialDt.Columns.Add(otColumn1) otColumn2 = DataColumn() otColumn2.ColumnName = "FDESCRIPTION" serialDt.Columns.Add(otColumn2) pythondict = dict(havaUpdateSerials) for key,value in pythondict.items(): dr = serialDt.NewRow() dr["FSERIALID"] = key dr["FDESCRIPTION"] = value serialDt.Rows.Add(dr) DBUtils.BulkInserts(this.Context, serialDt) sql = '''MERGE INTO T_BD_SERIALMASTER_L IT USING ( SELECT T1.FSERIALID, T1.FDESCRIPTION FROM {0} T1 JOIN T_BD_SERIALMASTER T2 ON T1.FSERIALID = T2.FSERIALID ) UT ON (IT.FSERIALID = UT.FSERIALID) WHEN MATCHED THEN UPDATE SET IT.FDESCRIPTION = UT.FDESCRIPTION '''.format(serialTmpTable) paras = List[SqlParam]() sqlObject = SqlObject(sql, paras) lstSqlObj.Add(sqlObject) if lstSqlObj.Count > 0: DBUtils.ExecuteBatch(this.Context, lstSqlObj) def BuildUpdateDestSerialTmpTable(ctx, tempTableName): sqlTM = " ( FSERIALID INT NOT NULL DEFAULT(0), FDESCRIPTION NVARCHAR(255) NULL)" sql = " CREATE TABLE {0} {1} ".format(str(tempTableName), str(sqlTM)) sqls = List[str]() sqls.Add(sql) guid = Guid.NewGuid() idxName = guid.ToString("N").Substring(0, 10) sql = " CREATE INDEX IDX_IDX_SERIALID{0} ON {1} ({2}) ".format(str(idxName), str(tempTableName), "FSERIALID") sqls.Add(sql) DBUtils.ExecuteBatchWithTime(ctx, sqls, sqls.Count, 120)
说明
1、从this.BusinessInfo.Entrys判断单据体的类型是否是序列号单据体类型SNSubEntryEntity,从而找到序列号单据和单据明细的实体对象,这样使得数据的获取在不同的单据之间可以通用
二开实现序列号单据备注保存写入序列号主档(Python实现) …(1.41KB)
赞 16
16人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读