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 OnPreparePropertys(e): e.FieldKeys.Add("FLot"); #批号 e.FieldKeys.Add("F_RIWN_Decimal"); #长度 e.FieldKeys.Add("F_RIWN_Decimal1"); #面积 e.FieldKeys.Add("F_RIWN_Integer"); #接头个数 e.FieldKeys.Add("F_RIWN_Text2"); #生产型号 def AfterExecuteOperationTransaction(e): if(this.OperationResult.IsSuccess == False): return if len(e.DataEntitys) == 0 or e.DataEntitys == None: return for bill in e.DataEntitys: billEntry = bill["Entity"] #获取单据体 #判断是否需要反写批号主档 isNeed = 0 for entry in billEntry: lotId = Convert.ToInt64(entry["Lot_Id"]) if lotId > 0: isNeed = 1 break if isNeed == 1: 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 = "FCD" lotDt.Columns.Add(otColumn2) #面积 otColumn3 = DataColumn(); otColumn3.ColumnName = "FMJ" lotDt.Columns.Add(otColumn3) #接头个数 otColumn4 = DataColumn(); otColumn4.ColumnName = "FJTGS" lotDt.Columns.Add(otColumn4) #生产型号 otColumn5 = DataColumn(); otColumn5.ColumnName = "FSCXH" #定义字段 lotDt.Columns.Add(otColumn5) for entry in billEntry: lotId = Convert.ToInt64(entry["Lot_Id"]) if lotId == 0: continue cd = Convert.ToDecimal(entry["F_RIWN_Decimal"]) #长度 mj = Convert.ToDecimal(entry["F_RIWN_Decimal1"]) #面积 jtgs = Convert.ToInt32(entry["F_RIWN_Integer"]) #接头个数 scxh = entry["F_RIWN_Text2"] #生产型号 #往DataTable增加一行 dr = lotDt.NewRow() dr["FLOTID"] = lotId; dr["FCD"] = cd; dr["FMJ"] = mj; dr["FJTGS"] = jtgs; dr["FSCXH"] = scxh; lotDt.Rows.Add(dr); #往临时表插入数据 DBUtils.BulkInserts(this.Context, lotDt) #更新批号主档 sql = '''MERGE INTO T_BD_LOTMASTER IT USING ( SELECT T1.FLOTID, T1.FCD, T1.FMJ, T1.FJTGS,T1.FSCXH 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.F_RIWN_DECIMAL = UT.FCD, IT.F_RIWN_DECIMAL1 = UT.FMJ, IT.F_RIWN_INTEGER = UT.FJTGS, IT.F_RIWN_Text = UT.FSCXH; '''.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), FCD DECIMAL(23,10) NULL, FMJ DECIMAL(23,10) NULL, FJTGS INT NULL,FSCXH NVARCHAR(50) 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)
作者:Mr舍得
来源:金蝶云社区
原文链接:https://wenku.my7c.com/article/522505489805134848?productLineId=1
著作权归作者所有。未经允许禁止转载,如需转载请联系作者获得授权。
python生产入库单保存更新批号主档案
案例说明:生产入库单分录的自定义字段更新到批号主档案的自定义字段上import clrclr.AddReference('System')clr.AddReference('System.Dat...
点击下载文档
本文2024-09-16 17:44:25发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-17643.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章