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-21656: Backend Membership with Priceset applies taxes twice to line_item #11521

Merged
merged 1 commit into from
Jan 18, 2018

Conversation

monishdeb
Copy link
Member

@monishdeb monishdeb commented Jan 15, 2018

Overview

Steps to reproduce:

Enable Taxes, Add a tax account with a 10% tax

  1. Add the tax account to the Membership financial type
  2. Create a new priceset for memberships, with radio options for the main membership options.
  3. From a contact record, add a new membership for that contact, select an option from the priceset.

Notice how to total amount is OK, but when we view the contribution, the line
item shows a unit_price with the tax_amount included, so then the total_line
ends up adding the taxes again.

Before

test-multiple-before

After

test-multiple-after

Technical Details

Also, there is a minor change in contribution backoffice form, where earlier the fn responsible to fetch line-item, got missing parameter $priceSetID.


@monishdeb
Copy link
Member Author

ping @mlutfy @eileenmcnaughton

@@ -430,11 +430,12 @@ public static function getAssoc($withInactive = FALSE, $extendComponentName = FA
* Appears to have no effect based on reading the code.
* @param bool $validOnly
* Should only fields where today's date falls within the valid range be returned?
* @param bool $resetOptions
Copy link
Member Author

Choose a reason for hiding this comment

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

This parameter is introduced for unit test which needs to reload price options when sale tax is enabled, in order to get tax_amount and tax_rate info.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should switch to using \Civi::$statics inside the CRM_Price_BAO_PriceField::getOptions rather than add this param if it is to support unit tests - we have been doing that elsewhere

@@ -3774,6 +3777,9 @@ protected function relationForFinancialTypeWithFinancialAccount($financialTypeId
'account_relationship' => key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Sales Tax Account is' ")),
);

// set tax rate (as 10) for provided financial type ID to static variable, later used to fetch tax rates of all financial types
\Civi::$statics['CRM_Core_PseudoConstant']['taxRates'][$financialTypeId] = 10;
Copy link
Member Author

Choose a reason for hiding this comment

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

There is no other way where we can update this static variable (which holds the tax rates of all FT) after setting a Taxable financial account to a financial type.

@monishdeb
Copy link
Member Author

monishdeb commented Jan 16, 2018

@eileenmcnaughton thanks for the tip :) used Civi::$statics['CRM_Price_BAO_PriceField']['priceOptions'] instead and this is the commit

@eileenmcnaughton
Copy link
Contributor

This looks solid to me - lets squash to one patch (to avoid adding & removing the $reset param) and merge once the test passes

@monishdeb
Copy link
Member Author

Done 👍

@eileenmcnaughton
Copy link
Contributor

OK - the change itself is minor and logical

@monishdeb
Copy link
Member Author

Jenkins test this please

@eileenmcnaughton
Copy link
Contributor

I think that might be related - the fail is about ensuring that money is cleaned at the form layer not low down - good to get it fixed

if (CRM_Utils_Array::value('field_title', $lineItem[$optionValueId]) == 'Membership Amount') {
$lineItem[$optionValueId]['line_total'] = $lineItem[$optionValueId]['unit_price'] = CRM_Utils_Rule::cleanMoney($lineItem[$optionValueId]['line_total'] - $lineItem[$optionValueId]['tax_amount']);
}
$lineItem[$optionValueId]['line_total'] = $lineItem[$optionValueId]['unit_price'] = CRM_Utils_Rule::cleanMoney($lineItem[$optionValueId]['line_total'] - $lineItem[$optionValueId]['tax_amount']);
Copy link
Member

@mlutfy mlutfy Jan 17, 2018

Choose a reason for hiding this comment

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

This is causing weird things in the Contribution Confirm & ThankYou pages, when using pricesets:

  • say a membership is 100$ with a 5$ tax,
  • then it will show: 95$ membership, 5$ tax, total 100$.

@monishdeb
Copy link
Member Author

@mlutfy I have updated the PR, can you please check now?

@mlutfy
Copy link
Member

mlutfy commented Jan 17, 2018

@monishdeb yep, works! thanks! I also re-tested some other use-cases, such as a simple membership without a priceset.

@eileenmcnaughton
Copy link
Contributor

test this please

@seamuslee001
Copy link
Contributor

Tests have passed and seems to have been reviewed and tested by @mlutfy so I think this is good to merge now

@eileenmcnaughton eileenmcnaughton merged commit e0cdb02 into civicrm:master Jan 18, 2018
@mlutfy mlutfy added this to the 4.7.31 milestone Feb 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants