import clr clr.AddReference("System") clr.AddReference('System.Data') clr.AddReference("Kingdee.BOS") clr.AddReference("Kingdee.BOS.DataEntity") clr.AddReference("Kingdee.BOS.Core") clr.AddReference('Kingdee.BOS.App') clr.AddReference("Kingdee.BOS.ServiceHelper") from Kingdee.BOS.Core import * from Kingdee.BOS.Util import * from Kingdee.BOS.Orm.DataEntity import * from Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn import * from Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args import * from System import * from System.Data import * from System.Collections.Generic import * from Kingdee.BOS.ServiceHelper import * # python:已生成条码的数据不能重复生成! def OnParseFilter(e): # raise Exception(e.FilterPolicySQL) fromId = e.SourceBusinessInfo.GetForm().Id; e.FilterPolicySQL = e.FilterPolicySQL + """ AND NOT EXISTS ( SELECT 1 FROM T_PRD_MOASSEMBLE_LK uwbc WHERE uwbc.FSID = t0.FID AND uwbc.FSTableName = 'T_PLN_FORECAST1' ) """ e.PlugFilterDesc = "已生成组装单的数据不能重复生成!"; return; # def OnParseFilter(e): # raise Exception(e.FilterPolicySQL) def FirstOrDefault(collection, func): """仿Linq的FirstOrDefault Args: collection (_type_): 数据集 func (_type_): lambda公式 Returns: _type_: 获取数据集第一个或null """ result = filter(func, collection) if len(result) == 0: return None return result[0] # 数据转换完毕后触发事件 def AfterConvert(e): # 选单 # if this.OperationNumber == "Draw": # # 下推 # if this.OperationNumber == "Push": # raise Exception(JsonUtil.Serialize(e.TargetBusinessInfo)) billHead = e.Result.FindByEntityKey("FBillHead")[0].DataEntity # raise Exception(JsonUtil.Serialize(billHead)) srcBillEntryId = billHead["FPSrcBillEntryId"] # raise Exception(str(FPSrcBillEntryId)) # 来源类型 srcBillType = billHead["FSrcBillType"] if srcBillType == 'PLN_FORECAST': sqlL = """/*dialect*/ DECLARE @EntryId int SET @EntryId = {0} ;WITH #预测单数据 AS ( --套件子项 SELECT t0.FBILLNO,t0e.FID,t0e.FENTRYID,t0e.FMATERIALID ,t0e.FROWID,t0e.FPARENTROWID,t0e.FBOMID,t0e.FBOMENTRYID,t0e.FOWNERID,t0e.FOWNERTYPEID ,t0e.FPRODUCTTYPE,t0e.FSEQ,t0e.F_UHIK_TEXT8 AS '标签货号' ,t0e.F_UHIK_QTY2 AS '父项数量',t0e.F_UHIK_TEXT2 AS '标签规格_Note' ,t0e.FSTOCKORGID AS '库存组织',t0e.F_HUOHAO AS '货号' ,t0e.F_UHIK_DATE AS '标签生产日期' ,t0e.F_UHIK_LOT AS '标签批号' FROM T_PLN_FORECAST t0 INNER JOIN T_PLN_FORECASTENTRY t0e on t0.FID = t0e.FID INNER JOIN T_PLN_FORECASTENTRY t2e on t2e.FROWID = t0e.FPARENTROWID WHERE 1 = 1 AND t0e.FPRODUCTTYPE = 2 AND t2e.FENTRYID = @EntryId ) SELECT t1.FNUMBER,t1_l.FNAME,t0.*,t2.* FROM #预测单数据 t0 INNER JOIN T_BD_MATERIAL t1 on t1.FMATERIALID = t0.FMATERIALID INNER JOIN T_BD_MATERIAL_L t1_l on t1_l.FMATERIALID = t0.FMATERIALID AND t1_l.FLOCALEID = 2052 CROSS APPLY ( SELECT t2.FBILLNO AS 'MOBIllNo',t2.FBILLTYPE AS 'MoBillType',t2.FID AS 'MoId',t2e.FENTRYID AS 'MoEntryId' ,t2e.F_GZQty,t2e.F_GS_QTY,t2e.F_FYL_QTY,t2e.FQTY ,t2e.FLOT,t2e.FLOT_TEXT,t2e.FUNITID ,t2e.F_UHIK_DATE '生产日期',t2e.F_UHIK_DATE1 '有效期至' FROM T_PRD_MO t2 INNER JOIN T_PRD_MOENTRY t2e on t2.FID = t2e.FID INNER JOIN T_PRD_MOENTRY_A t2e_a on t2e.FENTRYID = t2e_a.FENTRYID AND t2e_a.FREQSRC = 2 WHERE 1 = 1 AND t2e.FSALEORDERENTRYSEQ = t0.FSEQ AND t2e.FSALEORDERNO = t0.FBILLNO ) t2 """.format(srcBillEntryId) # raise Exception(sqlL) dataList = DBServiceHelper.ExecuteDynamicObject(this.Context, sqlL) if dataList != None and dataList.Count > 0: entrys = billHead["FEntity"] # ea = e.TargetBusinessInfo.Entrys[0].DynamicObjectType.Name entityType = entrys[0].DynamicObjectType # raise Exception(firstEntry.DynamicObjectType.Name) #! 物料 matFld = e.TargetBusinessInfo.GetField("FMaterialId"); #! 货主 ownerFId = e.TargetBusinessInfo.GetField("FOwnerId"); #! 批号 lotFId = e.TargetBusinessInfo.GetField("FLot"); #! 单据类型 moBillTypeFId = e.TargetBusinessInfo.GetField("FMoBillTypeId"); #! 计量单位 unitFId = e.TargetBusinessInfo.GetField("FUnitID") FPStockOrgObj = billHead["FPStockOrgId"] FPStockOrgId_Id = billHead["FPStockOrgId_Id"] entrys.Clear() for idx,item in enumerate(dataList): entry = DynamicObject(entityType) entry["Seq"] = idx + 1; # 物料 matId = item["FMATERIALID"] entry["FMaterialId_Id"] = matId matObj = BusinessDataServiceHelper.LoadSingle(this.Context, matId, matFld.RefFormDynamicObjectType) entry["FMaterialId"] = matObj # 产品类型 entry["FProductType"] = item["FPRODUCTTYPE"] # 来源单据 entry["FSrcBillId"] = item["FID"] entry["FSrcBillEntryId"] = item["FENTRYID"] # 生产订单数据 moBillTypeId = item["MoBillType"] entry["FMoId"] = item["MoId"] entry["FMoEntryId"] = item["MoEntryId"] entry["FMoBillTypeId_Id"] = moBillTypeId moBillTypeObj = BusinessDataServiceHelper.LoadSingle(this.Context, moBillTypeId, moBillTypeFId.RefFormDynamicObjectType) entry["FMoBillTypeId"] = moBillTypeObj if billHead["FPMoId"] == 0: billHead["FPMoId"] = item["MoId"] billHead["FPMOBillNo"] = item["MOBIllNo"] billHead["FPMoBillTypeId_Id"] = moBillTypeId billHead["FPMoBillTypeId"] = moBillTypeObj # 货主类型 entry["FOwnerTypeId"] = item["FOWNERTYPEID"] # 货主 ownerId = item["FOWNERID"] if ownerId > 0 : ownerObj = BusinessDataServiceHelper.LoadSingle(this.Context, ownerId, ownerFId.RefFormDynamicObjectType) entry["FOwnerId_Id"] = ownerId entry["FOwnerId"] = ownerObj # 批号 lotId = item["FLOT"] if lotId > 0: lotObj = BusinessDataServiceHelper.LoadSingle(this.Context, lotId, lotFId.RefFormDynamicObjectType) entry["FLot_Id"] = lotId entry["FLot"] = lotObj; entry["FLot_Text"] = item["FLOT_TEXT"] # 计量单位 unitId = item["FUNITID"] if unitId > 0: unitObj = BusinessDataServiceHelper.LoadSingle(this.Context, unitId, unitFId.RefFormDynamicObjectType) entry["FUnitID_Id"] = unitId entry["FUnitID"] = unitObj # 库存组织 entry["FStockOrgId_Id"] = FPStockOrgId_Id entry["FStockOrgId"] = FPStockOrgObj entry["FLabHuoHao"] = item["标签货号"] entry["FGZLQty"] = item["F_GZQty"] entry["FLabSpec"] = item["标签规格_Note"] entry["FZGSQty"] = item["F_GS_QTY"] entry["FHuoHao"] = item["货号"] entry["FProducedDate"] = item["生产日期"] entry["FExpiryDate"] = item["有效期至"] # entry[""] = item["标签生产日期"] # 富余量 entry["FFYLQty"] = item["F_FYL_QTY"] entry["FQty"] = item["FQTY"] entry["FRptQty"] = item["FQTY"] entry["FNoInStockQty"] = item["FQTY"] entrys.Add(entry)