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

[ready-for-core-team-review]CRM-16189, added code to validate financial type for contribution #8586

Merged
merged 10 commits into from
Aug 1, 2016

Conversation

pradpnayak
Copy link
Contributor


@@ -177,6 +177,11 @@ public static function add(&$params, $ids = array()) {
$params['prevContribution'] = self::getValues(array('id' => $contributionID), CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
}

// CRM-16189
$error = CRM_Financial_BAO_FinancialAccount::checkForValidFinancialType($params, $contributionID);
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems to be a new function so let's have it throw an exception. In general we prefer BAO functions (& lots of other things) to throw exceptions rather than return errors - which leads to ugly stuff like this. The form layer should catch & handle the exceptions

@pradpnayak pradpnayak force-pushed the CRM-16189-17 branch 2 times, most recently from 7261e5a to 1e9e935 Compare June 26, 2016 23:55
@pradpnayak pradpnayak changed the title CRM-16189, added code to validate financial type for contribution [ready-for-core-team-review]CRM-16189, added code to validate financial type for contribution Jul 2, 2016
@@ -998,7 +998,12 @@ public static function formRule($fields, $files, $self) {
$errors['trxn_id'] = ts('Transaction ID\'s must be unique. Transaction \'%1\' already exists in your database.', array(1 => $fields['trxn_id']));
}
}

// CRM-16189
$errorMessage = CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($fields, $self->_id, $self);
Copy link
Member

Choose a reason for hiding this comment

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

IMO checkFinancialTypeHasDeferred should be updated to return a boolean and the message should be generated here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

@Edzelopez
Copy link
Contributor

@colemanw, are the test errors related?

