Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9820 -Update EmailTemplate.php #10277

Open
wants to merge 1 commit into
base: hotfix
Choose a base branch
from

Conversation

pstevens71
Copy link
Contributor

@pstevens71 pstevens71 commented Dec 7, 2023

Allows currency fields to be parsed in email templates as currency on the final email.

The current $value just outputs raw value. Needs to be formatted as currency. There is already a function in the file to do that, just need to get the field type to use the function.

Description

First lirst line just gets the field "type" from the array. The second field just runs the value through the already defined function _convertToType() which formats for currency if it is a currency field.

This is issue #9820

Motivation and Context

It solves the problem of email templates with currency being formatted properly.

How To Test This

I tested this with a currency field and also a text field and both work after the change and produce the desired result in the email template final formatting.

To test you can create an email template with a currency field and see it is not formatted as currency, apply the patch and then re-output the email and you'll see its formatted as currency.

Types of changes

  • [ x] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Final checklist

  • [ x] My code follows the code style of this project found here.
  • My change requires a change to the documentation.
  • [ x] I have read the How to Contribute guidelines.

@chris001
Copy link
Contributor

chris001 commented Dec 7, 2023

It should it be titled Fix #9820 Email Template doesn't parse currency with email compose.
The pattern is Fix #(issue number) (exact same title of that issue).

Allows currency fields to be parsed in email templates as currency on the final email.
@serhiisamko091184
Copy link
Contributor

Hello @pstevens71,

thanks for your contribution!

Regards,
Serhii

@serhiisamko091184 serhiisamko091184 added Status: Requires Code Review Needs the core team to code review Status:Assessed PRs that have been tested and confirmed to resolve an issue by a core team member Area: Emails:Templates Issues & PRs related to email templates Branch:Hotfix PR 4-8 Score given to PRs once assessed labels Dec 11, 2023
@jack7anderson7 jack7anderson7 added Status: Requires Testing Requires Manual Testing Status: Passed Code Review Mark issue has passed code review reviewed and removed Status: Requires Code Review Needs the core team to code review labels May 2, 2024
@johnM2401 johnM2401 added the Status:Requires Updates Issues & PRs which requires input or update from the author label May 3, 2024
@johnM2401
Copy link
Contributor

johnM2401 commented May 3, 2024

Hey @pstevens71 !

Thank you for your contributions!

I've given this PR a test locally
However, it seems as though the Email template always formats the amount value as USD.
This might lead to confusion / wrong information being interpreted if the CRM is using multiple Currencies.

For example, if I create the following Email template for Opportunities:
image

I create a 2nd Currency for GBP, and set it on an Opportunity:
image

The Email comes through with the correct Currency selected, but the "Amount" field is rendered in USD:
image


Do you know if this is intended/expected for this PR?

Thanks!

@pstevens71
Copy link
Contributor Author

Hmm, it seems like the problem (in addition to this one) is with the _convertToType() either not parsing the right currency or, not getting passed what it needs to do so. I'll have a look.

@pstevens71
Copy link
Contributor Author

Ok having a deeper dive into the _convertToType() function it will always convert it to the default currency specified in the locale (not the amount, but they formatting of the output). It needs a condition to check the current record to see if a different currency is set in order to work for an alternate currency from the default locale. I'll see if I can come up with something for that too.

@pstevens71
Copy link
Contributor Author

Grr, why does everything have to be a can of worms! Ok so the amount in $opportunity_amount_usdollar is not actually the amount in USD, it's an unfortunate field name, it is actually the amount in the default currency specified in the locale settings (in my case CDN). $opportunity_amount is the $opportunity_usdollar_amount converted to the currency selected in the opportuntiy. So in my case, $CDN = 1, and $25,000 outputs as both $25,000 for both fields. If I change the opp to USD then the output is: Amount in USD = $25,000 (which is actuall $25, 000 CDN) and the $opportunity_amount is now $18,250 (USD). So the rule would have to be something like if the record contains amount_usdollar, then use the locale currency, if the current record contains a currency ID other than the locale, then use that instead for the field. So the amount_usdollar should always output as the default locale and any other amounts (if they exist) should output in the currency of current record. Ok let's see if I can do that!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Emails:Templates Issues & PRs related to email templates Branch:Hotfix PR 4-8 Score given to PRs once assessed Status:Assessed PRs that have been tested and confirmed to resolve an issue by a core team member Status: Passed Code Review Mark issue has passed code review reviewed Status: Requires Testing Requires Manual Testing Status:Requires Updates Issues & PRs which requires input or update from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants