入库类单据可以实时管控到库存是否超出上限(超出最大库存)
需求:控制库存不能超过设置的最大库存。
实现思路:在单据保存或者审核操作上进行校验,获取即时库存以及本单数量与最大库存进行对比,如果超出了最大库存就不能保存或审核。
Python脚本如下(注册在保存或者审核操作上):
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 = StockMaxQtyValidator() validator.AlwaysValidate = True validator.EntityKey = "FBillHead" e.Validators.Add(validator) class StockMaxQtyValidator(AbstractValidator): def Validate(self, dataEntities, validateContext, ctx): if len(dataEntities) == 0: return for bill in dataEntities: billId = bill["Id"] sqlText = '''select T1.* from (select a.FSTOCKORGID,b.FMATERIALID,b.FNUMBER,c.FMAXSTOCK,SUM(a.FBASEQTY+ts.FBASEUNITQTY) FBASEQTY from T_STK_INVENTORY a join T_BD_MATERIAL b on b.FMASTERID=a.FMATERIALID and b.FUSEORGID=a.FSTOCKORGID join T_BD_MATERIALSTOCK c on c.FMATERIALID=b.FMATERIALID join T_STK_INSTOCK t on t.FSTOCKORGID=a.FSTOCKORGID --对于采购入库单,其他单据需要修改表名 join T_STK_INSTOCKENTRY ts on ts.FID=t.FID and ts.FMATERIALID=b.FMATERIALID --对于采购入库单,其他单据需要修改表名 where c.FISENABLEMAXSTOCK='1' and t.FID={0} group by a.FSTOCKORGID,b.FMATERIALID,b.FNUMBER,c.FMAXSTOCK) T1 where T1.FMAXSTOCK<=T1.FBASEQTY'''.format(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-16 18:59:49发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-25741.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章