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

dev/financial#109 Fix country/province assignation in the contribution invoice #15964

Merged
merged 1 commit into from
Mar 1, 2020

Conversation

mlutfy
Copy link
Member

@mlutfy mlutfy commented Nov 26, 2019

Overview

To reproduce:

  • Enable Taxes and Invoicing
  • Edit the "Contribution Invoice Receipt" message template to include {$country} (other related contact tokens are called {$street_address}, {$email}, etc.
  • Go to a contact, create a contribution, and from "view contribution", click "print PDF invoice" to view an invoice.

The country will be empty.

https://lab.civicrm.org/dev/financial/issues/109

Technical Details

  • CRM_Contribute_Form_Task_Invoice: I did a bit of code cleanup because the invoice code did not make a ton of sense, and presumably CRM_Core_BAO_Address::getValues() has changed a fair amount since this invoice code was first written. Notably the loop for finding the billing address seemed over-complex.
  • CRM_Contribute_Form_Task_Invoice also had an array for billingAddress, which hinted that there could be something more going on, but given that the variable is initialized inside the loop, I could not figure out its purpose.
  • `CRM_Core_BAO_Address::getValues() was doing state/province lookup, but it was not storing it in the right variable, so it was not getting returned to the caller.

@civibot civibot bot added the master label Nov 26, 2019
@civibot
Copy link

civibot bot commented Nov 26, 2019

(Standard links)

CRM/Contribute/Form/Task/Invoice.php Show resolved Hide resolved
CRM/Contribute/Form/Task/Invoice.php Outdated Show resolved Hide resolved
CRM/Core/BAO/Address.php Show resolved Hide resolved
@mlutfy mlutfy force-pushed the financial109 branch 2 times, most recently from d870c86 to 5fc4ca7 Compare November 26, 2019 17:43
@mlutfy
Copy link
Member Author

mlutfy commented Nov 26, 2019

We can still have only a "primary" address. CRM_Core_BAO_Address::getValues() only inserts an order by clause when we specify is_billing = 1:

factures

@@ -495,15 +495,16 @@ public static function &getValues($entityBlock, $microformat = FALSE, $fieldName
if (!empty($address->state_province_id)) {
$address->state = CRM_Core_PseudoConstant::stateProvinceAbbreviation($address->state_province_id, FALSE);
$address->state_name = CRM_Core_PseudoConstant::stateProvince($address->state_province_id, FALSE);
$values['state_province_abbreviation'] = $address->state;
Copy link
Contributor

Choose a reason for hiding this comment

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

@mlutfy which one is meant to be the abbreviation?

Copy link
Member Author

Choose a reason for hiding this comment

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

@seamuslee001 oops, good catch, auto-complete typo (fixed). I guess that would be a good use-case for a test?

@mlutfy mlutfy force-pushed the financial109 branch 2 times, most recently from 2e03af8 to ccf3af0 Compare November 27, 2019 16:54
@eileenmcnaughton
Copy link
Contributor

@mlutfy I feel like this is stuck on not having a test

@BettyDolfing
Copy link

test this please

@jaapjansma
Copy link
Contributor

Betty and I are reviewing PR's and we came across this one.

  • General standards
    • Explain (r-explain)
      • PASS : The goal/problem/solution have been adequately explained in the PR and in the issue.
    • User impact (r-user)
      • PASS: The change would be intuitive.
    • Documentation (r-doc)
      • PASS: The changes do not require documentation.
    • Run it (r-run)
      • PASS: We tested it with a country other than the default country and it showed the country
      • COMMENT: When the country is the same as the default country and the setting Hide Country in Mailing Labels when same as domain country is enabled then the country is still shown. Not sure whether that is relevant for this PR.
  • Developer standards
    • Technical impact (r-tech)
      • PASS: The change potentially affects compatibility, but the risks have been sufficiently managed.
    • Code quality (r-code)
      • PASS: The functionality, purpose, and style of the code seems clear+sensible.
    • Maintainability (r-maint)
      • PASS: The change is trivial enough that it does not require tests. It even cleans up code about fetching the billing address well done!
    • Test results (r-test)
      • PASS: The test results are all-clear.

@eileenmcnaughton or @mattwire is one of you able to merge this PR?

@mlutfy
Copy link
Member Author

mlutfy commented Feb 19, 2020

I still need to add a test, alas. It's high on my list, and quickfix, hoping to do it soon.

@jaapjansma
Copy link
Contributor

Our opinion is that this doesn't necessarily needs a test. But a test makes it a surplus

@eileenmcnaughton
Copy link
Contributor

Test cover on everything to do with invoice code is awful - so I'm loathe to let anything be changed on the invoice code without tests.

Generally in an area like this with no tests I consider a 'no error' test to be enough - ie. a test that calls printPDF with no fatal errors - whether or not it tests the change being made. In this case it is progress on testing in that area

@mattwire mattwire mentioned this pull request Feb 24, 2020
@magnolia61
Copy link
Contributor

I can confirm that this patch enables the {$country} token in the invoice template

@mlutfy
Copy link
Member Author

mlutfy commented Feb 29, 2020

I added a test to check the province/abbreviation in getValues(), and I will add a test for the invoice itself in a separate PR, that will pass once #16569 is merged.

@eileenmcnaughton
Copy link
Contributor

Nice, thanks @mlutfy

@eileenmcnaughton eileenmcnaughton merged commit 4beda4a into civicrm:master Mar 1, 2020
@eileenmcnaughton eileenmcnaughton deleted the financial109 branch March 1, 2020 20:10
@magnolia61
Copy link
Contributor

Thanks, I am using the {$country) token in the updated Contribution Invoice template (#16680)

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.

7 participants