电脑桌面
添加蚂蚁七词文库到电脑桌面
安装后可以在桌面快捷访问

单据表单插件用python从临时单据体数据添加到子单据体

来源:金蝶云社区作者:金蝶2024-09-163

单据表单插件用python从临时单据体数据添加到子单据体

业务场景:

    从一个临时单据体“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.Bus

单据表单插件用python从临时单据体数据添加到子单据体

业务场景: 从一个临时单据体“F_cc_Entity”,根据单据体“FEntity”的复选框“F_cc_CheckBox”勾选状态,循环添加到勾选行的子单据...
点击下载文档文档为doc格式

声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

已经是第一篇
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息
QQ群
  • 答案:my7c点击这里加入QQ群
支持邮箱
微信
  • 微信