python插件-上游单据反审核自动反审核、删除下游单据
金蝶云社区-138xxxx3260
138xxxx3260
18人赞赏了该文章 3,395次浏览 未经作者许可,禁止转载编辑于2017年12月11日 09:03:47



#上游单据反审核操作插件
#--------------------------------------------begin-----------------------------
#FNOFFRECAMOUNT

#引入clr运行库
import clr
#import numpy as np
#添加对cloud插件开发的常用组件的引用
clr.AddReference('System')
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.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')
clr.AddReference('Kingdee.BOS.BusinessEntity')
from System import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core import List
from Kingdee.BOS.Core.List import *
from Kingdee.BOS.App.Data import DBUtils
from Kingdee.BOS.ServiceHelper import *
from Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs import *
from Kingdee.BOS import Orm
from Kingdee.BOS import *
from Kingdee.BOS.Orm.DataEntity import *
from Kingdee.BOS.Orm import *
from Kingdee.BOS.Core.DynamicForm.Operation import *
from Kingdee.BOS.Core.Metadata import *
from Kingdee.BOS.Util import *
from Kingdee.BOS.App import *
#from Kingdee.BOS.App.ServiceHelper import *
from Kingdee.BOS.Contracts import *
from Kingdee.BOS.Util.OperateOptionUtils import *
from System.Collections.Generic import *
from System.Collections.Generic import List, Dictionary
from Kingdee.BOS.BusinessEntity.BusinessFlow import *
from Kingdee.BOS.Core.BusinessFlow.ServiceArgs import *

def OnPreparePropertys(e):
e.FieldKeys.Add("FDOSTATUS");

def BeginOperationTransaction(e):
#清除自动下推的直接调拨单
for entity in e.DataEntitys:
fbillno=entity["billno"];
sql_list=[];
liststr="declare @FBILLNO varchar(50) set @FBILLNO='"+str(fbillno)+"'";
sql_list.append(liststr);
liststr= """
select distinct a.FID,b.FDOCUMENTSTATUS
from T_STK_STKTRANSFERINENTRY_R a
inner join T_STK_STKTRANSFERIN b on a.FID=b.FID and b.FBIJAUTOPUSHFLAG='1'
where a.FSRCBILLTYPEID='BIJ_CXLLD' and a.FSRCBILLNO=@FBILLNO
"""
sql_list.append(liststr)
vsql=" "
sqlStr='/*dialect*/'+vsql.join(sql_list)
objs=[];
objs2=[];
reader=DBUtils.ExecuteReader(this.Context, sqlStr);
while reader.Read():
objs2.append(reader[0]);
if reader[1]=="C":
objs.append(reader[0]);
reader.Close();
reader.Dispose();
objs2=tuple(objs2);
meta=MetaDataServiceHelper.Load(this.Context, "STK_TransferDirect");
if len(objs)>0:
UnAutidoption=OperateOption.Create();
UnAutidoption.SetVariableValue("IgnoreWarning",True);
UnAutidoption.SetVariableValue("_IgnoreInteraction_",True);
UnAutidoption.SetVariableValue("BIJ_OPTYPE",1);
ss1=KeyValuePair[object, object]();
pkEntityIds=List[type(ss1)]();
for p1 in objs:
pkEntityId=KeyValuePair[object, object](p1,"");
pkEntityIds.Add(pkEntityId);
paras=List[object]();
paras.Add("2");
paras.Add("");

UnAutidResult=BusinessDataServiceHelper.SetBillStatus(this.Context, meta.BusinessInfo, pkEntityIds,paras,"UnAudit",UnAutidoption);
SuccessFlag=UnAutidResult.IsSuccess;
if str(SuccessFlag)=="False":
ss="";
if UnAutidResult.OperateResult.Count>0:
ss=UnAutidResult.OperateResult[0].Message;
if UnAutidResult.ValidationErrors.Count>0:
ss=ss+","+UnAutidResult.ValidationErrors[0].Message;
ss=ss+","+str(UnAutidResult.InteractionContext);
raise NameError("反审核直接调拨单失败:"+ss);

if len(objs2)>0:
deloption=OperateOption.Create();
deloption.SetVariableValue("IgnoreWarning",True);
deloption.SetVariableValue("_IgnoreInteraction_",True);
deleteResult=BusinessDataServiceHelper.Delete(this.Context,meta.BusinessInfo,objs2,deloption,"Delete");
SuccessFlag=deleteResult.IsSuccess;
if str(SuccessFlag)=="False":
ss="";
if deleteResult.OperateResult.Count>0:
ss=deleteResult.OperateResult[0].Message;
if deleteResult.ValidationErrors.Count>0:
ss=ss+","+deleteResult.ValidationErrors[0].Message;
ss=ss+","+str(deleteResult.InteractionContext);
raise NameError("删除直接调拨单失败:"+ss);
#检测是否还存在下游单据
dataEntitySet=ExtendedDataEntitySet();
dataEntitySet.Parse(e.DataEntitys, this.BusinessInfo);
for entity in this.BusinessInfo.Entrys:
rows=dataEntitySet.FindByEntityKey(entity.Key);
for row in rows:
dd=IsPushArgs(this.BusinessInfo,entity.Key,row.DataEntity);
a22=BusinessFlowDataServiceHelper.IsPush(this.Context,dd);
if str(a22)=="True":
raise NameError("有其它关联下游单据!");
#--------------------------------------------end-----------------------------

#下游单据反审核插件
#--------------------------------------------begin-----------------------------

#FNOFFRECAMOUNT
#引入clr运行库
import clr
#import numpy as np
#添加对cloud插件开发的常用组件的引用
clr.AddReference('System')
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.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 System import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core import List
from Kingdee.BOS.Core.List import *
from Kingdee.BOS.App.Data import DBUtils
from Kingdee.BOS.ServiceHelper import *
from Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs import *
from Kingdee.BOS import Orm
from Kingdee.BOS import *
from Kingdee.BOS.Orm.DataEntity import *
from Kingdee.BOS.Orm import *
from Kingdee.BOS.Core.DynamicForm.Operation import *
from Kingdee.BOS.Core.Metadata import *
from Kingdee.BOS.Util import *
from Kingdee.BOS.App import *
#from Kingdee.BOS.App.ServiceHelper import *
from Kingdee.BOS.Contracts import *
from Kingdee.BOS.Util.OperateOptionUtils import *
from System.Collections.Generic import *
from System.Collections.Generic import List, Dictionary
from Kingdee.BOS.Core.Validation import *

#class OperValidator(AbstractValidator):
class OperValidator(AbstractValidator):
__opervalidatortype=0;
def __init__(self,ovtype):
self.__opervalidatortype=ovtype;
AbstractValidator.__init__(self);
def Validate(self,dataEntities,validateContext,ctx):
for dataEntity in dataEntities:
autopushflag=dataEntity["FBIJAUTOPUSHFLAG"];
if str(autopushflag)=="True" and self.__opervalidatortype==0:
validationErrorInfo=ValidationErrorInfo("",str(dataEntity["Id"]),dataEntity.DataEntityIndex,dataEntity.RowIndex,str(dataEntity["Id"]), "系统自动下推生成的单据禁止手工反审!","");
validateContext.AddError(None, validationErrorInfo);
continue;

def OnPreparePropertys(e):
e.FieldKeys.Add("FDOCUMENTSTATUS");
e.FieldKeys.Add("FBIJAUTOPUSHFLAG");

def OnAddValidators(e):
aa=this.Option.GetVariables();
optbyself=True;
for p in aa:
if p.Key=="BIJ_OPTYPE" and p.Value==1:
optbyself=False;
break;
if optbyself:
operValidator=OperValidator(0);
else:
operValidator=OperValidator(1);
operValidator.AlwaysValidate=True;
operValidator.EntityKey = "FBillHead";
e.Validators.Add(operValidator);