
@[TOC](目录)
### pytho案例(以采购退料单为例)
```python
import clr
clr.AddReference('System')
clr.AddReference('mscorlib')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.K3.SCM.ServiceHelper')
from System import *
from Kingdee.BOS.Core.Metadata import CreateFrom
from Kingdee.K3.SCM.ServiceHelper import *
def AfterCreateNewData(e):
if this.View.OpenParameter.CreateFrom == CreateFrom.Copy:
SetExchangeRate()
def SetExchangeRate():
locCurr = this.View.Model.GetValue("FLocalCurrId")
exchangeType = this.View.Model.GetValue("FExchangeTypeId")
setCurr = this.View.Model.GetValue("FSettleCurrId")
if locCurr == None or exchangeType == None or setCurr == None:
return
locCurrId = Convert.ToInt64(locCurr["Id"])
exchangeTypeId = Convert.ToInt64(exchangeType["Id"])
setCurrId = Convert.ToInt64(setCurr["Id"])
billdate = Convert.ToDateTime(this.View.Model.GetValue("FDate"))
if locCurrId == setCurrId or billdate == DateTime.MinValue:
this.View.Model.SetValue("FExchangeRate", 1)
else:
rateNDec = CommonServiceHelper.GetExchangeRateAndDecimal(this.Context, setCurrId, locCurrId, exchangeTypeId, billdate, billdate)
this.View.Model.SetValue("FExchangeRate", rateNDec.Key)
this.View.GetFieldEditor("FExchangeRate", 0).Scale = Convert.ToInt16(rateNDec.Value)
this.View.InvokeFieldUpdateService("FExchangeRate", 0)
def AfterCopyData(e):
exchangeRate = Convert.ToDecimal(this.View.Model.GetValue("FExchangeRate"))
currencyObj = this.View.Model.GetValue("FSettleCurrId")
iAmountDigits = 2
if currencyObj != None:
iAmountDigits = Convert.ToInt16(currencyObj["AmountDigits"])
dycFinanceEntryData = e.DataObject["PUR_MRBFIN"]
if dycFinanceEntryData != None and dycFinanceEntryData.Count > 0:
financeEntryData = dycFinanceEntryData[0]
financeEntryData["BILLTAXAMOUNT_LC"] = Math.Round(Convert.ToDecimal(financeEntryData["BILLTAXAMOUNT"]) * exchangeRate, int(iAmountDigits))
financeEntryData["BillAmount_LC"] = Math.Round(Convert.ToDecimal(financeEntryData["BillAmount"]) * exchangeRate, int(iAmountDigits))
financeEntryData["FBILLALLAMOUNT_LC"] = Convert.ToDecimal(financeEntryData["BILLTAXAMOUNT_LC"]) + Convert.ToDecimal(financeEntryData["BillAmount_LC"])
for entry in e.DataObject["PUR_MRBENTRY"]:
entry["TAXAMOUNT_LC"] = Math.Round(Convert.ToDecimal(entry["TaxAmount"]) * exchangeRate, int(iAmountDigits))
entry["Amount_LC"] = Math.Round(Convert.ToDecimal(entry["Amount"]) * exchangeRate, int(iAmountDigits))
entry["ALLAMOUNT_LC"] = Convert.ToDecimal(entry["TAXAMOUNT_LC"]) + Convert.ToDecimal(entry["Amount_LC"])
```
**其他更多文章入口:**[https://wenku.my7c.com/link/s/lbRPP](https://wenku.my7c.com/link/s/lbRPP)