-
Notifications
You must be signed in to change notification settings - Fork 0
/
copydcr2ct.py
58 lines (36 loc) · 1.87 KB
/
copydcr2ct.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
# utility for copying latest DatedConversionRate.ConversionRate to CurrencyType.ConversionRate
#
# https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_datedconversionrate.htm?search_text=dated
# https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_currencytype.htm?search_text=dated
import simple_salesforce
import optparse
import getpass
parser = optparse.OptionParser("usage: %prog [options] username csvfile")
parser.add_option('-s', action='store_true', default=False, dest='sandbox')
(options, args) = parser.parse_args()
username = args[0]
# Login to salesforce
password = getpass.getpass(prompt='password + token, no spaces')
security_token = ''
session_id, instance = simple_salesforce.SalesforceLogin(
username=username,
password=password,
security_token=security_token,
sandbox=options.sandbox)
sf = simple_salesforce.Salesforce(instance=instance, session_id=session_id)
# Get a list of the configured currencies
currencies = {} # isocode: id
currencyResult = sf.query("select Id, IsoCode, ConversionRate, DecimalPlaces, IsActive, IsCorporate from CurrencyType")
for r in currencyResult['records']:
currencies[r['IsoCode']] = r['Id']
# For each configured currency, update currencytype from datedconversionrate
for isocode in currencies:
dcrResult = sf.query("select ConversionRate " +
"from DatedConversionRate " +
"where IsoCode = '" + isocode + "' " +
"order by startdate desc " +
"limit 1")
for r in dcrResult['records']:
updateResult = sf.CurrencyType.update(currencies[isocode], {'ConversionRate': r['ConversionRate']})
assert(updateResult==204)