单据表单插件用python从临时单据体数据添加到子单据体原创
金蝶云社区-枫少
枫少
26人赞赏了该文章 2,764次浏览 未经作者许可,禁止转载编辑于2020年08月16日 22:58:45

业务场景:

    从一个临时单据体“F_cc_Entity”,根据单据体“FEntity”的复选框“F_cc_CheckBox”勾选状态,循环添加到勾选行的子单据体“F_cc_xsm_entry_cf”。

其中有个位置至今还没搞懂为什么:

    在添加对基础资料字段赋值时候,为什么不能用newobject["FBW"]=cfentityRow["FBW2"],这样会造成保存时候实际上没保存到;不知道是不是因为内存地址都同时指向了临时单据体的DynamicObject原因造成的,但是SetValue又不会??


代码冗余比较多,听说python写的代码可以短点,如果有大神可以帮忙优化一下的话,请指点下小弟,感激!


import clr
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.DataEntity')

from Kingdee.BOS.Core import *
import Kingdee.BOS.Orm.DataEntity as de

def ButtonClick(e):
    #获取临时录入的成分数据
    cfentity=this.View.BusinessInfo.GetEntity("F_cc_Entity")
    
    #获取单据体
    entity=this.View.BusinessInfo.GetEntity("FEntity")
    
    #获取子单据体,此单据体是一个集合,根据每个集合的属性去找关联单据体
    subentity=this.View.BusinessInfo.GetEntity("F_cc_xsm_entry_cf")
    
    if e.Key.ToString()=="FBATHADD":
        AddSubEntity(entity,subentity,cfentity)
    if e.Key.ToString()=="FBATHDEL":
        DelSubEntity(entity,subentity,cfentity)
        
    #最后updateview刷新界面
    this.View.UpdateView("F_cc_xsm_entry_cf")
    
#批量添加
def AddSubEntity(entity,subentity,cfentity):
    #获取临时单据体数据航,DynamicObjectCollection
    cfentityRows=cfentity.DynamicProperty.GetValue(this.Model.DataObject)
    #获取单据体数据航,DynamicObjectCollection
    entityRows=entity.DynamicProperty.GetValue(this.Model.DataObject)
    if entityRows:
        #循环单据体
        for entityRow in entityRows:
            #是否勾选
            if entityRow["F_cc_CheckBox"]==True:
                #根据单据体行获取关联子单据体集合
                subEntityRows = subentity.DynamicProperty.GetValue(entityRow)
                if cfentityRows:
                    #循环临时单据体
                    for cfentityRow in cfentityRows:
                        #判断是否存在
                        isExists=False
                        #循环子单据体
                        for subEntityRow in subEntityRows:
                            if subEntityRow:
                                if cfentityRow["FBW2"] and subEntityRow["FBW"] and cfentityRow["FCF2"] and subEntityRow["FCF"]:
                                    #组合条件,不存在则添加
                                    if cfentityRow["FBW2"]["Number"]==subEntityRow["FBW"]["Number"] and cfentityRow["FCF2"]["Number"]==subEntityRow["FCF"]["Number"]:
                                        isExists=True
                                        break
                        if not isExists:

                            #创建子单据体行结构
                            newobject=de.DynamicObject(subEntityRows.DynamicCollectionItemPropertyType)
                            this.View.Model.SetValue(this.View.BusinessInfo.GetField("FBW"),newobject,cfentityRow["FBW2"])
                            this.View.Model.SetValue(this.View.BusinessInfo.GetField("FVALUE"),newobject,cfentityRow["FVALUE2"])
                            this.View.Model.SetValue(this.View.BusinessInfo.GetField("FCF"),newobject,cfentityRow["FCF2"])
                            subEntityRows.Add(newobject)

#批量删除
def DelSubEntity(entity,subentity,cfentity):
    #获取临时单据体数据航,DynamicObjectCollection
    cfentityRows=cfentity.DynamicProperty.GetValue(this.Model.DataObject)
    #获取单据体数据航,DynamicObjectCollection
    entityRows=entity.DynamicProperty.GetValue(this.Model.DataObject)
    if entityRows:
        #循环单据体
        for entityRow in entityRows:
            #是否勾选
            if entityRow["F_cc_CheckBox"]==True:
                #根据单据体行获取关联子单据体集合
                subEntityRows = subentity.DynamicProperty.GetValue(entityRow)
                if cfentityRows:
                    #循环临时单据体
                    for cfentityRow in cfentityRows:
                        removeList=[]
                        #循环子单据体
                        for subEntityRow in subEntityRows:
                            if subEntityRow:
                                if cfentityRow["FBW2"] and subEntityRow["FBW"] and cfentityRow["FCF2"] and subEntityRow["FCF"]:
                                    #组合条件,把要删除的数据添加进removeList
                                    if cfentityRow["FBW2"]["Number"]==subEntityRow["FBW"]["Number"] and cfentityRow["FCF2"]["Number"]==subEntityRow["FCF"]["Number"]:
                                        removeList.append(subEntityRow)
                        #删除数据
                        if removeList:
                            for removedata in removeList:
                                subEntityRows.Remove(removedata)        

图标赞 26
26人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!