Skip to content

Commit

Permalink
Merge pull request #192 from compucorp/COMCL-744-fix-creditnote
Browse files Browse the repository at this point in the history
COMCL-744: Remove methods and class depreceated in 5.75
  • Loading branch information
olayiwola-compucorp authored Sep 4, 2024
2 parents 361f1f9 + 19bb3e2 commit 99958b2
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 21 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ jobs:
run : composer self-update 2.2.5

- name: Build Drupal site
run: civibuild create drupal-clean --civi-ver 5.51.3 --cms-ver 7.94 --web-root $GITHUB_WORKSPACE/site
run: civibuild create drupal-clean --civi-ver 5.75.0 --cms-ver 7.94 --web-root $GITHUB_WORKSPACE/site

- uses: compucorp/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
repo: compucorp/civicrm-core
version: 5.51.3
version: 5.75.0
path: site/web/sites/all/modules/civicrm

- uses: actions/checkout@v2
Expand All @@ -49,6 +49,25 @@ jobs:
- name: Installing Finance Extras
working-directory: ${{ env.CIVICRM_EXTENSIONS_DIR }}
run: cv en financeextras


- name: Setup Test DB
run: echo "CREATE DATABASE civicrm_test;" | mysql -u root --password=root --host=mysql

- name: Update civicrm.settings.php
run: |
FILE_PATH="$GITHUB_WORKSPACE/site/web/sites/default/civicrm.settings.php"
INSERT_LINE="\$GLOBALS['_CV']['TEST_DB_DSN'] = 'mysql://root:root@mysql:3306/civicrm_test?new_link=true';"
TMP_FILE=$(mktemp)
while IFS= read -r line
do
echo "$line" >> "$TMP_FILE"
if [ "$line" = "<?php" ]; then
echo "$INSERT_LINE" >> "$TMP_FILE"
fi
done < "$FILE_PATH"
mv "$TMP_FILE" "$FILE_PATH"
echo "File modified successfully."
- name: Run phpunit tests
working-directory: ${{ env.CIVICRM_EXTENSIONS_DIR }}/io.compuco.financeextras
Expand Down
4 changes: 2 additions & 2 deletions CRM/Financeextras/BAO/CreditNote.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ private static function createRefundAccountingEntries(array $creditNote, $data)
$data = array_merge($creditNote, ['total_credit' => $data['amount'] * -1], $data);
$financialTypeId = $creditNote['line'][0]['financial_type_id'];
$data['from_account_id'] = FinancialAccountUtils::getFinancialTypeAccount($financialTypeId, 'Accounts Receivable Account is');
$data['to_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($data['payment_instrument_id']);
$data['to_account_id'] = CRM_Financial_BAO_EntityFinancialAccount::getInstrumentFinancialAccount($data['payment_instrument_id']);
$data['is_payment'] = 1;
$data['net_amount'] = $data['total_credit'] - ($data['fee_amount'] ?? 0);
$financialTrxn = self::createAccountingEntries($data, 'Completed');
Expand All @@ -352,7 +352,7 @@ private static function createRefundAccountingEntries(array $creditNote, $data)
private static function createFeeAccountingEntries($creditNote, $data) {
$financialTypeId = $creditNote['line'][0]['financial_type_id'];
$data = [
'from_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($data['payment_instrument_id']),
'from_account_id' => CRM_Financial_BAO_EntityFinancialAccount::getInstrumentFinancialAccount($data['payment_instrument_id']),
'to_account_id' => FinancialAccountUtils::getFinancialTypeAccount($financialTypeId, 'Expense Account is'),
'date' => $data['date'],
'total_credit' => $data['fee_amount'],
Expand Down
2 changes: 1 addition & 1 deletion CRM/Financeextras/BAO/CreditNoteLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static function deleteAccountingEntries($creditNoteLineId) {
$financialItem->find(TRUE);

$entityTrxn = new \CRM_Financial_DAO_EntityFinancialTrxn();
$entityTrxn->entity_table = \CRM_Financial_BAO_FinancialItem::$_tableName;
$entityTrxn->entity_table = \CRM_Financial_BAO_FinancialItem::getTableName();
$entityTrxn->entity_id = $financialItem->id;
$entityTrxn->find(TRUE);

Expand Down
2 changes: 2 additions & 0 deletions CRM/Financeextras/Page/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ private function generateActionLinks() {
'name' => ts('Edit'),
'url' => 'civicrm/admin/financeextras/company/add',
'qs' => 'id=%%id%%&reset=1',
'weight' => 10,
],
CRM_Core_Action::DELETE => [
'name' => ts('Delete'),
'url' => 'civicrm/admin/financeextras/company/delete',
'qs' => 'id=%%id%%',
'weight' => 12,
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Civi\Financeextras\Event;

use Symfony\Component\EventDispatcher\Event;
use Civi\Core\Event\GenericHookEvent as Event;

/**
* The fe.contribution.received_payment event will be dispatched
Expand Down
2 changes: 1 addition & 1 deletion Civi/Financeextras/Event/CreditNoteDownloadedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Civi\Financeextras\Event;

use Symfony\Component\EventDispatcher\Event;
use Civi\Core\Event\GenericHookEvent as Event;

/**
* The fe.creditnote.downloaded event is dispatched
Expand Down
2 changes: 1 addition & 1 deletion Civi/Financeextras/Event/CreditNoteMailedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Civi\Financeextras\Event;

use Symfony\Component\EventDispatcher\Event;
use Civi\Core\Event\GenericHookEvent as Event;

/**
* The fe.creditnote.mailed event is dispatched
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
border: 1px dotted #000;
border-style: none none dotted;
">
<img src="{$base_url}{crmResURL ext=io.compuco.financeextras file=images/cut.png}" style="height: 31px; width: auto;">
<img src="{$base_url}{crmResURL ext='io.compuco.financeextras' file='images/cut.png'}" style="height: 31px; width: auto;">
</div>

<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function testExpectedAccountingEntriesAreCreatedForCrediNoteLine() {
// Financial item should have a entity financial transaction.
$entityFinancialTrxn = \Civi\Api4\EntityFinancialTrxn::get(FALSE)
->addWhere('entity_id', '=', $financialItem['id'])
->addWhere('entity_table', '=', \CRM_Financial_BAO_FinancialItem::$_tableName)
->addWhere('entity_table', '=', \CRM_Financial_BAO_FinancialItem::getTableName())
->execute()
->first();

Expand Down Expand Up @@ -263,7 +263,7 @@ public function testExpectedAccountingEntriesAreCreatedForCrediNoteLineWithTax()
foreach ([$financialItemForMainAmount, $financialItemForTax] as $financialItem) {
$entityFinancialTrxn = \Civi\Api4\EntityFinancialTrxn::get(FALSE)
->addWhere('entity_id', '=', $financialItem['id'])
->addWhere('entity_table', '=', \CRM_Financial_BAO_FinancialItem::$_tableName)
->addWhere('entity_table', '=', \CRM_Financial_BAO_FinancialItem::getTableName())
->execute()
->first();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function testExpectedCreditNoteLineAccountingEntriesAreDeleted() {

$entityFinancialTrxn = \Civi\Api4\EntityFinancialTrxn::get(FALSE)
->addWhere('entity_id', '=', $financialItem['id'])
->addWhere('entity_table', '=', \CRM_Financial_BAO_FinancialItem::$_tableName)
->addWhere('entity_table', '=', \CRM_Financial_BAO_FinancialItem::getTableName())
->execute()
->first();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testRefundFinancialTrxnHasExpectedToandFromAccountId() {
$creditNote['items'][0]['financial_type_id'],
'Accounts Receivable Account is'
);
$expectedToAccount = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount(1);
$expectedToAccount = CRM_Financial_BAO_EntityFinancialAccount::getInstrumentFinancialAccount(1);

$this->assertEquals($financialTrxn['to_financial_account_id'], $expectedToAccount);
$this->assertEquals($financialTrxn['from_financial_account_id'], $expectedFromAccount);
Expand Down Expand Up @@ -153,7 +153,7 @@ public function testExpectedRefundEntityFinancialAccountingEntriesAreCreatedForF
'Expense Account is'
);

$expectedFromAccount = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount(3);
$expectedFromAccount = CRM_Financial_BAO_EntityFinancialAccount::getInstrumentFinancialAccount(3);

$refundFeeFinancialTrxn = \Civi\Api4\FinancialTrxn::get(FALSE)
->addWhere('id', '=', $refundAllocation['fee_financial_trxn_id'])
Expand Down Expand Up @@ -235,7 +235,7 @@ public function testRefundEntityFinancialAccountingEntriesAreNotCreatedForFee()
'Expense Account is'
);

$expectedFromAccount = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount(3);
$expectedFromAccount = CRM_Financial_BAO_EntityFinancialAccount::getInstrumentFinancialAccount(3);

$refundFeeFinancialTrxn = \Civi\Api4\FinancialTrxn::get(FALSE)
->addWhere('id', '=', $refundAllocation['fee_financial_trxn_id'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function testExpectedCreditNoteLineAccountingEntriesAreCreated() {
foreach ([$financialItemForMainAmount, $financialItemForTax] as $financialItem) {
$entityFinancialTrxn = \Civi\Api4\EntityFinancialTrxn::get(FALSE)
->addWhere('entity_id', '=', $financialItem['id'])
->addWhere('entity_table', '=', \CRM_Financial_BAO_FinancialItem::$_tableName)
->addWhere('entity_table', '=', \CRM_Financial_BAO_FinancialItem::getTableName())
->execute()
->first();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function testExpectedEntityFinancialAccountingEntriesAreCreated($status,
->first();

$lineItemEntityFinancialTrxn = \Civi\Api4\EntityFinancialTrxn::get(FALSE)
->addWhere('entity_table', '=', CRM_Financial_BAO_FinancialItem::$_tableName)
->addWhere('entity_table', '=', CRM_Financial_BAO_FinancialItem::getTableName())
->addWhere('financial_trxn_id', '=', $entityFinancialTrxn['financial_trxn_id'])
->execute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function testExpectedEntityFinancialAccountingEntriesAreCreatedForReversa
->first();

$lineItemEntityFinancialTrxn = \Civi\Api4\EntityFinancialTrxn::get(FALSE)
->addWhere('entity_table', '=', CRM_Financial_BAO_FinancialItem::$_tableName)
->addWhere('entity_table', '=', CRM_Financial_BAO_FinancialItem::getTableName())
->addWhere('financial_trxn_id', '=', $entityFinancialTrxn['financial_trxn_id'])
->execute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AdditionalPaymentButtonTest extends BaseHeadlessTest {

private $additionalPaymentForm;

public function setUp() {
public function setUp(): void {
$formController = new CRM_Core_Controller();
$this->additionalPaymentForm = new CRM_Contribute_Form_AdditionalPayment();
$this->additionalPaymentForm->controller = $formController;
Expand All @@ -23,6 +23,7 @@ public function setUp() {
public function testSubmitRefundButtonLinkAddedToAdditionalPaymentForm() {
$contact = ContactFabricator::fabricate();
$paymentProcessor = PaymentProcessorFabricator::fabricate([
'name' => "Dummy",
'payment_processor_type_id' => "Dummy",
'financial_account_id' => "Payment Processor Account",
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private function submitForm($formValues) {
$form->_submitValues = $formValues;
$form->_action = \CRM_Core_Action::ADD;

$form->set('BAOName', 'CRM_Financeextras_BAO_BatchOwnerOrganisation');
$form->buildForm();
$form->loadValues($formValues);
$form->validate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ContributionValidatorTest extends BaseHeadlessTest {

private $memberDuesFinancialTypeId;

public function setUp() {
public function setUp(): void {
parent::setUp();

$this->donationFinancialTypeId = civicrm_api3('FinancialType', 'getvalue', [
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/Civi/Financeextras/Payment/RefundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class RefundTest extends BaseHeadlessTest {
public function testIsEligibleForRefund() {
$contact = ContactFabricator::fabricate();
$paymentProcessor = PaymentProcessorFabricator::fabricate([
'name' => "Dummy",
'payment_processor_type_id' => "Dummy",
'financial_account_id' => "Payment Processor Account",
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function testGetRefundProcessorIDs() {

private function fabricateDummyProcessor() {
return PaymentProcessorFabricator::fabricate([
'name' => "Dummy",
'payment_processor_type_id' => "Dummy",
'financial_account_id' => "Payment Processor Account",
]);
Expand Down
7 changes: 6 additions & 1 deletion tests/phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

ini_set('memory_limit', '2G');
ini_set('safe_mode', 0);

define('CIVICRM_CONTAINER_CACHE', 'never');
define('CIVICRM_TEST', 1);
putenv('CIVICRM_UF=' . ($_ENV['CIVICRM_UF'] = 'UnitTests'));

// phpcs:disable
eval(cv('php:boot --level=classloader', 'phpcode'));
eval(cv('php:boot --level=settings', 'phpcode'));
// phpcs:enable
// Allow autoloading of PHPUnit helper classes in this extension.
$loader = new \Composer\Autoload\ClassLoader();
Expand Down

0 comments on commit 99958b2

Please sign in to comment.