Python继承AbstractValidator实现校验器案例
【业务背景】
组装拆卸单成品跟子件物料编码相同时,设置相同仓库,批次不能相同才能保存,或者批次相同,但是不允许仓库相同
【需求分析】
从业务背景中分析得出,只有满足以下3种条件的任意一种,才允许保存
1、成品子件:仓库相同,批号不同
2、成品子件:批号相同,仓库不同
3、成品子件:仓库批号均不同
通常的做法,保存的服务端校验一般有两种方式:
1、使用BOS提供的校验规则
2、使用校验器进行校验
【插件实现】
import clr clr.AddReference('System') clr.AddReference('Kingdee.BOS') clr.AddReference('Kingdee.BOS.Core') from System import * from Kingdee.BOS.Core import * from Kingdee.BOS.Core.Validation import * from Kingdee.BOS.Log import Logger def OnAddValidators(e): validator = AssemblyStockLotExValidator() validator.EntityKey = "FBillHead" validator.AlwaysValidate = True e.Validators.Add(validator) class AssemblyStockLotExValidator(AbstractValidator): def Validate(self, dataEntities, validateContext,ctx): for bill in dataEntities: products = bill["ProductEntity"] for product in products: productSeq = Convert.ToInt32(product["Seq"]) subs = product["STK_ASSEMBLYSUBITEM"] stock = product["StockID"] lot = product["Lot"] material = product["MaterialID"] for sub in subs: destStock = sub["FStockIDSETY"] destLot = sub["LotSETY"] destMaterial = sub["MaterialIDSETY"] if str(material["Id"]) == str(destMaterial["Id"]): # and Convert.ToString(material["Number"]).StartsWith("03"): if product["Lot_Text"] != '' and sub["LotSETY_Text"] != '' and not( (str(stock["Id"]) == str(destStock["Id"]) and product["Lot_Text"] != sub["LotSETY_Text"]) \ or (str(stock["Id"]) != str(destStock["Id"]) and product["Lot_Text"] == sub["LotSETY_Text"]) \ or (str(stock["Id"]) != str(destStock["Id"]) and product["Lot_Text"] != sub["LotSETY_Text"]) ): billId = str(bill["Id"]) msg = '''组装拆卸单{0}第{1}行物料{2}-{3}仓库或批号不符合保存条件,保存不成功'''.format(bill.BillNo, productSeq, Convert.ToString(material["Number"]), Convert.ToString(material["Name"])) info = ValidationErrorInfo("",billId, bill.DataEntityIndex,productSeq,billId, msg,"表体校验",ErrorLevel.Error) validateContext.AddError(None,info)
Python继承AbstractValidator实现校验器案例
【业务背景】组装拆卸单成品跟子件物料编码相同时,设置相同仓库,批次不能相同才能保存,或者批次相同,但是不允许仓库相同【需求分析】从...
点击下载文档
本文2024-09-16 19:06:12发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-26412.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章