本文介绍了在使用金蝶ERP系统时,如何通过编程方式实现在不同模块间快捷查询物料清单(BOM)的需求。作者通过网上查询和自学摸索,实现了物料正查与反查之间的相互跳转,并扩展了从其他模块(如计划订单列表、生产订单列表等)中直接跳转到物料清单正查的功能。代码中包含了使用Python和金蝶BOS(Business Object Service)框架的示例,通过调用API和设置参数来动态打开查询窗口,并传递所需物料编码等信息,从而简化了查询流程,提高了工作效率。同时,作者也提醒了代码中的部分代码含义和作用尚不完全清楚,但不影响实现实际问题的目的。
场景:当我们需要展开查询BOM时,往往需要复制物料编码,然后回到主页,然后再打开物料清单正查窗口,粘贴,然后查询,当我们想要看其中某项物料的共用性(还有哪些BOM中有用到此物料)时,我们又得复制物料编码,然后回到主页,打开物料清单反查窗口,粘贴,然后查询。
注:本次分享的内容是属于非专业人士经过网上查询+自学摸索得出的结果(很多代码我也不知道具体啥作用,啥含义),请勿喷。我们以解决实际问题为目的。
(其它模块中也可能有此需求,比如计划订单列表,生产订单列表,随处都想能快捷查看到对应的BOM,甚至成品层级的BOM.)
解:1,先讲物料正查与反查相互跳转. (根据所选行的对应物料编码进行跳转查询)
物料清单正查跳转到反查
代码如下:
#引入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')
#导入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 *
def OnInitialize(e):
global dic;
dic=this.View.OpenParameter.GetCustomParameter("FBomVersion");
def AfterCreateNewData(e):
parentFormId=this.View.ParentFormView.BillBusinessInfo.GetForm().Id;
if parentFormId=="ENG_BOM":
this.View.Model.SetItemValueByNumber("FBomVersion",dic,0)
def AfterBindData(e):
parentFormId=this.View.ParentFormView.BillBusinessInfo.GetForm().Id;
if parentFormId=="ENG_BOM":
this.View.ButtonClick("FRefresh","")
代码如下:
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Log import *
def ButtonClick(e):
key=e.Key.ToUpperInvariant();
if(key=="F_ora_Button_qtr".ToUpperInvariant()):#点击按钮
c =this.View.Model.GetEntryCurrentRowIndex("FBottomEntity");
obj=this.View.Model.GetValue("FMaterialId2",c)
mtrlId=obj["Id"];
#this.View.ShowMessage(str(mtrlId))
parameteropt =DynamicFormShowParameter();
parameteropt.FormId = "ENG_BomQueryBackward";
parameteropt.CustomParams.Add("FMtrlId", str(mtrlId));#FBomVersion
parameteropt.CustomParams.Add("FUseOrgId", str(1));
parameteropt.ParentPageId = this.View.PageId;
this.View.ShowForm(parameteropt);
2,物料清单反查跳转到正查
代码如下:
def BeforeBindData(e):
c=this.View.ParentFormView.BillBusinessInfo.GetForm().Id;
#this.View.ShowMessage(c);
if (c <> "BOS_MainConsoleNewSutra"):#c == "PLN_PLANORDER" or c == "PRD_MO" or c == "SUB_SUBREQORDER"):
this.View.ButtonClick("F_ora_Button_re5","");
def ButtonClick(e):
key=e.Key.ToUpperInvariant();
if(key=="F_ora_Button_re5".ToUpperInvariant()):#点击按钮
c=this.View.OpenParameter.GetCustomParameter("FMtrlId");
if (c is not None):
this.View.Model.SetItemValueByID("FMtrlId",c,0);
#this.View.Model.SetItemValueByID("FMaterialID",c,0);
this.View.Model.SetValue("FBillMaterialId",this.View.Model.GetValue("FMtrlId",0),0);
this.View.ButtonClick("FReloadData","")#触发按钮
else:
this.View.ButtonClick("FReloadData","")#触发按钮
代码如下:
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Log import *
def ButtonClick(e):
key=e.Key.ToUpperInvariant();
if(key=="F_ora_Button_apv".ToUpperInvariant()):#点击按钮
c =this.View.Model.GetEntryCurrentRowIndex("FBottomEntity");
#if selectedRow.Count==0:
# this.View.ShowErrMessage("没有选择任何数据,请先选择数据!");
# return;
# if selectedRow.Count>1:
# this.View.ShowErrMessage("只能选择一行数据操作,请重新选择数据!");
# return;
obj=this.View.Model.GetValue("FMaterialId2",c)
mtrlId=obj["Id"];
parameteropt =DynamicFormShowParameter();
parameteropt.FormId = "ENG_BomQueryForward2";
parameteropt.CustomParams.Add("FMaterialId", str(mtrlId));#FBomVersion
parameteropt.CustomParams.Add("FUseOrgId", str(1));
parameteropt.ParentPageId = this.View.PageId;
this.View.ShowForm(parameteropt);
>>>>>>正查,反查相互跳转功能到此结束<<<<<<<
2,从其它模块的列表清单中,根据所选行内容进行快捷跳转到物料清单正查.
从物料清单中打开物料清单正查为例:
(在物料清单模块中,默认菜单里是没有<物料清单正查>的,当我们想展开BOM检查时,只能用树形维护,有时候可能这种呈现效果并不理想.)
代码如下:
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Log import *
def ButtonClick(e):
key=e.Key.ToUpperInvariant();#按钮标识大写
if(key=="F_BOMBT".ToUpperInvariant()):
billObj = this.View.Model.DataObject;
mtrlId=billObj["Number"];#MATERIALID_id
#mtrlId=billObj["MATERIALID_id"];
#useOrgId = obj[0]["FUseOrgId_Id"];#这个是组织码,如果多组织,可能需要用这个,下面的str(1)也要换str(useOrgId)
#mtrlId = obj[0]["FNumber"];#mtrlId = obj[0]["FMATERIALID_Id"];
#mtrlId=this.View.Model.GetValue("FMATERIALID",0);
parameteropt =DynamicFormShowParameter();
parameteropt.FormId = "ENG_BomQueryForward2";
#parameteropt.CustomParams.Add("FMaterialId", str(mtrlId));#FBomVersion,FNumber
parameteropt.CustomParams.Add("FBomVersion", str(mtrlId));#FBomVersion
parameteropt.CustomParams.Add("FUseOrgId", str(1));
parameteropt.ParentPageId = this.View.PageId;
this.View.ShowForm(parameteropt);
>>>>>>>>>>从物料清单的菜单中打开物料清单正查功能到此结束<<<<<<<<<<<<<<<<<
3,从销售订单列表打开物料清单正查,(展开BOM,未按版本号,仅按物料编码.)
代码如下:
def BarItemClick(e):
if e.BarItemKey=='ora_tbButton_B':
selectedRow = this.ListView.SelectedRowsInfo;
if selectedRow.Count==0:
this.View.ShowErrMessage("没有选择任何数据,请先选择数据!");
return;
if selectedRow.Count>1:
this.View.ShowErrMessage("只能选择一行数据操作,请重新选择数据!");
return;
obj = this.ListModel.GetData(selectedRow);
#useOrgId = obj[0]["FUseOrgId_Id"];
mtrlId = obj[0]["FMATERIALID_Id"];
parameteropt =DynamicFormShowParameter();
parameteropt.FormId = "ENG_BomQueryForward2";
parameteropt.CustomParams.Add("FMaterialId", str(mtrlId));
parameteropt.CustomParams.Add("FUseOrgId", '1');
parameteropt.ParentPageId = this.View.PageId;
this.View.ShowForm(parameteropt);
>>>>>>>>>>>>>>>>>>>>从销售订单列表打开物料清单正查功能到此结束.<<<<<<<<<<<<<<<<<<<<<<<
推荐阅读