Commit 4750ab01 authored by eileen's avatar eileen

Add test for api money, fix net_amount calc

parent 5528fa66
......@@ -122,7 +122,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
//if priceset is used, no need to cleanup money
if (!empty($params['skipCleanMoney'])) {
unset($moneyFields[0]);
$moneyFields = [];
}
else {
// @todo put a deprecated here - this should be done in the form layer.
......
......@@ -47,6 +47,13 @@ function civicrm_api3_contribution_create(&$params) {
$params = array_merge($params, $values);
// The BAO should not clean money - it should be done in the form layer & api wrapper
// (although arguably the api should expect pre-cleaned it seems to do some cleaning.)
if (empty($params['skipCleanMoney'])) {
foreach (['total_amount', 'net_amount', 'fee_amount'] as $field) {
if (isset($params[$field])) {
$params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]);
}
}
}
$params['skipCleanMoney'] = TRUE;
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
......
......@@ -682,15 +682,26 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
/**
* Create test with unique field name on source.
*
* @param string $thousandSeparator
* punctuation used to refer to thousands.
*
* @dataProvider getThousandSeparators
*/
public function testCreateDefaultNow() {
public function testCreateDefaultNow($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$params = $this->_params;
unset($params['receive_date']);
unset($params['receive_date'], $params['net_amount']);
$params['total_amount'] = $this->formatMoneyInput(5000.77);
$params['fee_amount'] = $this->formatMoneyInput(.77);
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$contribution = $this->callAPISuccessGetSingle('contribution', array('id' => $contribution['id']));
$this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receive_date'])));
$this->assertEquals(5000.77, $contribution['total_amount'], 'failed to handle ' . $this->formatMoneyInput(5000.77));
$this->assertEquals(.77, $contribution['fee_amount']);
$this->assertEquals(5000, $contribution['net_amount']);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment