{"action":"created","issue":{"url":"https://api.github.com/repos/SalesforceFoundation/Cumulus/issues/3682","repository_url":"https://api.github.com/repos/SalesforceFoundation/Cumulus","labels_url":"https://api.github.com/repos/SalesforceFoundation/Cumulus/issues/3682/labels{/name}","comments_url":"https://api.github.com/repos/SalesforceFoundation/Cumulus/issues/3682/comments","events_url":"https://api.github.com/repos/SalesforceFoundation/Cumulus/issues/3682/events","html_url":"https://github.com/SalesforceFoundation/Cumulus/issues/3682","id":367347325,"node_id":"MDU6SXNzdWUzNjczNDczMjU=","number":3682,"title":"Opportunities in currency other than org default not auto-closing","user":{"login":"lmeerkatz","id":2000501,"node_id":"MDQ6VXNlcjIwMDA1MDE=","avatar_url":"https://avatars1.githubusercontent.com/u/2000501?v=4","gravatar_id":"","url":"https://api.github.com/users/lmeerkatz","html_url":"https://github.com/lmeerkatz","followers_url":"https://api.github.com/users/lmeerkatz/followers","following_url":"https://api.github.com/users/lmeerkatz/following{/other_user}","gists_url":"https://api.github.com/users/lmeerkatz/gists{/gist_id}","starred_url":"https://api.github.com/users/lmeerkatz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmeerkatz/subscriptions","organizations_url":"https://api.github.com/users/lmeerkatz/orgs","repos_url":"https://api.github.com/users/lmeerkatz/repos","events_url":"https://api.github.com/users/lmeerkatz/events{/privacy}","received_events_url":"https://api.github.com/users/lmeerkatz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-05T19:56:08Z","updated_at":"2018-10-05T20:01:57Z","closed_at":null,"author_association":"NONE","body":"In organizations with multicurrency enabled (not advanced currency management), opportunities are not being automatically closed when currency conversion is causing total payments to be slightly different from the opportunity amount due to rounding. \r\n\r\nWorking: I have an opportunity for USD100 in a stage of Prospecting. I mark the corresponding payment as paid and give it a date. The stage on the opportunity automatically changes to Closed Won. \r\n\r\nNot working: I have an opportunity for CAD100 in a stage of Prospecting. I mark the corresponding payment as paid and give it a date. The stage on the opportunity doesn't change.\r\n\r\n**Setup**\r\n\r\nMulticurrency is enabled. CAD is set up with a rate of 1.290000.\r\n\r\n<img width=\"805\" alt=\"screen shot 2018-10-04 at 5 24 26 pm\" src=\"https://user-images.githubusercontent.com/2000501/46556921-f1ae8580-c89c-11e8-99ad-a62b05fe503d.png\">\r\n\r\n**Tests that demonstrate the problem** https://gist.github.com/lmeerkatz/273db30a77ee46afa8abf55fc1ddbf18 (These need to be cleaned up to be production ready)\r\n\r\n**Source of bug**\r\nhttps://github.com/SalesforceFoundation/Cumulus/blob/master/src/classes/PMT_PaymentCreator.cls#L401\r\n\r\n**A possible solution**\r\n\r\nRound the currency amounts to the number of decimals specified before comparing them. \r\n\r\n```\r\nprivate static Boolean isEqualWhenRounded(Decimal amount1, Decimal amount2, Integer decimalPlaces) {\r\n    Decimal amount1Rounded = amount1.setScale(decimalPlaces);\r\n    Decimal amount2Rounded = amount2.setScale(decimalPlaces);\r\n    return (amount1Rounded == amount2Rounded);\r\n}\r\n\r\n```\r\n\r\n```\r\nString oppCurrency = (String)newOpp.get(CurrencyIsoCode);\r\nInteger decimalPlaces = UTIL_CurrencyCache.getCurrDecimalPlaces(oppCurrency);\r\n\r\nBoolean amountEqualPaymentReceived = isEqualWhenRounded(newOpp.Amount,  totalPaymentAmount, decimalPlaces);\r\n```"},"comment":{"url":"https://api.github.com/repos/SalesforceFoundation/Cumulus/issues/comments/427482795","html_url":"https://github.com/SalesforceFoundation/Cumulus/issues/3682#issuecomment-427482795","issue_url":"https://api.github.com/repos/SalesforceFoundation/Cumulus/issues/3682","id":427482795,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNzQ4Mjc5NQ==","user":{"login":"lmeerkatz","id":2000501,"node_id":"MDQ6VXNlcjIwMDA1MDE=","avatar_url":"https://avatars1.githubusercontent.com/u/2000501?v=4","gravatar_id":"","url":"https://api.github.com/users/lmeerkatz","html_url":"https://github.com/lmeerkatz","followers_url":"https://api.github.com/users/lmeerkatz/followers","following_url":"https://api.github.com/users/lmeerkatz/following{/other_user}","gists_url":"https://api.github.com/users/lmeerkatz/gists{/gist_id}","starred_url":"https://api.github.com/users/lmeerkatz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmeerkatz/subscriptions","organizations_url":"https://api.github.com/users/lmeerkatz/orgs","repos_url":"https://api.github.com/users/lmeerkatz/repos","events_url":"https://api.github.com/users/lmeerkatz/events{/privacy}","received_events_url":"https://api.github.com/users/lmeerkatz/received_events","type":"User","site_admin":false},"created_at":"2018-10-05T20:01:57Z","updated_at":"2018-10-05T20:01:57Z","author_association":"NONE","body":"**lurch: add"}}
{"actor":{"display_login":"lmeerkatz"}}