-
-
Notifications
You must be signed in to change notification settings - Fork 814
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
Conversation
@@ -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); |
There was a problem hiding this comment.
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
7261e5a
to
1e9e935
Compare
@@ -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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much nicer!
I don't think so. This does need rebasing though. @pradpnayak or @Edzelopez |
Hi @colemanw, I've rebased the PR. |
jenkins, retest this please |
---------------------------------------- * 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
jenkins, retest this please |
Edsel / Pradeep, could you check the tests for add and edit are different and appropriate wrt to storing value of opening balances? |
@Edzelopez or @pradpnayak these 2 test failures do look relevant. |
'total_amount' => 100, | ||
'financial_type_id' => 3, | ||
'financial_type_id' => 4, |
There was a problem hiding this comment.
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.
Jenkin, test this please |
@pradpnayak there is one related test failure https://test.civicrm.org/job/CiviCRM-Core-PR/10564/
|
@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
https://test.civicrm.org/job/CiviCRM-Core-PR/10619/ |
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
Could you update call signature docblock for validateFinancialType()? |
@eileenmcnaughton are you doing anything with Auth.net right now that might cause the error here? Or is it likely something in this PR? |
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 |
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
Updated Code |
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)) { |
There was a problem hiding this comment.
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
Added fix |
jenkins, retest this please |
1 similar comment
jenkins, retest this please |
@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. |
Hmm, it looks like the test ran https://test.civicrm.org/job/CiviCRM-Core-PR/10966/ which reports one failure, |
As well, that error seems unrelated to the code in the PR. @colemanw I think this is ready to merge. |
https://issues.civicrm.org/jira/browse/CRM-16189