2

I noticed importing or adding contributions in Serbian dinars (RSD) doesn't work. I tried using API Explorer to create a contribution that way but I get the same error I get when I try to import contributions.

{"sequential":1,"financial_type_id":"Donation","total_amount":100,"contact_id":2,"currency":"RSD"}

"error_message": "Currency not a valid code: "

I then tried to find out are there other currencies that don't work and I tried importing a file with donations in all currencies in the civicrm_currency table. It turns out that there three more currencies which don't work.

The currencies affected are:

  • Serbian Dinar (RSD)

  • Venezuela Bolivar (VEF)

  • Azerbaijanian Manat (AZN)

  • Mozambique Metical (MZN)

When I try to add a contribution manually through the form using these currencies, CiviCRM disregards my selection and uses the default currency.

There is a workaround. You can set any of these affected currencies as default, and then leave the field for currencies blank for that currency when importing (or leave default when adding a contribution manually). CiviCRM will then assume you are using a default currency and import or add it correctly. Still there's a problem if you want to use other currency for default (USD for example) and add contributions in affected currencies.

What could be causing this?

I'm using the current version of CiviCRM (4.7.29)

  • 1
    Teamwork makes the dream work! 12 hours after Marko asked this question, I tracked down the cause and Hassan Farooq wrote the fix. Thanks to you both for improving CiviCRM! The fix will be in 4.7.31+. – Jon G - Megaphone Tech Jan 16 '18 at 23:48
  • Great work, people! – Marko Jan 17 '18 at 8:53
2

This was curious, so I tracked it down.

Apparently the list of valid currencies predates the civicrm_currency table. So right now the valid currencies are hardcoded - you can see that in <civiroot>/CRM/Core/Pseudoconstant.php around line 1077 - the currencyCode() function.

As a quick workaround, you could add your currency to the list. However, the correct solution would be to modify this function to return the result of SELECT name FROM civicrm_currency.

1

I tried to replicate it in Civicrm 4.7.23 and Drupal 7.56 and i also got same error message through API call:

$result = civicrm_api3('Contribution', 'create', array( 'financial_type_id' => "Donation", 'total_amount' => 100, 'contact_id' => 202, 'currency' => "RSD", ));

Looks like its bug (maybe) in civicrm, i have created Jira issue here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.