金蝶云·星空python插件示例代码

持续更新中……

企鹅qun:688729914

欢迎加入,共同进步

值更新后赋值

#引入clr运行库
import clr
#添加对cloud插件开发的常用组件的引用
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
from Kingdee.BOS.Core import *
def DataChanged(e):
	groupNumber = str(this.Model.GetValue("FGroup")['Number']) if (this.Model.GetValue("FGroup") <>None) else "0";
	if "G2" in groupNumber:
		this.Model.SetValue("F_PFIH_Group","101435");
	else :
		this.Model.SetValue("F_PFIH_Group","");

记录上机操作日志

参数说明:

参数logObject为日志详情,关键属性如下:

属性

描述

string pkValue

单据内码

OperatingEnvironment Environment

操作场景,枚举值,包括登录、退出、操作等;

string SubSystemId

子系统

【子系统】

SELECT b.FNAME AS 子系统名称,a.FID AS 子系统内码,a.* 

FROM T_META_SUBSYSTEM a 

LEFT JOIN T_META_SUBSYSTEM_L b ON a.FID=b.FID AND b.FLOCALEID=2052

string Description

日志详情

string ObjectTypeId

业务对象内码,如单据的FormId

【业务对象】

SELECT b.FNAME AS 业务对象名称,a.FID AS [业务对象标识(FormId)],* 

FROM T_META_OBJECTTYPE a 

LEFT JOIN T_META_OBJECTTYPE_L b ON a.FID=b.FID AND b.FLOCALEID=2052 

WHERE a.FID='SAL_OUTSTOCK'

string OperateName

操作名称,如”保存”、”删除”、”提交”、”审核”、”反审核”

#引入clr运行库
import clr
#添加对cloud插件开发的常用组件的引用
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.ServiceHelper')
#导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入)
from Kingdee.BOS import *
from System import *
from Kingdee.BOS.Core.Log import *
from Kingdee.BOS.ServiceHelper import *

def BarItemClick(e) :
	if e.BarItemKey=="JQH_tbButton" :
		message = this.Model.GetValue("FName")
		logObj = LogObject()
		logObj.pkValue = "0"
		logObj.SubSystemId = "BOS";
		logObj.Description = "测试描述"+str(message)
		logObj.Environment = OperatingEnvironment.BizOperate;
		logObj.OperateName = "测试操作名称"
		LogServiceHelper.WriteLog(this.Context, logObj)

特殊说明: 该插件保存时会报错如下的错,可以忽略不管

Could not add reference to assembly Kingdee.BOS.ServiceHelper
   在 IronPython.Runtime.ClrModule.AddReference(CodeContext context, String name)
   在 IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object[] references)
   在 Microsoft.Scripting.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   在 Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   在 Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)

发送get请求

#引入clr运行库
import clr
#添加对cloud插件开发的常用组件的引用
clr.AddReference("System")
clr.AddReference("System.Web.Extensions")
clr.AddReference("Kingdee.BOS")
clr.AddReference("Kingdee.BOS.Core")
clr.AddReference("Newtonsoft.Json")
#导入cloud基础库中的常用实体对象(分命名空间导入,不会递归导入)
import sys
from System import *
from System.Collections.Generic import *
from System.Threading import *
from System.IO import *
from System.Net import *
from System.Text import *
from System.Security.Cryptography import *
from System.Web.Script.Serialization import *
from System.Collections.Generic import Dictionary
from Newtonsoft.Json.Linq import *


def BarItemClick(e) :
	if e.BarItemKey=="JQH_tbButton" :
		test = get("https://www.test.com")
		this.View.ShowMessage(test)
	
def get(url):
	req = HttpWebRequest.Create(url);
	req.Method = "GET";
	rsp = req.GetResponse();
	stream = rsp.GetResponseStream();
	reader = StreamReader(stream, Encoding.GetEncoding("utf-8"));
	result = reader.ReadToEnd();
	return result

