客户需求:接着上一个文章,现在要根据预测单表体的物料带出期初库存数量、本周收单数量,总收单未出货数,年预测量,8周平均数量等二开字段,这些字段是通过sql视图做成一个数据源,在二开插件里面获取这个视图的值在写入都对应字段
代码实现:
import clr
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')
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 System.Net import *
from System.Text import *
from System.IO import *
from Kingdee.BOS.Core.Bill.PlugIn import *
from Kingdee.BOS.App.Data import *
from System.Collections.Generic import List
from Kingdee.BOS.ServiceHelper import *
# 根据物料编码,查询出期初库存数量、本周收单数量,总收单未出货数,年预测量,8周平均数量,赋值给对应栏位
def DataChanged(e):
# 检查触发事件的是否是FQty字段
if e.Field.Key == "FQty":
# 获取当前行的FMaterialId字段的值
cfmid = this.Model.GetValue("FMaterialId", e.Row)
# 如果FMaterialId字段的值为空,则返回
if cfmid is None:
return
# 将FMaterialId字段的值转换为字符串
fmid = str(cfmid["Id"])
# 如果fmid的长度小于等于0,则返回
if len(fmid) <= 0:
return
# 根据sql视图V_Custom_YCD查询对应的字段
sqlGetmu = ("""select A,FMATERIALID, E from V_Custom_YCD where FMATERIALID={0} """).format(fmid);
# 执行SQL查询,并将结果存储在muinfo中
muinfo = DBUtils.ExecuteDynamicObject(this.Context, sqlGetmu);
# 根据sql视图V_Custom_YCD查询赋值到对应变量
if not muinfo or not muinfo[0]:
return
# 获取muinfo的第一个元素
mu_info = muinfo[0]
# 获取mu_info中的A字段的值
A = mu_info [2]#期初库存
# 根据变量A的值,将其赋值到当前行的F_JA_QICHUQTY字段
this.Model.SetValue("F_JA_QICHUQTY", A, e.Row) # 期初库存
代码分享.rar(1.01KB)