单据表单插件-python插件开发-点击单据体按钮,弹出物料清单列表,选择子项物料返回数据到单据体原创
3人赞赏了该文章
54次浏览
未经作者许可,禁止转载编辑于2024年11月11日 10:50:36
需求部门希望在BOS单据的单据体中选择物料清单中子项物料信息,方便操作,提高效率。
故编写表单插件,实现点击按钮,弹出物料清单列表,勾选行,点击返回物料,数据返回到单据体中,如下图:
分享代码,供大家参考。
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('Kingdee.BOS.KDSReportEntity')
clr.AddReference('Kingdee.BOS.App.KDSService')
clr.AddReference('Newtonsoft.Json')
clr.AddReference('Kingdee.BOS.DataEntity')
clr.AddReference('Kingdee.BOS.Contracts')
clr.AddReference('Kingdee.BOS.WebApi.Client')
#导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入)
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.Bill import *
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel 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 Kingdee.BOS.JSON import *
from Newtonsoft.Json.Linq import *
from Kingdee.BOS.Core.List import *
from Kingdee.BOS.Core.List.PlugIn import *
from System.Text import *
from System.Collections import *
from System.Collections.Generic import *
from Kingdee.BOS.Orm.Metadata.DataEntity import *
from Kingdee.BOS.Orm.DataEntity import *
from Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn import *
from Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args import *
from Kingdee.BOS.ServiceHelper import *
from Kingdee.BOS.Core.Metadata.EntityElement import *
from Newtonsoft.Json import JsonConvert
from Kingdee.BOS.Core.SqlBuilder import *
from Kingdee.BOS.Core.Metadata import*
#弹出BOM列表的方法
def ShowFilterList():
listPara = ListShowParameter()
guid = str(Guid.NewGuid())
listPara.PageId=guid
listPara.FormId="ENG_BOM"
listPara.IsLookUp = True
listPara.IsShowApproved = True
this.View.ShowForm(listPara,Callback)
def AfterEntryBarItemClick(e):
key=e.BarItemKey;
if(str(key)=="tbSelectBOM"):
ShowFilterList();#弹出子页面
def Callback(callBack_Data): #这个是回调函数,只能有一个参数
res = callBack_Data.ReturnData
if str(res) == 'None':
this.View.ShowErrMessage("请选择至少一行物料清单分录行数据!");#显示错误提示信息
else:
fentryids = res.GetEntryPrimaryKeyValues()
array_length = len(fentryids)
if array_length > 0:
joined_fentryids = ','.join(str(x) for x in fentryids)
#this.View.ShowMessage(str(joined_fentryids))
#执行MSSQL,获取BOM子项信息
sql = """/*dialect*/SELECT T0.FID,t0.FNUMBER fBOMnumber,t0.FMATERIALID FPMATERIALID,t1.FMATERIALID FCMATERIALID,fnumerator,t1.FUNITID
FROM T_ENG_BOM t0
LEFT OUTER JOIN T_ENG_BOMCHILD t1 ON t0.FID = t1.FID
LEFT OUTER JOIN T_ENG_BOM_L t0_L ON (t0.FID = t0_L.FID AND t0_L.FLocaleId = 2052)
LEFT OUTER JOIN T_BD_MATERIAL st07 ON t0.FMATERIALID = st07.FMATERIALID
WHERE t1.FENTRYID in ({0}) """.format(joined_fentryids)
result = DBUtils.ExecuteDynamicObject(this.Context, sql)
if result and result.Count > 0:
for row in result:
FID = "{0}".format(row['FID'])
FPMATERIALID = "{0}".format(row['FPMATERIALID'])
FCMATERIALID = "{0}".format(row['FCMATERIALID'])
FNUMERATOR = "{0}".format(row['fnumerator'])
FUNITID = "{0}".format(row['FUNITID'])
#FREMARKS = FID+'_'+FPMATERIALID+'_'+FCMATERIALID+'_'+FNUMERATOR
#this.View.ShowMessage(FREMARKS)
# 单据体最后新增一个空白行,并更新编码、备注信息
this.View.Model.CreateNewEntryRow("FReturnMaterialEntity");#为单据体新增一行
row = this.View.Model.GetEntryCurrentRowIndex("FReturnMaterialEntity");#获取单据体当前焦点行号
this.View.Model.SetItemValueByID("FBOMID_R",FID,row-1) #更新BOM版本号
this.View.Model.SetItemValueByID("FFMATERIALID_R",FPMATERIALID,row-1) #更新父项ID
this.View.Model.SetItemValueByID("FCHILDMATERIALID_R",FCMATERIALID,row-1) #更新子项ID
this.View.Model.SetItemValueByID("FUNITID_R",FUNITID,row-1) #更新单位
this.View.Model.SetValue("FMUSTQTY_R",FNUMERATOR,row-1) #更新BOM分子数量
else:
this.View.ShowErrMessage("请选择至少一行物料清单分录行数据!");#显示错误提示信息
赞 3
3人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读