单据转换部分代码
import clr
clr.AddReference("System")
clr.AddReference("System.Data")
clr.AddReference("System.XML")
clr.AddReference("System.Web.Extensions")
clr.AddReference("Kingdee.BOS")
clr.AddReference("Kingdee.BOS.Core")
clr.AddReference("Kingdee.BOS.DataEntity")
clr.AddReference("Kingdee.BOS.ServiceHelper")
clr.AddReference("Newtonsoft.Json")
clr.AddReference("Kingdee.BOS.Contracts")
clr.AddReference("Kingdee.BOS.App")
clr.AddReference("System.Web")
clr.AddReference("Kingdee.BOS.WebApi.Client")
import sys
from System import *
from System.IO import *
from System.Net import *
from System.Web import *
from System.Text import *
from System.Threading import *
from System.Globalization import *
from System.Security.Cryptography import *
from System.Web.Script.Serialization import *
from System.Collections.Generic import List as syslist
from System.Collections.Generic import Dictionary
from Newtonsoft.Json.Linq import *
from Kingdee.BOS.Contracts import *
from Kingdee.BOS.Core.List import *
from Kingdee.BOS.Core.CommonFilter import *
from Kingdee.BOS.Contracts.Report import *
from Kingdee.BOS.Core.Report import ISysReportView
from Kingdee.BOS.Core.Report import ReportTitles
from Kingdee.BOS.App import ServiceHelper as ServiceHelperAPP
from Kingdee.BOS.Orm.Metadata.DataEntity import *
from Kingdee.BOS import *
from Kingdee.BOS.WebApi.Client import *
from Kingdee.BOS.Core.List.PlugIn import *
from Kingdee.BOS.Core.Log import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.DynamicForm import *
from Kingdee.BOS.Orm import OperateOption
from Kingdee.BOS.Orm import OrmUtils
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.DynamicForm import *
from Kingdee.BOS.DataEntity import *
from Kingdee.BOS.Orm.DataEntity import *
from Kingdee.BOS.Core.Bill import *
from Kingdee.BOS.Core.Bill.PlugIn import *
from Kingdee.BOS.ServiceHelper import *
from Kingdee.BOS.Core.Interaction import KDInteractionException
from Kingdee.BOS.Core.Metadata.EntityElement import *
from Kingdee.BOS.Core.Metadata import BusinessInfo
from Kingdee.BOS.Core.Metadata import SelectorItemInfo ##字段选择实体类
from Kingdee.BOS.Core.SqlBuilder import QueryBuilderParemeter ##查询参数实体类
from Kingdee.BOS.Core.DynamicForm.PlugIn import *
from Kingdee.BOS.Core.DynamicForm.PlugIn.Args import *
from Kingdee.BOS.Orm.Metadata.DataEntity import *
from Kingdee.BOS.Core.Metadata import *
from Kingdee.BOS.Core.Metadata.FieldElement import *
reload(sys)
sys.setdefaultencoding('utf-8')
def AfterConvert(e):
list2=[]
_ExtendedDataEntitys=e.Result.FindByEntityKey("FEntityDetail")
for k,_ExtendedDataEntity in enumerate(_ExtendedDataEntitys):
LinkentryRows = _ExtendedDataEntity.DataEntity["FEntityDetail_Link"]
for i,LinkentryRow in enumerate(LinkentryRows):
SrcBillID=Convert.ToInt64(LinkentryRow["SBillID"])
SId=Convert.ToInt64(LinkentryRow["SId"])
sql = "SELECT FDATE,t2.FMATERIALID,t3.FNUMBER FROM T_SAL_OUTSTOCK T1 LEFT JOIN T_SAL_OUTSTOCKENTRY T2 ON T1.FID = T2.FID \
LEFT JOIN T_BD_MATERIAL T3 ON T2.FMATERIALID = T3.FMATERIALID \
WHERE FENTRYID = {0}".format(int(SId))
dr = DBServiceHelper.ExecuteDynamicObject(this.Context, sql)
if len(dr)!=0:
list2.append((str(dr[0][0])).split(" ",1)[0])
_ExtendedDataEntity["F_PAEZ_Text"]=str(list2) #如果字段名不一样改为COMMENT
list2=[]
应收单代码:
clr.AddReference('System') clr.AddReference('Kingdee.BOS.Core') clr.AddReference('Kingdee.BOS') clr.AddReference("Kingdee.BOS.ServiceHelper") from Kingdee.BOS import * from System import * from Kingdee.BOS.ServiceHelper import * def BeforeSave(e): entity = this.View.BusinessInfo.GetEntity("FEntityDetail") rowObjs = this.View.Model.GetEntityDataObject(entity) docSCDDIdsl = this.View.Model.DataObject FBILL=docSCDDIdsl["BillNo"] FCUSTOMERID = docSCDDIdsl["CUSTOMERID_Id"] yuandanlx=rowObjs[0]["FSOURCETYPE"] xzbd,list2 ,list3,list4,list5,list6,list7,list8,list9,list10,list11,list12= [],[],[],[],[],[],[],[],[],[],[],[] ybd,list22 ,list23,list24,baochbdsj,list26,list27,ybd1,xzbd1=[], [],[],[],[],[],[],[],[] sql="SELECT FMATERIALID,FPRICEQTY,T2.F_PAEZ_Text FROM T_AR_RECEIVABLE T1 \ LEFT JOIN T_AR_RECEIVABLEENTRY T2 ON T1.FID = T2.FID \ WHERE FBILLNO = '{0}' ORDER BY FMATERIALID".format(FBILL) #如果字段名不一样改为T2.FCOMMENT drr = DBServiceHelper.ExecuteDynamicObject(this.Context, sql) if FCUSTOMERID!=273781 and yuandanlx=='SAL_OUTSTOCK' and len(drr)==0 : ##条件可以适当改变,但是最后一个条件不变 a=len(rowObjs) for i in range(0,a): wuliao=int(rowObjs[i]["MATERIALID_Id"]) xzbd.append(wuliao) beizu= rowObjs[i]["F_PAEZ_Text"] #如果字段名不一样改为COMMENT list2.append(eval(beizu)) #SId for i in set(xzbd): for j ,k in enumerate(xzbd): if i==k: list3=list3+list2[j] list4=list(set(list3)) list4.sort() list5.append(list4) list3=[] for i,j in enumerate(set(xzbd)): sql = "SELECT T2.FENTRYID ,t2.FMATERIALID FROM T_SAL_OUTSTOCK T1 LEFT JOIN T_SAL_OUTSTOCKENTRY T2 ON T1.FID = T2.FID \ LEFT JOIN T_SAL_OUTSTOCKENTRY_R T5 ON T2.FENTRYID = T5.FENTRYID \ WHERE FDOCUMENTSTATUS = 'C'AND FARNOTJOINQTY > 0 \ AND T2.FMATERIALID ='{0}' AND FCUSTOMERID = '{1}' ORDER BY FDATE".format(j,str(FCUSTOMERID)) dr = DBServiceHelper.ExecuteDynamicObject(this.Context, sql) if len(dr)!=0: for m in range(len(list5[i])): list6.append(int(dr[m][0])) if list6== list5[i]: list7.append(str(list5[i])+str(list6)) elif list5[i]!=list6: list8.append(str(list5[i])+str(list6)) sql="SELECT FNUMBER FROM T_BD_MATERIAL WHERE FMATERIALID ={0}".format(j) dr2= DBServiceHelper.ExecuteDynamicObject(this.Context, sql) if len(dr2)!=0: list9.append(dr2[0][0]) if len(list9) != 0 : e.Cancel = True #this.View.ShowMessage("物料代码"+str(list5)+"有更早的未推完销售出库单") this.View.ShowMessage("物料代码"+str(list9) +"#"+str(FBILL) +"有更早的未推完销售出库单") elif FCUSTOMERID!=273781 and yuandanlx=='SAL_OUTSTOCK' and len(drr)!=0: ##条件可以适当改变 ####第一次保存物料与日期 if len(drr)!=0: for i in range(len(drr)): ybd.append(drr[i][0])#保存的物料 #list22.append(drr[i][1]) list23.append(drr[i][2])#SId ybd1=list(set(ybd)) ybd1.sort() for i in range(len(ybd1)):#物料去重复 for j in range(len(ybd)): if ybd1[i]==ybd[j]: list24=list24+eval(list23[j])#SID baochbdsj.append(list(set(list24) )) list24=[] else: this.View.ShowMessage("单据数据有重复") a=len(rowObjs) for i in range(0,a): wuliao=int(rowObjs[i]["MATERIALID_Id"])#后加减物料 xzbd.append(wuliao) beizu= rowObjs[i]["F_PAEZ_Text"] #如果字段名不一样改为COMMENT list2.append(eval(beizu)) #SId xzbd1=list(set(xzbd)) xzbd1.sort() for i in xzbd1: #物料去重复 for j ,k in enumerate(xzbd): if i==k: list3=list3+list2[j]# list4.append(list(set(list3)))#后加 SId去重复合集 list5.append(len(list(set(list3))))#数量 list3=[] list100=[] list100.append(xzbd) list100.append(ybd) for i in range(len(ybd1),0,-1): if ybd1[i-1] not in xzbd1: #原表单 #新增表 baochbdsj.pop(i-1) #去除原表单不存在的SId ##再次查找要补充的数据库 for i in range(len(set(xzbd))): if xzbd1[i] not in ybd : #新增表单不在原表单 sql = "SELECT T2.FENTRYID,t2.FMATERIALID, FDATE FROM T_SAL_OUTSTOCK T1 LEFT JOIN T_SAL_OUTSTOCKENTRY T2 ON T1.FID = T2.FID \ LEFT JOIN T_SAL_OUTSTOCKENTRY_R T5 ON T2.FENTRYID = T5.FENTRYID \ WHERE FDOCUMENTSTATUS = 'C'AND FARNOTJOINQTY > 0 \ AND T2.FMATERIALID ='{0}' AND FCUSTOMERID = '{1}' ORDER BY FDATE ASC".format((xzbd1)[i],str(FCUSTOMERID)) dr = DBServiceHelper.ExecuteDynamicObject(this.Context, sql) if len(dr)!=0 : for m in range(list5[i]): list6.append((int(dr[m][0]))) #SId list6.sort() list7.append(list6) #SId集合 list6=[] continue for j in range(len(set(ybd))): list100.append(str(list5[i])+str(baochbdsj[j])) if xzbd1[i] == ybd1[j] and list5[i]>len(baochbdsj[j]): sql = "SELECT T2.FENTRYID ,t2.FMATERIALID ,FDATE FROM T_SAL_OUTSTOCK T1 LEFT JOIN T_SAL_OUTSTOCKENTRY T2 ON T1.FID = T2.FID \ LEFT JOIN T_SAL_OUTSTOCKENTRY_R T5 ON T2.FENTRYID = T5.FENTRYID \ WHERE FDOCUMENTSTATUS = 'C'AND FARNOTJOINQTY > 0 \ AND T2.FMATERIALID ='{0}' AND FCUSTOMERID = '{1}' ORDER BY FDATE ".format(xzbd1[i],str(FCUSTOMERID)) #ASC dr = DBServiceHelper.ExecuteDynamicObject(this.Context, sql) if len(dr)!=0 and list5[i]>len(baochbdsj[j]): for m in range(list5[i]-len(baochbdsj[j])): baochbdsj[j].append((int(dr[m][0]))) #SId elif xzbd1[i] == ybd1[j] and list5[i]<=len(baochbdsj[j]): for k in range(len(baochbdsj[j]-list5[i])): baochbdsj[j].pop() k=0 kk=0 for i in range(len(set(xzbd))): #新增表单 if xzbd1[i] not in ybd: list8.append(list7[k]) k=k+1 else: list8.append(baochbdsj[kk]) kk=kk+1 for i,m in enumerate( xzbd1): list4[i].sort() list8[i].sort() if (list4[i])!=(list8[i]): sql="SELECT FNUMBER FROM T_BD_MATERIAL WHERE FMATERIALID ={0}".format(m) dr = DBServiceHelper.ExecuteDynamicObject(this.Context, sql) if len(dr)!=0: list9.append(dr[0][0]) if len(list9)!=0: e.Cancel = True this.View.ShowMessage("物料编码"+str(list9)+"有更早的未推完销售出库单") #this.View.ShowMessage("物料编码"+str(list9)+"有问题"+"表单日期和正确日期分别为"+str(list4)+"#"+str(list8)+"#"+str(list100)+"有更早的"+str(set(xzbd))+"未推完销售出库单") else: e.Cancel = True this.View.ShowMessage(" 销售出库单符合先进先出") 补充:应收单明细要求增加文本框F_PAEZ_Text,有的默认系统字段备注为COMMENT,相应代码改成: _ExtendedDataEntity["COMMENT"]=str(list2) sql="SELECT FMATERIALID,FPRICEQTY,T2.FCOMMENT FROM T_AR_RECEIVABLE T1 \ LEFT JOIN T_AR_RECEIVABLEENTRY T2 ON T1.FID = T2.FID \ WHERE FBILLNO = '{0}' ORDER BY FMATERIALID".format(FBILL) beizu= rowObjs[i]["COMMENT"]