a
This commit is contained in:
@@ -42,100 +42,76 @@ def OnPreparePropertys(e):
|
||||
def EndOperationTransaction(e):
|
||||
# * 保存8提交9审核1反审核26删除3
|
||||
if this.FormOperation.OperationId == 1:
|
||||
# raise Exception(JsonUtil.Serialize(e.DataEntitys))
|
||||
billNos = List[str]();
|
||||
for item in e.DataEntitys:
|
||||
DoCreatePackCode(item["BillNo"])
|
||||
|
||||
# 建立条码组装单
|
||||
def DoCreatePackCode(billNo):
|
||||
if billNo != "":
|
||||
sqlL = """/*dialect*/
|
||||
WITH #基础数据 AS (
|
||||
SELECT t0.FBILLNO AS 'packBillNo',t0.FMATERIALID,0 packEntryId,0 packSeq
|
||||
,ISNULL(t2.FID,0) 'barCodeId'
|
||||
,t2.FBARCODE
|
||||
,ISNULL(t2.FQTY,0) FQTY,ISNULL(t3.FID,0) packId
|
||||
,t0.FBILLNO,1 IS_Main,1 FYLRate
|
||||
FROM T_PRD_PACKAGEINSTOCK t0
|
||||
LEFT JOIN T_UNW_WMS_BARCODE t2 on t2.FBILLENTRYID = t0.FSRCBILLENTRYID AND t2.FBILLFORMID = 'PLN_FORECAST'
|
||||
LEFT JOIN T_UNW_WMS_PACKING t3 on t3.FBOXCODEID = t2.FID
|
||||
UNION ALL
|
||||
SELECT t0.FBILLNO AS 'packBillNo',t0e.FMATERIALID
|
||||
,t0e.FEntryID
|
||||
,t0e.FSeq
|
||||
,ISNULL(t2.FID,0) 'barCodeId'
|
||||
,t2.FBARCODE
|
||||
,ISNULL(t2.FQTY,0) FQTY,ISNULL(t3e.FID,0) packId
|
||||
,t0.FBILLNO,0,1.05
|
||||
FROM T_PRD_PACKAGEINSTOCK t0
|
||||
INNER JOIN T_PRD_PACKAGEINSTOCKENTRY t0e on t0.FID = t0e.FID
|
||||
LEFT JOIN T_UNW_WMS_BARCODE t2 on t2.FBILLENTRYID = t0e.FMOENTRYID AND t2.FBILLFORMID = 'PRD_MO'
|
||||
LEFT JOIN T_UNW_WMS_PACKINGENTRY t3e on t3e.FBARCODEID = t2.FID
|
||||
)
|
||||
SELECT t0.packBillNo,t0.IS_Main,t0.FMATERIALID,SUM(t0.FQTY) / t0.FYLRate FQTY,MAX(t0.barCodeId) barCodeId
|
||||
FROM #基础数据 t0
|
||||
WHERE t0.FBILLNO = '{0}'
|
||||
GROUP BY t0.packBillNo,t0.IS_Main,t0.FMATERIALID,t0.FYLRate
|
||||
ORDER BY t0.IS_Main DESC
|
||||
|
||||
""".format(billNo)
|
||||
dataList = DBServiceHelper.ExecuteDynamicObject(this.Context, sqlL);
|
||||
if dataList != None and dataList.Count > 0:
|
||||
|
||||
formID = "UNW_WMS_PACKING";
|
||||
|
||||
meta = MetaDataServiceHelper.Load(this.Context, formID)
|
||||
objType = meta.BusinessInfo.GetDynamicObjectType();
|
||||
newObj = DynamicObject(objType)
|
||||
|
||||
main = dataList[0];
|
||||
if main["IS_Main"] == 1:
|
||||
if main["barCodeId"] == 0:
|
||||
raise Exception("条码装箱单套件码未生成!")
|
||||
|
||||
newObj["BoxCodeId_Id"] = main["barCodeId"]
|
||||
newObj["Capacity"] = main["FQTY"]
|
||||
newObj["CreateOrgId_Id"] = this.Context.CurrentOrganizationInfo.ID
|
||||
newObj["CreatorId_Id"] = this.Context.UserId
|
||||
newObj["ModifierId_Id"] = this.Context.UserId
|
||||
entry = newObj["List"]
|
||||
for item in dataList:
|
||||
if item["IS_Main"] == 0:
|
||||
if item["barCodeId"] == 0:
|
||||
raise Exception("分录【{0}】条码未生成!".format(item["packSeq"]))
|
||||
|
||||
entity = entry.DynamicCollectionItemPropertyType.CreateInstance()
|
||||
entity["BarCodeId_Id"] = item["barCodeId"]
|
||||
entity["Qty"] = item["FQTY"]
|
||||
entry.Add(entity)
|
||||
|
||||
ObjList = List[DynamicObject]();#单据的数据包集合
|
||||
if entry.Count > 0:
|
||||
ObjList.Add(newObj);
|
||||
saveRslt = BusinessDataServiceHelper.Save(this.Context, meta.BusinessInfo ,ObjList.ToArray(), None, "Save");
|
||||
# raise Exception(JsonUtil.Serialize(newObj))
|
||||
|
||||
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]
|
||||
Reference in New Issue
Block a user