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

CRM-16228, fixed tax calculation as per https://github.com/civicrm/ci… #9643

Closed
wants to merge 3 commits into from

Conversation

pradpnayak
Copy link
Contributor

…vicrm-core/pull/9626#issuecomment-270380614


@pradpnayak
Copy link
Contributor Author

Will add test soon

@pradpnayak
Copy link
Contributor Author

The fix should not cause regression for https://issues.civicrm.org/jira/browse/CRM-17848
(please test using paypal as part of QA)

----------------------------------------
* CRM-16228: Tax Math is not correct due to premature rounding
  https://issues.civicrm.org/jira/browse/CRM-16228
----------------------------------------
* CRM-16228: Tax Math is not correct due to premature rounding
  https://issues.civicrm.org/jira/browse/CRM-16228
----------------------------------------
* CRM-16228: Tax Math is not correct due to premature rounding
  https://issues.civicrm.org/jira/browse/CRM-16228
@@ -473,10 +473,12 @@ public static function getFirstLastDetails($contactID) {
* array of tax amount
*
*/
public static function calculateTaxAmount($amount, $taxRate) {
public static function calculateTaxAmount($amount, $taxRate, $htmlType = NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this an odd place to have $htmlType? A static utility function, which calculates a tax based on an amount and a rate, shouldn't need to know something like $htmlType. I see that it's used to decide whether or not to round the amount, but why does this rounding happen in this function -- or specifically, why does it happen only for certain values of $htmlType? Shouldn't rounding happen somewhere later, just at the time this value actually needs to be rounded (e.g., at display time)?

Copy link
Contributor

@twomice twomice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggesting test names be more explicit.

/**
* Test form submission CRM-16228.
*/
public function testSubmitContributionPageWithPriceSetHavingTaxCRM16228() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because unit tests are so important, it's also important that unit tests have very clear names. A name like "testContributionPageWithPriceSetHavingTaxHasCorrectTaxAndTotalAmounts" would be better than "testSubmitContributionPageWithPriceSetHavingTaxCRM16228" because it plainly says what's being tested, without requiring someone to look-up and read through a JIRA ticket. This is an easy fix to improve our ability to keep writing unit tests on financial code.

/**
* Test form submission CRM-16228.
*/
public function testSubmitContributionPageWithPriceSetHaving2PriceFieldTaxCRM16228() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, it would be very helpful to rename this test to "testContributionPageWithPriceSetHaving2PriceFieldTaxHasCorrectTaxAndTotalAmounts" (because: plainly says what's being tested; doesn't require examining a JIRA ticket to understand). An important and easy fix to improve our ability to keep writing unit tests on financial code.

/**
* Test form submission CRM-16228.
*/
public function testSubmitContributionPageWithPriceSetHavingTaxCRM16228() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above comments, it would be very helpful to rename this test to "testContributionPageWithPriceSetHavingTaxHasCorrectTaxAndTotalAmounts" .

/**
* Test form submission CRM-16228.
*/
public function testSubmitContributionPageWithPriceSetHaving2PriceFieldTaxCRM16228() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above comments, it would be very helpful to rename this test to "testContributionPageWithPriceSetHaving2PriveFieldTaxHasCorrectTaxAndTotalAmounts" .

@KarinG
Copy link
Contributor

KarinG commented Jan 9, 2017

Please note that there are (Test Result) (10 failures / +9)

1. api_v3_ContributionPageTest.testSubmitMembershipBlockNotSeparatePaymentZeroDollarsWithEmail
2. api_v3_ContributionPageTest.testSubmitMembershipBlockIsSeparatePayment
3. api_v3_ContributionPageTest.testSubmitMembershipBlockIsSeparatePaymentWithEmail
4. api_v3_ContributionPageTest.testSubmitMembershipBlockIsSeparatePaymentZeroDollarsPayLaterWithEmail
5. api_v3_ContributionPageTest.testSubmitMembershipBlockTwoTypesIsSeparatePayment
6. api_v3_ContributionPageTest.testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNow
7. api_v3_ContributionPageTest.testSubmitMembershipPriceSetPaymentPaymentProcessorSeparatePaymentRecurInstantPayment
8. api_v3_ContributionPageTest.testSubmitPledgePaymentPaymentProcessorRecurFuturePayment
9. api_v3_ContributionPageTest.testSubmitPledgePayment
10. api_v3_ContributionTest.testpayLater

twomice added a commit to twomice/civicrm-core that referenced this pull request Jan 23, 2017
@pradpnayak pradpnayak closed this Jan 27, 2017
@pradpnayak pradpnayak deleted the CRM-16228 branch February 22, 2017 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants