单据保存、反审核等操作,判断是否库存已关账、是否生成凭证校验二开插件
单据在保存、审核、反审核等操作时,有时需要校验单据所在日期是否已经关账、该单据是否已经生成凭证。
插件注册在相应的操作上,如保存操作。
代码示例如下(有源码附件):
import clr clr.AddReference('System') clr.AddReference('Kingdee.BOS') clr.AddReference('Kingdee.BOS.Core') clr.AddReference('Kingdee.BOS.ServiceHelper') from System import * from System import StringComparison from Kingdee.BOS.Core import * from Kingdee.BOS.Core.Metadata.EntityElement import * from Kingdee.BOS.Core.Validation import * from Kingdee.BOS.Log import Logger from Kingdee.BOS.ServiceHelper import * def OnAddValidators(e): #判断是否关账 validator = StockOrgCloseDateValidator() validator.AlwaysValidate = True validator.EntityKey = "FBillHead" e.Validators.Add(validator) #单据是否生成凭证 validator2 = BillVoucherValidator() validator2.AlwaysValidate = True validator2.EntityKey = "FBillHead" e.Validators.Add(validator2) #判断是否关账 class StockOrgCloseDateValidator(AbstractValidator): def Validate(self, dataEntities, validateContext, ctx): if len(dataEntities) == 0: return for bill in dataEntities: targetOrgId = bill["StockOrgId_Id"] # 单据库存组织 sqlText = "select max(FCLOSEDATE) FCLOSEDATE FROM T_STK_CLOSEPROFILE WHERE FCATEGORY = 'STK' and FORGID = " + str(targetOrgId); dyObjs = DBServiceHelper.ExecuteDynamicObject(this.Context, sqlText) if dyObjs.Count == 0: continue date = Convert.ToDateTime(bill["Date"]) # 单据业务日期 closeDate = Convert.ToDateTime(dyObjs[0]["FCLOSEDATE"]) if date < closeDate: errorMsg = "单据日期{0}必须大于库存组织最后关账日期{1}" info = ValidationErrorInfo("",str(bill["Id"]), bill.DataEntityIndex, bill.RowIndex, "关账日期校验", errorMsg.format(str(date), str(closeDate)), str(bill["BillNo"]), ErrorLevel.Error) validateContext.AddError(None,info) #判断单据是否生成凭证 class BillVoucherValidator(AbstractValidator): def Validate(self, dataEntities, validateContext, ctx): if len(dataEntities)==0: return curFormId=validateContext.BusinessInfo.GetForm().Id for bill in dataEntities: billId=bill["Id"] sqlText="SELECT FSOURCEBILLID FROM T_BAS_Voucher WHERE FSOURCEBILLKEY = '"+curFormId+"' AND FSOURCEBILLID="+str(billId); dyObjs = DBServiceHelper.ExecuteDynamicObject(this.Context, sqlText) if dyObjs.Count > 0: errorMsg = "单据{0}已生成凭证" info = ValidationErrorInfo("",str(bill["Id"]), bill.DataEntityIndex, bill.RowIndex, "单据凭证校验", errorMsg.format(str(bill["BillNo"])), str(bill["BillNo"]), ErrorLevel.Error) validateContext.AddError(None,info)
单据保存、反审核等操作,判断是否库存已关账、是否生成凭证校验二开插件
单据在保存、审核、反审核等操作时,有时需要校验单据所在日期是否已经关账、该单据是否已经生成凭证。插件注册在相应的操作上,如保存操作...
点击下载文档
本文2024-09-23 02:55:02发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-155521.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章