Fix bug where tax_amount is miscalculated on membership renewals
authoreileen <emcnaughton@wikimedia.org>
Sat, 14 Mar 2020 00:29:28 +0000 (13:29 +1300)
committereileen <emcnaughton@wikimedia.org>
Sat, 14 Mar 2020 20:52:26 +0000 (09:52 +1300)
commit7aa78908c50c23d8fcd15fb757e87a466627ddba
tree8e7d414880b3f6a3ce7773d5b0e1851bb5388d77
parent0f4c9fab67a61ba6f927efcffbe9b70fe2a772e9
Fix bug where tax_amount is miscalculated on membership renewals

In order to replicate
1) enable tax & invoicing
2) configure a financial type with sales tax
3) renew a membership, entering an amount other than the default membership amount.
4) view the membership - tax amount will be the same as it would be if the default amount had been used.

Tangental bugs I noticed
1) regression in master on adding financial accounts - I will do a separate PR
2) tax term not assigned to the template - out of scope for now but I believe a pre-hook type
structure should exist, assigning this to the template when enabled (as part of moving some code to
a core-extension).
3) the form shows  the tax amount & does not update it - this is pretty big already so that is also out of scope for now

This bug affects both membership & membership renewal pages. This PR only fixes for membership renewal
but the goal is to fix for membership too once this is merged. It is a fairly 'bug' fix in that it
introduces a new class with new methods to get the information otherwise provided by
CRM_Price_BAO_PriceSet::processAmount. processAmount is one of those functions that is hard to read
and understand & has been hacked to do various things. Code that calls it is hard
to read because of this. Having a cleaner way to operate has been a goal for a while. We
have plans to build up the Order api to be much more usable and used. However, we really
need to build up sensible helpers before we can address that. This PR adds a class
that has a whole lot of functions that are more readable to do what the processAmount otherwise
does. The goal is to deprecate processAmount.

I started on MembershipRenewal as
1) it has a bug currently and
2) it is pretty simple in that it doesn't actually support pricesets - which is especially
helpful when testing :-)
CRM/Financial/BAO/Order.php [new file with mode: 0644]
CRM/Member/Form.php
CRM/Member/Form/MembershipRenewal.php
CRM/Price/BAO/PriceSet.php
tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php
tests/phpunit/CRM/Member/Form/MembershipTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php