#引入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.DataEntity')
clr.AddReference('Kingdee.BOS.Contracts')
clr.AddReference('Kingdee.BOS.ServiceHelper')
clr.AddReference('Newtonsoft.Json')
# clr.AddReference('Kingdee.K3.SCM')
#clr.AddReference('Kingdee.BOS.Orm')
#导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入)
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Contracts import *
from Kingdee.BOS.Orm.DataEntity import *
from Kingdee.BOS.DataEntity import *
from Kingdee.BOS.Core.Bill import *
from Kingdee.BOS.Core.DynamicForm 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 Newtonsoft.Json import JsonConvert
from Newtonsoft.Json.Linq import *
from Kingdee.BOS.Orm import *
from Kingdee.BOS.DataEntity import *
# from Kingdee.K3.SCM.App.Core import *
def OnPreparePropertys(e):
e.FieldKeys.Add("FBillTypeId"); #单据单据类型,标识 667e76c006c8a9
#def EndOperationTransaction(e):
def BeginOperationTransaction(e):#AfterExecuteOperationTransaction(e):
#这里获取单据数据包方式和前面一样
SrcBillNolist=[];
PkIds=List[object]();#执行空操作的单据内码集合
for billObj in e.DataEntitys: #获取单据整体数据(可能是多个单据)
billId=billObj["Id"];#单据ID 113907
billNo=billObj["BillNo"];#单据编号 WLYS2406290004
BillTypeId=billObj["BillTypeId"] #获取单据类型
#typeID=BillTypeId["ID"] #获取单据类型ID
typeNumber=""
stockid=0
matstockid=""
matfmid=""
if BillTypeId!=None:
typeNumber=BillTypeId["Number"] #获取单据类型编码
#raise Exception(str(typeNumber)) #QTCKD01_SYS
Dept=billObj["DeptId"] #获取领料部门信息
if Dept!=None:
stocknc=Dept["F_TXBE_Base_qtr_83g"] #获取商贸农场仓库信息
if stocknc!=None:
stockid=stocknc["Id"]
matstockid="and stock.FStockId='{0}'".format(stockid)
#stockjc=Dept["F_TXBE_Base_qtr"] #获取商贸集采仓库信息
F_TXBE_Stock=billObj["F_TXBE_Stock"] #获取库存是否充足
F_TXBE_feiliao=billObj["F_TXBE_feiliao"] #是否农药或肥料
StockOrg=billObj["StockOrgId"] #获取库存组织
stockTrue=False
if StockOrg!=None:
StockOrgId=StockOrg["Number"] #获取库存组织ID
if StockOrgId in('1082','1087','4101','4102','4103','4104','4105','4107','4109','4110','4111','4112','4115','4117','9999'):
stockTrue=True
if typeNumber=="QTCKD01_SYS" and F_TXBE_Stock>=1 and F_TXBE_feiliao>0 and stockTrue==True:
entity=billObj["BillEntry"]#进一步解析单据体,明细信息
fmid=""
for rObj in entity:#在单据体中开始取值,判断,赋值
FMATERIALID=rObj["MaterialId"] #获取物料信息
if FMATERIALID!=None:
fmid=FMATERIALID["Number"]
matfmid="and m.fnumber='{0}'".format(fmid)
# service = StockLockService.GetInstance();
#raise Exception(str(FMATERIALID))
# #根据库存维度等信息查找即时库存
# invStock = service.getInvStockID(this.Context, stockId, stockLocID, lotID, ownerTypeID, ownerID,materialID).FirstOrDefault();
sql="""
select
a.FBASEQTY-0 as FBASEQTY
from T_STK_INVENTORY a
left join T_BD_LOTMASTER lotStock on lotStock.FLOTID=a.FLOT and lotStock.FMATERIALID=a.FMATERIALID and a.FSTOCKORGID=lotStock.FUSEORGID
left JOIN (SELECT TLKE.FSUPPLYINTERID AS FINVENTRYID, SUM(TLKE.FBASEQTY) AS FBASELOCKQTY,
SUM(TLKE.FSECQTY) AS FSECLOCKQTY
FROM T_PLN_RESERVELINKENTRY TLKE INNER JOIN T_PLN_RESERVELINK TLKH ON TLKE.FID = TLKH.FID
WHERE TLKE.FSUPPLYFORMID = 'STK_Inventory' AND TLKE.FLINKTYPE = '4'
GROUP BY TLKE.FSUPPLYINTERID) TSUB ON a.FID = TSUB.FINVENTRYID
inner join T_BD_MATERIAL m on m.FMATERIALID=a.FMATERIALID
inner join T_BD_MATERIAL_L mL on ml.FMATERIALID=m.FMATERIALID and ml.FLOCALEID=2052
inner join t_BD_StockStatus kczt on kczt.FSTOCKSTATUSID=a.FSTOCKSTATUSID
inner join T_BD_STOCKSTATUS_L kcztL on kcztL.FSTOCKSTATUSID=kczt.FSTOCKSTATUSID and kcztL.FLOCALEID=2052
inner join T_BD_UNIT_L baseUnit on baseUnit.FUNITID=a.FBASEUNITID and baseUnit.FLOCALEID=2052
inner join T_BD_Stock_L stockL on stockL.FSTOCKID=a.FSTOCKID and stockL.FLOCALEID=2052
inner join T_BD_Stock stock on stockL.FSTOCKID=stock.FSTOCKID
where a.FBASEQTY>0 and FSTOCKORGID=1137712 {0} {1}
""".format(matstockid,matfmid)
# try:
ds = DBUtils.ExecuteDataSet(this.Context,sql);
tab = ds.Tables[0];
FBASEQTY=0
tabcount=tab.Rows.Count
if tabcount==0:
rObj["F_TXBE_Ten_Qty"]=0
else:
for dr in tab.Rows:
FBASEQTY=dr["FBASEQTY"];
rObj["F_TXBE_Ten_Qty"]=FBASEQTY