Python脚本表达式原创
金蝶云社区-eris
eris
13人赞赏了该文章 3458次浏览 未经作者许可,禁止转载编辑于2024年04月02日 08:59:01

 1. 日期字段改变给另外一个日期字段赋值,比如日期为当月1-5号的取5号,5-15号的取15号,15-25号取25号,25号以后取下月5号,取5号,表达式为:

FDate1= FDate.AddDays((5 if FDate.Day < 6 else ( 15 if FDate.Day< 16 else (25 if 

FDate.Day< 26 else ( (FDate.AddDays(1 - FDate.Day).AddMonths(1).AddDays(-

1).Day)+5))))-FDate.Day)

2. 判断文本中是否存在每个字符?

首先需要把字段值转换为字符串类型,然后使用python字符串内置函数find进行判断,具体表达式为:

str(字段key).find("/")>=0

如果包含中文会报'ascii' codec can't decode byte 0 in position 0: ordinal not in range错误,可以使用python插件处理:

import clr
import sys
clr.AddReference("System")
clr.AddReference("Kingdee.BOS")
clr.AddReference("Kingdee.BOS.Core")
from System import *

def BarItemClick(e):
	if e.BarItemKey == "tbSave" or e.BarItemKey == "tbSplitSave":
		reload(sys)
		sys.setdefaultencoding("utf-8")
		cValue1 = this.Model.DataObject["Name"].ToString()
		isContain = cValue1.find("\\")>0
		if isContain:
			e.Cancel = True
			this.View.ShowWarnningMessage("物料名称中不能包含反斜杠")

3、判断所有分录是否有某个字段是否等于特定值?

len(filter(lambda x: ( x.FMaterialId.FSpecification == '某某规格型号' ), "物料所在的单据体key"))>0

4、去除为空的赋值?

FTaxprice =( 0 if FMATERIALID.F_PAEZ_Text == null else FMATERIALID.F_PAEZ_Text)

FTaxprice = (0 if FMaterialId.F_PAEZ_Text.replace(' ','')=="" else FMaterialId.F_PAEZ_Text)

5、截取字符串

len(filter(lambda x:(str(x.F_PAEZ_Material.FNumber)[0:3]='000'),FEntity))>0

6、单据体字段给单据头字段赋值

 取单据体第一个不为空的字段数据给单据头字段赋值

单据头字段可以=filter(lambda x:x.单据体字段key<>"", 单据体key)[0].单据体字段key

7、单据转换表单服务策略运行逻辑

1)根据被赋值字段所在的实体确定循环数据包,如果所在的实体是单据体,则循环单据体

8、反写规则表达式需要使用基础资料,如果加了属性,则无法解析出此基础资料,需要使用基础资料等于基础资料处理?

1)F_PAEZ_Material.Id <> 422657 And F_PAEZ_Qty  > 6  And  F_PAEZ_Material ==  F_PAEZ_Material

9、转换规则字段映射自定义表达式无效?

这些情况都无效,1 if   FSalerId <> 0 else 0,1 if   str(FSalerId) <>'0' else 0,1 if   FSalerId <>null else 0

原因:FSalerId 是基础资料字段,虽然取到的数据包中的FSalerId 对应的数据是长整形,但还是按基础资料字段来处理,FSalerId被包含在表达式中得到使用一个基础资料处理实例类,所以不会为null也不会为0等。

解决方案: 对销售员加编码引用,然后使用 1 if  FSalerId.FNumber <>null else 0 或者直接把销售员的信息带到下游,在服务策略中对复选框处理。

10. 辅助属性维度的值合并

F_PAEZ_Remark1 = str('' if F_PAEZ_Flex.FF100001 == null else F_PAEZ_Flex.FF100001.FNumber)+str('' if F_PAEZ_Flex.FF100002== null else F_PAEZ_Flex.FF100002.FNumber)

11、单据是否下推而来?

IsDraw    IsDraw()    IsDraw()=1   这样的写法都可以,  但还需要加个关联主实体的字段或者勾选一个关联主实体的字段

12、字段映射,自定义公式: F_BOS_Date日期减3天,大于当前日期则取,否则取当前日期;F_BOS_Date为空时取当前日期;@currentlongdate当前长日期、@currentshortdate当前短日期

(F_BOS_Date.AddDays(-3)  if F_BOS_Date.AddDays(-3) >  @currentlongdate else @currentlongdate) if F_BOS_Date<> null else  @currentlongdate

13、表达式中可调用的函数

@currentlongdate、@currentshortdate、@maxdate、@mindate、@userid、@currentorgid

14、单据转换合并下推,用逗号连接,去重脚本?

1)单据合并
def AfterConvert(e):
objExs = e.Result.FindByEntityKey("FBillHead")
for objEx in objExs:
oldStr = str(objEx.DataEntity["F_PAEZ_Text"])
splitStr = oldStr.Split(",")
lst = []
for ele in splitStr:
if not ele in lst:
lst.append(ele)
else:
continue
objEx.DataEntity["F_PAEZ_Text"] = ','.join(lst)
2)适应所以合并
也可以通过字段映射自定义公式赋值,假设来源字段key为fdemo
",".join(set(",".join(Sources.fdemo).split(","))) 其中Sources是单据转换的专业务关键字,代表字段来源数据包集合

15、转换规则记录主业务组织日志

import clr
clr.AddReference("System")
clr.AddReference("Kingdee.BOS")
clr.AddReference("Kingdee.BOS.Core")
from Kingdee.BOS.Log import *
from System import *
def OnInitVariable(e):
    dataStr = str(this.Option.GetVariableValue[Int64]("MainOrgID"))
    Logger.Error("OnInitVariable_MainOrgId传入的", dataStr,None)
def AfterConvert(e):
    dataStr2 = str(e.Result.FindByEntityKey("FBillHead")[0]["InspectOrgId_Id"])
    Logger.Error("AfterConvert_MainOrgId转换后的", dataStr2,None)


赞 13