金蝶云星空批改单据体字段

#引入clr运行库
import clr
#添加对cloud插件开发的常用组件的引用
clr.AddReference('System')
clr.AddReference('System.Data')
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.App')
clr.AddReference('Kingdee.BOS.ServiceHelper')
clr.AddReference('Newtonsoft.Json')
#导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入)
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.Bill import *
from Kingdee.BOS.Core.Metadata.ElementMetadata import*
from Kingdee.BOS.Core.DynamicForm import *
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import *
from Kingdee.BOS.Core.List import*
from Kingdee.BOS.Core.List.PlugIn import *
from Kingdee.BOS.Core.SqlBuilder import *
from Kingdee.BOS.Core.Metadata import *
from System import *
from System.Data import *
from Kingdee.BOS.App.Data import *
from System.Collections.Generic import List
from Kingdee.BOS.ServiceHelper import *
from Newtonsoft.Json import JsonConvert
from Newtonsoft.Json.Linq import *
from Kingdee.BOS.JSON import*

BukEditFormId="TXBE_BulkEditFldInput";#批改字段录入动态表单界面标识
BukEditBarItemKey="TXBE_tbBukEdit";#单据列表自定义的批改菜单标识
notAllowStatus=["123123123123123123123123123123"];#不允许批改的单据状态,例如,已审核(C)不允许批改,批改执行时,自动忽略该状态的单据,不进行批改操作
BulkEditFlds=["FWorkShopId1"];#需要批改的字段集合
def getEntityType(entityType):
    if(entityType==ElementType.ELEMENTTYPE_BILLHEAD):#单据头
        return "单据头";
    elif(entityType==ElementType.ELEMENTTYPE_SUBBILLHEAD):#子单据头
        return "子单据头";
    elif(entityType==ElementType.ELEMENTTYPE_BILLBODY):#单据体
        return "单据体";
    else:
        return "";
def ChildFromClosed(obj):
    if (obj.ReturnData == None):
        return;
    msg=("批改完成:{0}").format(obj.ReturnData);
    this.View.ShowMessage(msg);
    this.View.Refresh();
    #this.ListView.RefreshSelectRows(this.ListView.SelectedRowsInfo);#只刷新选中行,但是会把表头字段刷新出来
#弹出动态表单子页面的方法
def ShowListEditForm(ListData):
    global BukEditFormId,BulkEditFlds,notAllowStatus;
    enumList=List[EnumItem]();
    warningMsgList=[];
    for fldKey in BulkEditFlds:
        fld=this.View.BillBusinessInfo.GetField(fldKey);
        if(fld is None):
            err=("设定需要字段标识[{0}],在当前单据不存在,请检查!").format(fldKey);
            this.View.ShowWarnningMessage(err);
            return;
        fldType=fld.GetType().Name;
        fldEntity=fld.Entity;
        fldEntityKey=fldEntity.Key;#所属实体的标识
        fldEntityProName=fldEntity.EntryName;#所属实体对应的ORM实体属性标识
        fldEntityEleType=getEntityType(fldEntity.ElementType);
        entityName=fld.Entity.Name;
        fldName=("{0}.{1}").format(entityName,fld.Name);
        #子单据体不支持
        if(fldEntity.GetType().Name=="SubEntryEntity" or fldEntity.GetType().BaseType.Name=="SubEntryEntity"):
            msg=("字段[{0},{1}],是子单据体[{2},{3}]中的字段,暂不支持子单据体字段批量修改,批改界面不会显示该字段!").format(fldKey,fldName,fldEntityKey,entityName);
            warningMsgList.append(msg);
            continue;
        if(fldEntityEleType in ["单据体"]):
            if(ListData[0].EntryEntityKey<>fldEntityKey):
                msg=("字段[{0},{1}],是单据体字段,列表必须显示该单据体[{2},{3}],才能批改单据体字段,批改界面不会显示该字段!").format(fldKey,fldName,fldEntityKey,entityName);
                warningMsgList.append(msg);
                #this.View.ShowWarnningMessage(msg);
                continue;
        enumItem = EnumItem();
        enumItem.Caption=LocaleValue(fldName,2052);
        enumItem.EnumId=fldKey;
        enumItem.Value=fldKey;
        enumList.Add(enumItem);
    if(len(warningMsgList)>0):
        this.View.ShowWarnningMessage("\r\n".join(warningMsgList));
    dynamicFormShowParameter=DynamicFormShowParameter();
    guid = str(Guid.NewGuid());
    dynamicFormShowParameter.PageId=guid;
    dynamicFormShowParameter.FormId=BukEditFormId;#动态表单子页面FormID  
    dynamicFormShowParameter.CustomComplexParams.Add("ListData", ListData);#将构建好的参数传入子页面
    dynamicFormShowParameter.CustomComplexParams.Add("FldList", enumList);
    dynamicFormShowParameter.CustomComplexParams.Add("notAllowStatus", notAllowStatus);
    this.View.ShowForm(dynamicFormShowParameter, Action[FormResult](ChildFromClosed));#弹出动态表单

   
#列表菜单点击后事件,列表菜单点击完成后触发
#使用时一定要判断菜单标识!!!
#自定义菜单功能实现建议在此事件中完成
def AfterBarItemClick(e):
    global BukEditBarItemKey;
    key=e.BarItemKey.ToUpperInvariant();
    if(key==BukEditBarItemKey.ToUpperInvariant()):
        selectedRowsInfo=this.ListView.SelectedRowsInfo;#列表勾选的数据集
        billIDs=selectedRowsInfo.GetPrimaryKeyValues();
        #entryIDs=selectedRowsInfo.GetEntryPrimaryKeyValues();
        if (billIDs.Length<= 0):
            this.View.ShowWarnningMessage("未选择任何行!");
            return;
        #msg=("选中了[{0}]个单据,[{1}]条明细!").format(billIDs.Length,entryIDs.Length);
        #this.View.ShowMessage(msg);
        ShowListEditForm(selectedRowsInfo);


需要修改的地方:
BukEditBarItemKey字段修改为按钮对应的标识(按钮加在列表菜单中)
BulkEditFlds 字段中存放需要修改的字段标识
修改完成后将插件注册到列表插件中

 

posted on 2024-12-04 11:07  这一生,谢谢自己  阅读(12)  评论(0编辑  收藏  举报