需求:需要获取月度材料成本,而且需要保留结果,不能以报表的形式实现,通过单据获取数据保留结果,后来发现通过Python实现很简单。
#引入clr运行库
import clr
#添加对cloud插件开发的常用组件的引用
clr.AddReference('System')
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference("Kingdee.BOS.ServiceHelper")
clr.AddReference('Kingdee.BOS.App')
from System import *
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.ServiceHelper import *
from Kingdee.BOS.App.Data import *
def AfterButtonClick(e):
if e.Key == "FBTHQCB":
FYear = this.Model.GetValue("FYear");
FMonth = this.Model.GetValue("FMonth");
if FYear is None or FMonth is None:
this.View.ShowErrMessage("请先填写日期!");
return;
sql = ("/*dialect*/ ETC_P_HS_NBCB '{0}','{1}'").format(FYear,FMonth);
dbs = DBServiceHelper.ExecuteDynamicObject(this.Context, sql, None);
if len(dbs) > 0:
this.Model.DeleteEntryData("FEntity");
for i in range (len(dbs)):
db = dbs[i];
this.Model.CreateNewEntryRow("FEntity");
this.Model.SetValue("FCOLFC",db["分厂"],i);
this.Model.SetValue("FCOLFL",db["分类"],i);
this.Model.SetValue("FCOLCZ",db["材质"],i);
this.Model.SetValue("FCOLZCB",db["总成本"],i);
this.View.UpdateView("FEntity");
else:
if e.Key == "FBTHQNDCB":
FYear = this.Model.GetValue("FYear");
FMonth = this.Model.GetValue("FMonth");
if FYear is None:
this.View.ShowErrMessage("请先填写年份!");
return;
sql
= ("/*dialect*/ SELECT FCOLFC,FCOLFL,FCOLCZ,sum(FCOLZCB) FCOLZCB FROM
ETC_T_HS_FCNBCBEntity MX left join ETC_T_HS_FCNBCB DJ on DJ.FID = MX.FID
where FYEAR='{0}' group by FCOLFC,FCOLFL,FCOLCZ ").format(FYear);
dbs = DBServiceHelper.ExecuteDynamicObject(this.Context, sql, None);
if len(dbs) > 0:
this.Model.DeleteEntryData("FEntity");
for i in range (len(dbs)):
db = dbs[i];
this.Model.CreateNewEntryRow("FEntity");
this.Model.SetValue("FCOLFC",db["FCOLFC"],i);
this.Model.SetValue("FCOLFL",db["FCOLFL"],i);
this.Model.SetValue("FCOLCZ",db["FCOLCZ"],i);
this.Model.SetValue("FCOLZCB",db["FCOLZCB"],i);
this.View.UpdateView("FEntity");
推荐阅读