表单插件获取汇率类型和汇率
@[TOC](目录)
### 背景
需要在其他单据上增加本位币字段,获取汇率后计算本位币金额。以采购申请单为例
### 步骤
1. 在采购申请单表头添加字段,采购申请单已经有币别和汇率类型,还需要本位币和汇率字段
![1、在采购申请单上新增本位币和汇率字段.webp](/download/0100bebb2e6b035b48d3bc4d68b6beb2338f.webp)
2. 新增本位币
![2、币别字段.webp](/download/0100d1c0dff18cf24f8f818c83d15213f68a.webp)
3. 新增汇率
![3、汇率.webp](/download/0100a4471be0d9f94444b7c7244d3e63ae45.webp)
4. 注册表单插件根据申请组织获取汇率类型,并根据币别和本位币获取汇率
![4、注册表单插件.webp](/download/010057b5487eea0a49d4b714841db987b2a0.webp)
5. 按自己的字段标识修改脚本
![5、修改本位币和汇率字段标识.webp](/download/0100a9d7f769555343bfbba4b113aa0533f4.webp)
### python脚本
```python
import clr
clr.AddReference('mscorlib')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.K3.SCM.App')
clr.AddReference('Kingdee.BOS.DataEntity')
clr.AddReference('Kingdee.K3.BD.Contracts')
clr.AddReference('Kingdee.K3.SCM.Contracts')
from System import *
from Kingdee.BOS.Core.Metadata import *
from Kingdee.K3.SCM.App import *
from Kingdee.BOS.Orm.DataEntity import *
from Kingdee.K3.BD.Contracts import *
from Kingdee.K3.BD.Contracts.FIN import *
from Kingdee.K3.SCM.Contracts import *
def AfterCreateNewData(e):
#获取申请组织
purOrg = this.View.Model.GetValue("FApplicationOrgId")
#获取币别字段
currency = this.View.Model.GetValue("FCurrencyId")
purOrgId = 0
currencyId = 0
if purOrg != None:
purOrgId = purOrg["Id"]
if currency != None:
currencyId = currency["Id"]
#获取创建日期
myDate = this.View.Model.GetValue("FCreateDate")
SetLocalCurrAndExchangeTypeAndExchangeRate(purOrgId,currencyId,myDate)
def DataChanged(e):
if e.Field.Key == "FApplicationOrgId" or e.Field.Key == "FCurrencyId"or e.Field.Key == "FCreateDate":
purOrg = this.View.Model.GetValue("FApplicationOrgId")
currency = this.View.Model.GetValue("FCurrencyId")
purOrgId = 0
currencyId = 0
if purOrg != None:
purOrgId = purOrg["Id"]
if currency != None:
currencyId = currency["Id"]
myDate = this.View.Model.GetValue("FCreateDate")
SetLocalCurrAndExchangeTypeAndExchangeRate(purOrgId,currencyId,myDate)
def SetLocalCurrAndExchangeTypeAndExchangeRate(purOrgId,currencyId,myDate):
#本位币
commonService =ServiceHelper.GetService[ICommonService]()
localCurrId = commonService.GetDefaultCurrencyByBizOrgID(this.Context, purOrgId)
this.View.Model.SetValue("F_CH_LocalCurrId",localCurrId,0)
#汇率类型
exchangeTypeId = commonService.GetDefaultExchangeTypeByBizOrgID(this.Context, purOrgId)
this.View.Model.SetValue("FexchangeTypeId",exchangeTypeId,0)
#汇率
finCommonService = ServiceFactory.GetService[IFINServiceForCommon](this.Context)
exchangeRate = finCommonService.GetExchangeBusRateAndDecimal(this.Context,localCurrId,currencyId,exchangeTypeId,myDate,myDate)
exchangeRateValue = Math.Round(exchangeRate.Key, exchangeRate.Value)
this.View.Model.SetValue("F_CH_ExchangeRate",exchangeRateValue,0)
```
### 演示
1. 直接创建申请单时获取默认汇率
![6、测试1.webp](/download/010022f0e7d07ad949e7b86a62baf66b2cd7.webp)
2. 修改币别后联动修改汇率
![7、测试2.webp](/download/0100cf3a2e036c804331995b022b4a0fa9da.webp)
**其他更多文章入口:**[https://vip.kingdee.com/link/s/lbRPP](https://vip.kingdee.com/link/s/lbRPP)
表单插件获取汇率类型和汇率
@[TOC](目录)### 背景需要在其他单据上增加本位币字段,获取汇率后计算本位币金额。以采购申请单为例### 步骤1. 在采购申请单表头添加字...
点击下载文档
本文2024-09-23 02:34:11发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-153292.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章