Python实例3:使用BeforeSave事件-2原创
47人赞赏了该文章
252次浏览
未经作者许可,禁止转载编辑于2024年04月10日 11:43:54
实例描述:费用核销单中根据费用科目及预提区间组合校验重置预提金额,解决三方系统传递生成费用核销单时,预提金额在同一预提期间重复,造成生成凭证时冲销预提金额重复合计,多冲销异常。
实例效果:
注册python:
python代码:
def BeforeSave(f):
# 获取当前模型中的行数
rowIndex = this.Model.GetEntryRowCount('FEntity')
#获取OA ID值
oaId = this.Model.GetValue('F_OA_ID')
# 获取单据类型编号,FBillTypeID属性有内码id、名称name、编号number
billType = this.Model.GetValue('FBillTypeID')['number']
# 如果OA ID包含特定字符串,行数大于1,且单据类型匹配,则进行预提金额的检查和处理
if oaId.Contains('YFHTHX') and rowIndex > 1 and billType == 'FYHX003_SYS':
# 初始化用于存储不重复费用科目+预提期间组合及其对应预提金额的字典
amounts_dict = []
for i in range(0, rowIndex):
if this.Model.GetValue('FCOSTID',i):
#获取费用科目编号
cost_id = this.Model.GetValue('FCOSTID',i)['number']
#获取预提期间
period = this.Model.GetValue('F_Period',i)
# 创建费用科目+预提期间的组合键
key = str(cost_id) + "_" +str(period)
# 检查组合键是否已存在于字典中,如果是则将该行的预提金额设置为0
if key in amounts_dict:
this.Model.SetValue('F_WDING_MONEY', 0.00, i)
else:
# 将新的组合键及其预提金额添加到字典中
amounts_dict.append(key)
# 显示相关信息用于调试或确认
#this.View.ShowMessage("OAID是:"+str(oaId)+"_明细行数:"+str(rowIndex)+"_key:"+str(amounts_dict)+"_Bill:"+str(billType))
Python.CheckPeriodExpenseValue …(1.01KB)
推荐阅读