Files
GateDge2023_ljy/14.宝锐/GZ.LJY000.Biori/UHIK_PRD_PACKAGE_INSTOCK/OperationEventPlugInEx.py
PastSaid 9725ab5376 a
2024-12-05 15:39:19 +08:00

141 lines
5.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#引入clr运行库
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.App.Core')
clr.AddReference('Kingdee.BOS.Contracts')
clr.AddReference('Kingdee.BOS.DataEntity')
clr.AddReference('Kingdee.BOS.ServiceHelper')
#dairycloud基础库中的常用实体对象分命名空间导入不会递归导入
from Kingdee.BOS.Core import *
from Kingdee.BOS.Util import *
from Kingdee.BOS.Core.Bill import *
from Kingdee.BOS.Core.List import *
from Kingdee.BOS.Core.Bill.PlugIn import *
from Kingdee.BOS.Orm.DataEntity import *
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.Args import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import *
from Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs import *
from System import *
from System.Data import *
from Kingdee.BOS.App.Data import *
from Kingdee.BOS.App import *
from Kingdee.BOS.Orm import *
from Kingdee.BOS.Contracts import *
from System.Collections.Generic import List
from Kingdee.BOS.ServiceHelper import *
from Kingdee.BOS.App.Core import *
def OnPreparePropertys(e):
# e.FieldKeys.Add("FPMoBillTypeId_Id")
e.FieldKeys.Add("FPMoBillTypeId")
e.FieldKeys.Add("FMoId")
e.FieldKeys.Add("FMoEntryId")
e.FieldKeys.Add("FMoBillTypeId")
e.FieldKeys.Add("FMOBillNo")
def EndOperationTransaction(e):
# * 保存8提交9审核1反审核26删除3
if this.FormOperation.OperationId == 1:
# raise Exception(JsonUtil.Serialize(e.DataEntitys))
dataEntityList = List[DynamicObject]()
for data in e.DataEntitys:
srcBillEntryId = data["FPSrcBillEntryId"]
if srcBillEntryId != None and srcBillEntryId > 0:
dataEntityList.Add(data)
if dataEntityList.Count > 0:
DoCreateMoRpt(dataEntityList)
def DoCreateMoRpt(dataEntitys):
"""组装入库单审核后生成汇报单
Args:
dataEntitys (_type_): 数据集
Raises:
Exception: _description_
Exception: _description_
Exception: _description_
"""
# raise Exception(JsonUtil.Serialize(dataEntitys))
# service = ServiceHelper.GetService[IConvertService]();
ctx = this.Context;
service = ConvertService();
# *源单据标识
sourceFormId = "PRD_MO";
# *目标单据标识
targetFormId = "PRD_MORPT";
# ruleMetaList = service.GetRulesByFormId(this.Context,sourceFormId,targetFormId)
# raise Exception(JsonUtil.Serialize(ruleMetaList))
convertRuleId = "PRD_MO2MORPT"
ruleMeta = service.GetConvertRule(this.Context,convertRuleId)
# ! 装管公式(毫升):管数 = 数量 / 装管量(ml) / 1.05
# ! 装管公式(微升):管数 = 数量 / 装管量(ml) / 1000 / 1.05
if ruleMeta != None:
policies = ruleMeta.Rule.Policies
billTypeElement = FirstOrDefault(policies,lambda x: x.ElementType == 7009)
if billTypeElement == None:
raise Exception("转换单据中单据类型属性类型值7009不存在。")
for item in dataEntitys:
for entity in item.FEntity:
raise Exception(JsonUtil.Serialize(entity))
# 来源单据工单类型
sourceBillTypeId = item["FPMoBillTypeId_Id"]
# 单据转换匹配类型
billTypeMap = FirstOrDefault(billTypeElement.BillTypeMaps,lambda x: x.SourceBillTypeId == sourceBillTypeId);
if billTypeMap == None:
raise Exception("转换规则中,工单单据类型不存在!")
# 单据下推设置
selectedRows = List[ListSelectedRow]();
selectedRows.AddRange(list(map(lambda x : ListSelectedRow(str(x.FMoId), str(x.FMoEntryId) ,0 ,sourceFormId),item.FEntity)))
pushArgs = PushArgs(ruleMeta.Rule, selectedRows.ToArray())
pushArgs.TargetBillTypeId = billTypeMap.TargetBillTypeId
# !转换服务
convertResult = service.Push(this.Context , pushArgs, OperateOption.Create());
destObjs = List[DynamicObject]()
destObjs.AddRange(map(lambda x:x.DataEntity ,convertResult.TargetDataEntities))
# raise Exception(JsonUtil.Serialize(destObjs))
# !单据加载服务
metaDataService = MetaDataService()
destFormMetadata = metaDataService.Load(ctx, targetFormId)
# !保存服务
saveService = SaveService()
saveResult = saveService.Save(ctx, destFormMetadata.BusinessInfo, destObjs.ToArray(), OperateOption.Create());
msg = "";
# 操作结果校验
if saveResult.ValidationErrors != None and saveResult.ValidationErrors.Count > 0:
errorInfoList = list(map(lambda x : x.Message,saveResult.ValidationErrors))
errorInfo = ";".join(errorInfoList);
raise Exception("未知原因导致自动保存失败原因:"+ errorInfo)
# raise Exception(JsonUtil.Serialize(pushArgs))
def FirstOrDefault(collection, func):
result = filter(func, collection)
if len(result) == 0: return None
return result[0]