执行查询和更新sql

import clr
clr.AddReference('Kingdee.BOS.App')
from Kingdee.BOS.App.Data import *

def BarItemClick(e):
	if e.BarItemKey=="JQH_getSql":
		# 查询当前登录用户信息
		sql = "SELECT FNAME FROM T_SEC_USER WHERE FUSERID="+this.Context.UserId.ToString();
		userName = DBUtils.ExecuteScalar(this.Context,sql,None);
		this.View.ShowMessage(userName);
	elif e.BarItemKey=="JQH_exeSql":
		# 修改当前登录用户的描述
		sql = "UPDATE T_SEC_USER SET FDESCRIPTION=N'test' WHERE FUSERID="+this.Context.UserId.ToString();
		count = DBUtils.Execute(this.Context,sql);
		this.View.ShowMessage("更新成功,SQL:"+sql+",受影响行数:"+count.ToString());

列表过滤条件,新增菜单发布时的自定义参数

import clr
clr.AddReference("System")
clr.AddReference("System.Core")
clr.AddReference("Kingdee.BOS")
clr.AddReference("Kingdee.BOS.Core")
clr.AddReference("Kingdee.BOS.DataEntity")
clr.AddReference("Kingdee.BOS.Contracts")
from Kingdee.BOS import *
from Kingdee.BOS.JSON import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.Const import *
from Kingdee.BOS.Core.Bill import *
from Kingdee.BOS.Core.List import *
from System import *
from System.Collections.Generic import *
from System.Linq import *
def PrepareFilterParameter(e):
	listType=this.View.OpenParameter.GetCustomParameter("BillTypeID");
	if listType:
		filterString="";
		filterString=str.Format(" FBILLTYPEID='"+listType+"'");
		e.FilterString+="AND";
		e.FilterString+=filterString;
		#this.View.showMessage(e.FilterString)

单据体值更新时间

#引入clr运行库
import clr
#添加对cloud插件开发的常用组件的引用
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.DataEntity')
from Kingdee.BOS.Core import *
import Kingdee.BOS.Orm.DataEntity as de
from System import *

def DataChanged(e):
	#获取单据体选中行
	entry_row = this.View.Model.GetEntryCurrentRowIndex("FSaleOrderEntry");
	FQty = Convert.ToInt32(this.View.Model.GetValue("FQty", entry_row))
	#获取单据体    
	entity=this.View.BusinessInfo.GetEntity("FSaleOrderEntry")
	
	#获取子单据体,此单据体是一个集合,根据每个集合的属性去找关联单据体    
	subentity=this.View.BusinessInfo.GetEntity("FOrderEntryPlan")
	#获取单据体数据航,DynamicObjectCollection    
	entityRows=entity.DynamicProperty.GetValue(this.Model.DataObject)
	
	#获取更新的字段
	key = e.Field.Key.ToUpperInvariant();
	#this.View.ShowMessage(key)
	
	if key == 'F_JQH_STARTDATE' or key == 'F_JQH_ENDDATE':
		#this.View.ShowMessage(key)
			if entityRows:
				#this.View.ShowMessage('aa')
				#循环单据体
				for entityRow in entityRows :
					if entityRow :
						StartDate = Convert.ToDateTime(this.View.Model.GetValue("F_JQH_StartDate", entry_row))
						EndDate = Convert.ToDateTime(this.View.Model.GetValue("F_JQH_EndDate", entry_row))
						month = (EndDate.Year - StartDate.Year) * 12 + (EndDate.Month - StartDate.Month)
						month = Convert.ToInt32(month)
						#this.View.ShowMessage(Convert.ToString(month))
						#根据行获取子单据体
						#if entry_row > 1 and len(StartDate) > 0 and len(EndDate) > 0 and month > 0:
						if month > 0:
							count = 0;
							while(count < month):
								subEntityRows = subentity.DynamicProperty.GetValue(entityRow)
								newobject=de.DynamicObject(subEntityRows.DynamicCollectionItemPropertyType)
								#newobject["PlanQty"] = 122
								this.View.Model.SetValue('F_JQH_Integer',newobject,322)
								#this.View.Model.SetValue(this.View.Model.GetValue("FQty", entry_row),newobject,cfentityRow["FPlanQty"])
								subEntityRows.Add(newobject)
								
								count = count + 1
	
	


	#this.View.ShowMessage(Convert.ToString(entry_row))

单据保存后自动提交审核

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.Contracts')
clr.AddReference('Kingdee.BOS.ServiceHelper')
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.Bill import *
from Kingdee.BOS.Contracts import *
from Kingdee.BOS.App 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.Text import *
from System.Collections import *
from Kingdee.BOS.App.Data import *
from System.Collections.Generic import List
from Kingdee.BOS.ServiceHelper import *
def EndOperationTransaction(e):
	idList =List[object]()
	for billObj in e.DataEntitys:
		BillId = str(billObj["Id"])
		sql = "SELECT FbillTypeID FROM t_AR_receivable WHERE FID="+BillId;
		BillTypeID = DBUtils.ExecuteScalar(this.Context,sql,None);
		idList.Add(BillId)
		sql = "UPDATE T_SEC_USER SET FDESCRIPTION=N'"+BillTypeID+"' WHERE FUSERID=200";
		count = DBUtils.Execute(this.Context,sql);
	if(BillTypeID == "61a1d449dc25fe"):
		pkArray = idList.ToArray()
		formID=this.BusinessInfo.GetForm().Id
		meta = MetaDataServiceHelper.Load(this.Context, formID)
		submitOption = None
		subResult =BusinessDataServiceHelper.Submit(this.Context,meta.BusinessInfo,pkArray,"Submit",submitOption)
		if (subResult.IsSuccess == True):		
			auditOption = None
			auditResult = BusinessDataServiceHelper.Audit(this.Context,meta.BusinessInfo,pkArray,auditOption)
注意:上面的代码保存时会出现如下提示,可以忽略不管。
Could not add reference to assembly Kingdee.BOS.App

点击单据体,打开单据

import clr
clr.AddReference("Kingdee.BOS.Core")
from Kingdee.BOS.Core.Bill import BillShowParameter
from Kingdee.BOS.Core.Metadata import OperationStatus
from Kingdee.BOS.Core.DynamicForm import ShowType
#添加对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')
clr.AddReference('Newtonsoft.Json')
clr.AddReference('System.Web.Extensions')
#导入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 System.Net import *
from System.Text import *
from System.IO import *
#from System.String import *
from Kingdee.BOS.App.Data import *
from System.Collections.Generic import List
from Kingdee.BOS.ServiceHelper import *

def EntryButtonCellClick(e):
	if (e.FieldKey.ToUpperInvariant() == "F_ORA_BANKSTATEMENTNO"):
		#objId=1001
		billNo=this.Model.DataObject["ora_Cust_EntryBankStatement"][e.Row]["F_ora_BankStatementNo"]
	 	objId=getId(billNo)
	 	#this.View.ShowMessage(objId.ToString());
	 	showParameters=BillShowParameter()
	 	showParameters.FormId="ora_bankStatement"
	 	showParameters.PKey=objId.ToString()
	 	showParameters.Status=OperationStatus.VIEW
	 	showParameters.OpenStyle.ShowType=ShowType.Modal
	 	this.View.ShowForm(showParameters)

def getId(billNo):
	#从数据库获取token
	sql=("/*dialect*/SELECT FID FROM ora_t_Cust100013 WHERE FBILLNO="+"'"+billNo+"'");
	ds = DBUtils.ExecuteDataSet(this.Context,sql);
	tab = ds.Tables[0];
	for dr in tab.Rows:
		fid=dr["FID"];
	return fid;

你可能感兴趣的:(金蝶,python)