二开实现单据保存写入批号主档(Python实现)
业务需求和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 * def AfterExecuteOperationTransaction(e): if(this.OperationResult.IsSuccess == False): return if len(e.DataEntitys) == 0 or e.DataEntitys == None: return havaUpdateLots = Dictionary[str,str]() for bill in e.DataEntitys: lotNote = bill["NOTE"].ToString() if lotNote == "": continue billEntry = bill["STK_MISCELLANEOUSENTRY"] for entry in billEntry: lotId = Convert.ToInt64(entry["Lot_Id"]) if lotId == 0: continue havaUpdateLots.Add(str(lotId), lotNote) if havaUpdateLots.Count > 0: lstSqlObj = List[SqlObject]() lotTmpTable = DBServiceHelper.CreateTemporaryTableName(this.Context) BuildUpdateDestLotTmpTable(this.Context, lotTmpTable) lotDt = DataTable(lotTmpTable); otColumn1 = DataColumn(); otColumn1.ColumnName = "FLOTID" lotDt.Columns.Add(otColumn1) otColumn2 = DataColumn(); otColumn2.ColumnName = "FLOTNOTE" lotDt.Columns.Add(otColumn2) pythondict = dict(havaUpdateLots) for key,value in pythondict.items(): dr = lotDt.NewRow() dr["FLOTID"] = key; dr["FLOTNOTE"] = value; lotDt.Rows.Add(dr); DBUtils.BulkInserts(this.Context, lotDt) sql = '''MERGE INTO T_BD_LOTMASTER IT USING ( SELECT T1.FLOTID, T1.FLOTNOTE FROM {0} T1 JOIN T_BD_LOTMASTER T2 ON T1.FLOTID = T2.FLOTID ) UT ON (IT.FLOTID = UT.FLOTID) WHEN MATCHED THEN UPDATE SET IT.FNOTETEXT = UT.FLOTNOTE; '''.format(lotTmpTable) paras = List[SqlParam](); sqlObject = SqlObject(sql, paras) lstSqlObj.Add(sqlObject) if lstSqlObj.Count > 0: DBUtils.ExecuteBatch(this.Context, lstSqlObj) def BuildUpdateDestLotTmpTable(ctx, tempTableName): sqlTM = " ( FLOTID INT NOT NULL DEFAULT(0), FLOTNOTE 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_LOTID{0} ON {1} ({2}) ".format(str(idxName), str(tempTableName), "FLOTID") sqls.Add(sql) DBUtils.ExecuteBatchWithTime(ctx, sqls, sqls.Count, 120)
说明:
1、有时候需要取表头字段,有时取表体字段,根据不同的业务场景针对性修改脚本即可
您好老师,BOS里面对应的字段是Note 和批号主档的FLOTNOTE嘛
没看到代码呢
二开实现单据保存写入批号主档(Python实现)
业务需求和C#的插件实现,参考文章:【二开实现单据保存写入批号主档】,重写一个Python版本的实现,供参考。import clrclr.AddReference('...
点击下载文档
上一篇:自动锁库解锁服务简介下一篇:有源单批号拣货不拣已经过期的物料
本文2024-09-16 19:05:58发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-26380.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章