$error = CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params, $contributionID);
if ($error) {
if (CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params, $contributionID)) {
$error = ts('Revenue recognition date can only be specified if the financial type selected has a deferred revenue account configured. Please have an administrator set up the deferred revenue account at Administer > CiviContribute > Financial Accounts, then configure it for financial types at Administer > CiviContribution > Financial Types, Accounts');
Copy link
Contributor

Choose a reason for hiding this comment

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

Much nicer!

@colemanw
Copy link
Member

colemanw commented Jul 5, 2016

I don't think so. This does need rebasing though. @pradpnayak or @Edzelopez

@Edzelopez
Copy link
Contributor

Edzelopez commented Jul 6, 2016

Hi @colemanw, I've rebased the PR.

@colemanw
Copy link
Member

colemanw commented Jul 6, 2016

jenkins, retest this please

pradpnayak and others added 5 commits July 7, 2016 15:41
----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189

Conflicts:
	CRM/Contribute/Form/Contribution.php
----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189
----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189
----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189
@Edzelopez
Copy link
Contributor

jenkins, retest this please

@JoeMurray
Copy link
Contributor

Edsel / Pradeep, could you check the tests for add and edit are different and appropriate wrt to storing value of opening balances?

@colemanw
Copy link
Member

colemanw commented Jul 7, 2016

@Edzelopez or @pradpnayak these 2 test failures do look relevant.

'total_amount' => 100,
'financial_type_id' => 3,
'financial_type_id' => 4,
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: So it appears that this is Event Fee financial type (https://github.com/civicrm/civicrm-core/blob/master/xml/templates/civicrm_data.tpl#L128) which has a deferred revenue account (https://github.com/civicrm/civicrm-core/blob/master/xml/templates/civicrm_data.tpl#L889) defined for it at
https://github.com/civicrm/civicrm-core/blob/master/xml/templates/civicrm_data.tpl#L1700 so the created contribution should have a financial type with a deferred revenue account.

@monishdeb
Copy link
Member

Jenkin, test this please

@monishdeb
Copy link
Member

monishdeb commented Jul 8, 2016

@pradpnayak there is one related test failure https://test.civicrm.org/job/CiviCRM-Core-PR/10564/

This should have been true.
Failed asserting that false is true. ```

@JoeMurray
Copy link
Contributor

@pradpnayak check with @Edzelopez - I think he did some refactoring work on this today based on comments but didn't commit because it caused various test failures.

----------------------------------------
* CRM-16189:
  https://issues.civicrm.org/jira/browse/CRM-16189
@pradpnayak
Copy link
Contributor Author

https://test.civicrm.org/job/CiviCRM-Core-PR/10619/
Is failure related to changes in PR?

@pradpnayak pradpnayak closed this Jul 16, 2016
@pradpnayak pradpnayak deleted the CRM-16189-17 branch July 16, 2016 02:31
@pradpnayak pradpnayak restored the CRM-16189-17 branch July 16, 2016 02:32
@pradpnayak pradpnayak reopened this Jul 16, 2016
@JoeMurray
Copy link
Contributor

Pradeep, checkFinancialTypeHasDeferred still needs to be rewritten to address my comments so far as I can see.

…nition date

----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189
*
* @return string
* @return bool
*
*/
public static function checkFinancialTypeHasDeferred($params, $contributionID = NULL, $form = NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is good style to pass $form object to BAO. And I don't see where $form is used in function. Can we remove it from call signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I see it now at L393. @colemanw could you comment on what to do here - is this acceptable practice, or should the relevant work to deal with Priceset be done in the form and then passed in to this function?

Copy link
Contributor

Choose a reason for hiding this comment

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

@JoeMurray @pradpnayak the former - never do anything to a form outside the form class it you can help it!

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused what you mean by 'the former': this is 'acceptable practice' to read but not modify contents of the form? Or did you mean 'the latter', the form should do the work with the Priceset so that more detailed arg than the form would be passed into this function. Thanks for the feedback @eileenmcnaughton

Copy link
Member

Choose a reason for hiding this comment

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

I think it would be cleaner to change the variable to $priceSet and pass in $form->_priceSet instead of the entire $form.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed.

@JoeMurray
Copy link
Contributor

Could you update call signature docblock for validateFinancialType()?

@JoeMurray
Copy link
Contributor

@eileenmcnaughton are you doing anything with Auth.net right now that might cause the error here? Or is it likely something in this PR?

@eileenmcnaughton
Copy link
Contributor

That test has an intermittent failure which is time dependent - that does not look like the failure but it could have arisen in a previous PR without people noticing it due to the intermittent failure - it's probably work checking test history on test.civicrm.org

@JoeMurray
Copy link
Contributor

jenkins, retest this please

updated to code follow CiviCRM standard

----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189
@pradpnayak
Copy link
Contributor Author

Updated Code

@JoeMurray
Copy link
Contributor

Coleman, I think this is ready for merge, and is part of accrual accounting functionality for this release

@@ -177,6 +177,11 @@ public static function add(&$params, $ids = array()) {
$params['prevContribution'] = self::getValues(array('id' => $contributionID), CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
}

// CRM-16189
if (CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params, $contributionID)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

move the throwing of exception down into CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred() so that the $error string only needs to be specified once.

…rm level

----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189
----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189
@pradpnayak
Copy link
Contributor Author

Added fix

@pradpnayak
Copy link
Contributor Author

jenkins, retest this please

1 similar comment
@JoeMurray
Copy link
Contributor

jenkins, retest this please

@JoeMurray
Copy link
Contributor

@yashodha If it says 'Some checks haven't completed yet' after 5 days, and trying to retest doesn't change that, what is the next step? I would like this PR to be committed if it passes tests.

@eileenmcnaughton
Copy link
Contributor

maybe ping @totten or @mlutfy on why the test isn't kicking off?

@totten
Copy link
Member

totten commented Aug 1, 2016

Hmm, it looks like the test ran https://test.civicrm.org/job/CiviCRM-Core-PR/10966/ which reports one failure, CRM_Contact_BAO_ContactType_ContactTest.testCRM19133. (Aside: I'm not familiar with that test, but I've seen it sporadically in the past couple days...)

@JoeMurray
Copy link
Contributor

As well, that error seems unrelated to the code in the PR. @colemanw I think this is ready to merge.

@colemanw colemanw merged commit 02c14d7 into civicrm:master Aug 1, 2016
@pradpnayak pradpnayak deleted the CRM-16189-17 branch August 2, 2016 19:55
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.

8 participants