Skip to content

Commit

Permalink
Merge f049983 into feature/238
Browse files Browse the repository at this point in the history
  • Loading branch information
salesforce-org-metaci[bot] authored Dec 7, 2022
2 parents 9eb5995 + f049983 commit 96fe86d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 3 deletions.
11 changes: 8 additions & 3 deletions force-app/main/default/classes/ALLO_Allocations_TDTM.cls
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ public class ALLO_Allocations_TDTM extends TDTM_Runnable {
fillMapWrapper(pmts);

paymentAmountCurrencyChange(pmts);
//paymentAmountCurrencyChange(listPmtsForProcessing);
}
}

Expand All @@ -299,7 +298,7 @@ public class ALLO_Allocations_TDTM extends TDTM_Runnable {
List<npe01__OppPayment__c> refunds = new List<npe01__OppPayment__c>();
List<npe01__OppPayment__c> oldRefunds = new List<npe01__OppPayment__c>();
for (Integer i = 0; i < newList.size(); i++) {
if (newList[i].npe01__Payment_Amount__c < 0 && String.isBlank(newList[i].Elevate_Payment_ID__c)) {
if (newList[i].npe01__Payment_Amount__c < 0 && String.isBlank(newList[i].Elevate_Payment_ID__c) && hasRefundDebitType(newList[i])) {
refunds.add(newList[i]);
if ( oldList != null) {
oldRefunds.add(oldList[i]);
Expand Down Expand Up @@ -327,6 +326,11 @@ public class ALLO_Allocations_TDTM extends TDTM_Runnable {
}
}

private Boolean hasRefundDebitType (npe01__OppPayment__c payment) {
return (payment.DebitType__c == PMT_RefundService.PARTIAL_REFUND
|| payment.DebitType__c == PMT_RefundService.FULL_REFUND);
}

/*******************************************************************************************************
* @description Allocations before trigger handler on GAU Allocation. Validates allocation data per
* object and per parent object to avoid badly created allocations, exceeding opportunity amount,
Expand Down Expand Up @@ -842,9 +846,10 @@ public class ALLO_Allocations_TDTM extends TDTM_Runnable {
}
}
//if the Opportunity amount has decreased, we run the risk of allocations exceeding the total opportunity amount
if (oppWrap.totalAmount > oppWrap.parentAmount)
if (oppWrap.totalAmount > oppWrap.parentAmount) {
//using addError here because we want to block opportunity update, display the error inline, and block the DML of updating all the related allocations
opp.Amount.addError(Label.alloExceedsOppAmount);
}
}
//if we have no allocations for this opportunity, defaults are enabled, and the opportunity has an amount, make a default allocation
} else if (settings.Default_Allocations_Enabled__c && opp.Amount != null) {
Expand Down
98 changes: 98 additions & 0 deletions force-app/main/default/classes/ALLO_Allocations_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,104 @@ private with sharing class ALLO_Allocations_TEST {

}

/*******************************************************************************************************
* @description When working with negative and positive Payments:
* A mixture of positive and negative payments should be successfully inserted
* This test was created to ensure we are not breaking Accounting Subledger functionality
********************************************************************************************************/
static testMethod void pmtsWithPositiveAndNegativeAmounts() {
Date todaysDate = System.today();
Date tomorrowsDate = System.today().addDays(1);
Date todayPlusOneMonthsDate = System.today().addMonths(1);
Date todayPlusTwoMonthsDate = System.today().addMonths(2);
Date todayPlusThreeMonthsDate = System.today().addMonths(3);

General_Accounting_Unit__c defaultGau = new General_Accounting_Unit__c(Name='default GAU');
insert defaultGau;

setupSettings(new Allocations_Settings__c(
Payment_Allocations_Enabled__c = true,
Default_Allocations_Enabled__c = true,
Default__c = defaultGau.Id));

Account acc = new Account(Name='Account-pmtAmountChange');
insert acc;

List<General_Accounting_Unit__c> gaus = UTIL_UnitTestData_TEST.createGAUs(4);
insert gaus;

Opportunity opp = new Opportunity(Name='Opp-pmtAmountChange', Amount = 1000, AccountID=acc.Id, CloseDate=System.today(), StageName=UTIL_UnitTestData_TEST.getOpenStage(), npe01__Do_Not_Automatically_Create_Payment__c=true);
insert opp;

//Create Opportunity Allocation Defaults
List<Allocation__c> oppAllocations = new List<Allocation__c>();
Allocation__c opp1Allo1 = new Allocation__c(General_Accounting_Unit__c = gaus[0].Id,
Amount__c = 200, //20%
Opportunity__c = opp.Id);
Allocation__c opp1Allo2 = new Allocation__c(General_Accounting_Unit__c = gaus[1].Id,
Amount__c = 800, //80%
Opportunity__c = opp.Id);

oppAllocations.add(opp1Allo1);
oppAllocations.add(opp1Allo2);

insert oppAllocations;

List<npe01__OppPayment__c> payments = new List<npe01__OppPayment__c>();
npe01__OppPayment__c p1 = new npe01__OppPayment__c(npe01__Opportunity__c = opp.Id,
npe01__Scheduled_Date__c = todaysDate, npe01__Payment_Amount__c = 400);
npe01__OppPayment__c p2 = new npe01__OppPayment__c(npe01__Opportunity__c = opp.Id,
npe01__Scheduled_Date__c = todayPlusOneMonthsDate,
npe01__Payment_Amount__c = 600);
payments.add(p1);
payments.add(p2);

insert payments;

opp.StageName = UTIL_UnitTestData_TEST.getClosedWonStage();
update opp;

payments = new List<npe01__OppPayment__c>();

//Now Insert a mixture of payments
p1 = new npe01__OppPayment__c(
npe01__Opportunity__c = opp.Id,
npe01__Payment_Date__c = todaysDate,
npe01__Paid__c = true,
npe01__Payment_Amount__c = 300);
p2 = new npe01__OppPayment__c(
npe01__Opportunity__c = opp.Id,
npe01__Payment_Date__c = todayPlusOneMonthsDate,
npe01__Paid__c = true,
npe01__Payment_Amount__c = -200);
npe01__OppPayment__c p3 = new npe01__OppPayment__c(
npe01__Opportunity__c = opp.Id,
npe01__Payment_Date__c = todayPlusTwoMonthsDate,
npe01__Paid__c = true,
npe01__Payment_Amount__c = 500);
npe01__OppPayment__c p4 = new npe01__OppPayment__c(
npe01__Opportunity__c = opp.Id,
npe01__Payment_Date__c = todayPlusThreeMonthsDate,
npe01__Paid__c = true,
npe01__Payment_Amount__c = -600);

payments.add(p1);
payments.add(p2);
payments.add(p3);
payments.add(p4);

Test.startTest();
insert payments;
Test.stopTest();

List<Allocation__c> queryAllo = getAllocationsOrderByPercent(p1.Id, gaus[0].Id);
System.assertEquals(300 * 0.2, queryAllo[0].Amount__c, 'The allocation amount should be 20% of the Payment');

queryAllo = getAllocationsOrderByPercent(p2.Id, gaus[0].Id);
System.assertEquals(-200 * 0.2, queryAllo[0].Amount__c, 'The allocation amount should be 20% of the Payment');

}

/*******************************************************************************************************
* @description When working with negative amount Payments:
* Updating the amount will adjust the percentage allocations.
Expand Down

0 comments on commit 96fe86d

Please sign in to comment.