python 校验

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

python 校验

import clr 
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.App')
clr.AddReference('System')
clr.AddReference('System.Core')

from System import *
from System.Linq import *
from System import DateTime 
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.Metadata import *
from Kingdee.BOS.Core.Metadata.EntityElement import *
from Kingdee.BOS.Core.Validation import *
from Kingdee.BOS.Log import Logger
from Kingdee.BOS.App.Data import *


def OnPreparePropertys(e):
    e.FieldKeys.Add("FMoEntryId") #加载字段

def OnAddValidators(e):
    validator  = OneValidator()
    validator.EntityKey = "FBillHead"
    validator.AlwaysValidate = True
    e.Validators.Add(validator)

class OneValidator(AbstractValidator):
    def Validate(self, dataEntities, validateContext,ctx):
        global maxdate
        for bill in dataEntities:
            entrys = bill["Entity"]
            billId = str(bill["Id"])
            billdate=bill.DataEntity["Date"]
            for entry in entrys:
                seq = entry["Seq"]#序号
                qty = entry["ActualQty"]
                Moid=entry["MoEntryId"]
                qtysql=("/*dialect*/ select FQTY from T_PRD_MOENTRY  t1 inner join (select   FMoEntryId,sum(FRealQty) sumFRealQty from  T_PRD_INSTOCKENTRY  group by FMoEntryId ) t2 on t1.FENTRYID=t2.FMOENTRYID where t1.FENTRYID={0} and t1.FQTY=t2.sumFRealQty").format(Moid)#检查入库数量和生产订单数量是否相等

                qtys=DBUtils.ExecuteDynamicObject(this.Context,qtysql)
                if qtys.Count>0:
                    Sql=("/*dialect*/ select FDATE from T_PRD_INSTOCK t1 inner join T_PRD_INSTOCKENTRY t2 on t1.FID=t2.FID  where FMoEntryId={0} order by FDATE ").format(Moid)#获取所有入库单的日期
                    datas=DBUtils.ExecuteDynamicObject(this.Context,Sql)
                    if datas.Count>0 :
                        maxdate=datas[0]["FDATE"]
                        for data in datas:
                            if data["FDATE"]>=maxdate:
                                maxdate=data["FDATE"]#取最后的入库单日期
                        billyear=billdate.Year
                        year=maxdate.Year
                        billmonth=billdate.Month
                        month=maxdate.Month
                        if billyear != year or ( billyear == year and  billmonth>month):
                            msg = "补料单行号【{0}】最后入库单日期不在同一期间,请检查".format(seq)
                            info = ValidationErrorInfo("",billId, bill.DataEntityIndex,bill.RowIndex,billId,msg,"表体校验",ErrorLevel.Error)
                            validateContext.AddError(None,info)

python 校验

import clr clr.AddReference('Kingdee.BOS')clr.AddReference('Kingdee.BOS.Core')clr.AddReference('Kingdee.BOS.App')clr.AddReference(...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息