You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fineract.apache.org by "mariiaKraievska (via GitHub)" <gi...@apache.org> on 2026/10/22 16:19:16 UTC
[PR] FINERACT-2938: PL - Introduce "Down payment fee" charge type [fineract]
mariiaKraievska opened a new pull request, #6723:
URL: https://github.com/apache/fineract/pull/6723
## Description
Describe the changes made and why they were made. (Ignore if these details are present on the associated Apache Fineract JIRA ticket.)
## Checklist
Please make sure these boxes are checked before submitting your pull request - thanks!
- [ ] Write the commit message as per [our guidelines](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#pull-requests)
- [ ] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
- [ ] Create/update [unit or integration tests](https://fineract.apache.org/docs/current/#_testing) for verifying the changes made.
- [ ] Follow our [coding conventions](https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions).
- [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
- [ ] [This PR must not be a "code dump"](https://cwiki.apache.org/confluence/display/FINERACT/Pull+Request+Size+Limit). Large changes can be made in a branch, with assistance. Ask for help on the [developer mailing list](https://fineract.apache.org/#contribute).
- [ ] If merging this PR resolves a JIRA issue, I will mark that issue as resolved and set "Fix Version/s" appropriately.
- [ ] I followed the [AI Policy](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#ai-policy).
Your assigned reviewer(s) will follow our [guidelines for code reviews](https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2938: PL - Introduce "Down payment fee" charge type [fineract]
Posted by "mariiaKraievska (via GitHub) via issues" <is...@fineract.apache.org>.
mariiaKraievska commented on code in PR #6723:
URL: https://github.com/apache/fineract/pull/6723#discussion_r4465730316
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java:
##########
@@ -354,6 +360,17 @@ private boolean anyChangeInCriticalFloatingRateLinkedParams(JsonCommand command,
return isChangeFromFloatingToFlatOrViceVersa || isChangeInCriticalFloatingRateParams;
}
+ private void validateDownPaymentCharges(final LoanProduct product) {
Review Comment:
Yes, thank you, I've added this. The charge update now rejects the switch to Down payment if the charge is attached to a product that isn't progressive or has no down payment enabled. It's covered by E2E test C119636.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2938: PL - Introduce "Down payment fee" charge type [fineract]
Posted by "adamsaghy (via GitHub) via issues" <is...@fineract.apache.org>.
adamsaghy merged PR #6723:
URL: https://github.com/apache/fineract/pull/6723
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2938: PL - Introduce "Down payment fee" charge type [fineract]
Posted by "adamsaghy (via GitHub) via issues" <is...@fineract.apache.org>.
adamsaghy commented on PR #6723:
URL: https://github.com/apache/fineract/pull/6723#issuecomment-6632146369
@mariiaKraievska Thanks, I checked the updates: the accrual fix and the charge update validation look good, and the doc note on `PERCENT_OF_AMOUNT` covers point 3.
E2E coverage is enough here, no need to add Feign integration tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2938: PL - Introduce "Down payment fee" charge type [fineract]
Posted by "mariiaKraievska (via GitHub) via issues" <is...@fineract.apache.org>.
mariiaKraievska commented on PR #6723:
URL: https://github.com/apache/fineract/pull/6723#issuecomment-6627181679
> Reviewed against the [FINERACT-2938](https://issues.apache.org/jira/browse/FINERACT-2938) / PS-3478 acceptance criteria. Nearly all of them are covered, and the E2E suite is thorough. One bug, one validation gap and one point to confirm, details inline:
>
> 1. **Bug: double fee accrual when two tranches are disbursed on the same day.** `addChargeAccrual` collects the fees of a down payment period with `DownPaymentFees.dueOn(...)`, which returns every down payment fee on that date. With two same-day down payment periods, each fee is added to the accrual data twice and accrued twice (2 x 10 fees -> 40 accrued instead of 20). The same-day E2E scenario does not run COB, so this is not covered.
> 2. **Gap: a charge already attached to a loan product without down payment can be switched to the Down payment time type through the charge update API.** `validateDownPaymentCharges` only runs on loan product create/update. Loans are still protected by the loan-level check, but the product ends up carrying the fee.
> 3. **To confirm: percentage fees reuse `PERCENT_OF_AMOUNT`** (meaning % of the down payment amount when the time type is Down payment) rather than a new calculation type. The story allows this only as an agreed reuse, so please confirm it was agreed. It will show as "% Amount".
>
> Minor: the story asks for integration tests as well as E2E tests. The E2E scenarios cover the whole testing list, but no Feign integration tests were added.
@adamsaghy Thank you for the review!
1-2. FIxed
3. Confirmed on the ticket: we keep PERCENT_OF_AMOUNT, provided the UI and documentation state that the percentage is based on the down payment amount. I've added the documentation note and left a comment on the UI ticket.
About the integration tests: the E2E scenarios cover the whole testing list, but I haven't added Feign tests. Would E2E coverage be enough here, or would you like me to add them as well?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2938: PL - Introduce "Down payment fee" charge type [fineract]
Posted by "mariiaKraievska (via GitHub) via issues" <is...@fineract.apache.org>.
mariiaKraievska commented on code in PR #6723:
URL: https://github.com/apache/fineract/pull/6723#discussion_r4465713058
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualsProcessingServiceImpl.java:
##########
@@ -628,9 +633,16 @@ private void addChargeAccrual(@NonNull final Loan loan, @NonNull final LocalDate
@NonNull final AccrualPeriodsData accrualPeriods) {
final AccrualPeriodData period = accrualPeriods.getPeriodByInstallmentNumber(installment.getInstallmentNumber());
final LocalDate dueDate = installment.getDueDate();
- final Collection<LoanCharge> loanCharges = loan
- .getLoanCharges(lc -> !lc.isDueAtDisbursement() && (lc.isInstalmentFee() ? !DateUtils.isBefore(tillDate, dueDate)
- : isChargeDue(lc, tillDate, chargeOnDueDate, realTimeChargeAccrual, installment, period.isFirstPeriod())));
+ final Collection<LoanCharge> loanCharges;
+ if (installment.isDownPayment()) {
+ // DOWN_PAYMENT fees live on the DP period; match by due date only for this installment.
+ loanCharges = DateUtils.isAfter(dueDate, tillDate) ? List.of() : DownPaymentFees.dueOn(loan.getLoanCharges(), dueDate);
Review Comment:
Thank you! Fixed: it now uses DownPaymentFees.ofPeriod, as you suggested. I also added a COB step to the same-day scenario, and it checks that the accrual is 20 and the journal entries are correct.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2938: PL - Introduce "Down payment fee" charge type [fineract]
Posted by "adamsaghy (via GitHub) via issues" <is...@fineract.apache.org>.
adamsaghy commented on code in PR #6723:
URL: https://github.com/apache/fineract/pull/6723#discussion_r4455750917
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAccrualsProcessingServiceImpl.java:
##########
@@ -628,9 +633,16 @@ private void addChargeAccrual(@NonNull final Loan loan, @NonNull final LocalDate
@NonNull final AccrualPeriodsData accrualPeriods) {
final AccrualPeriodData period = accrualPeriods.getPeriodByInstallmentNumber(installment.getInstallmentNumber());
final LocalDate dueDate = installment.getDueDate();
- final Collection<LoanCharge> loanCharges = loan
- .getLoanCharges(lc -> !lc.isDueAtDisbursement() && (lc.isInstalmentFee() ? !DateUtils.isBefore(tillDate, dueDate)
- : isChargeDue(lc, tillDate, chargeOnDueDate, realTimeChargeAccrual, installment, period.isFirstPeriod())));
+ final Collection<LoanCharge> loanCharges;
+ if (installment.isDownPayment()) {
+ // DOWN_PAYMENT fees live on the DP period; match by due date only for this installment.
+ loanCharges = DateUtils.isAfter(dueDate, tillDate) ? List.of() : DownPaymentFees.dueOn(loan.getLoanCharges(), dueDate);
Review Comment:
`dueOn` returns every down payment fee on this date, not only the fees of this down payment period. With two tranches disbursed on the same day there are two down payment installments on that date, so each fee is added to the accrual data once per installment. `addPaidByMappings` and the period fee totals sum those entries without removing duplicates, so the fee is accrued twice.
Suggest `DownPaymentFees.ofPeriod(loan.getLoanCharges(), installment, loan.getRepaymentScheduleInstallments())`, as the schedule wrapper and allocation already do. Please also add a COB step to the "each tranche disbursed on the same day gets its own down payment fee" scenario.
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java:
##########
@@ -354,6 +360,17 @@ private boolean anyChangeInCriticalFloatingRateLinkedParams(JsonCommand command,
return isChangeFromFloatingToFlatOrViceVersa || isChangeInCriticalFloatingRateParams;
}
+ private void validateDownPaymentCharges(final LoanProduct product) {
Review Comment:
This only runs on loan product create/update. A charge already attached to a product without down payment can still be switched to `DOWN_PAYMENT` through `PUT /charges/{id}`, because `ChargeWritePlatformServiceJpaRepositoryImpl.updateCharge` doesn't check the products it is attached to. Should the charge update reject that too?
##########
fineract-charge/src/main/java/org/apache/fineract/portfolio/charge/domain/ChargeCalculationType.java:
##########
@@ -92,6 +92,10 @@ public static Object[] validValuesForTrancheDisbursement() {
return new Integer[] { ChargeCalculationType.FLAT.getValue(), ChargeCalculationType.PERCENT_OF_DISBURSEMENT_AMOUNT.getValue() };
}
+ public static Object[] validValuesForDownPayment() {
Review Comment:
Reusing `PERCENT_OF_AMOUNT` as "% of the down payment amount": the story allows this only as an agreed reuse of an existing calculation type. Was it agreed? Clients will see it labelled "% Amount".
##########
fineract-charge/src/main/java/org/apache/fineract/portfolio/charge/domain/ChargeCalculationType.java:
##########
@@ -92,6 +92,10 @@ public static Object[] validValuesForTrancheDisbursement() {
return new Integer[] { ChargeCalculationType.FLAT.getValue(), ChargeCalculationType.PERCENT_OF_DISBURSEMENT_AMOUNT.getValue() };
}
+ public static Object[] validValuesForDownPayment() {
Review Comment:
Reusing `PERCENT_OF_AMOUNT` as "% of the down payment amount": the story allows this only as an agreed reuse of an existing calculation type. Was it agreed? Clients will see it labelled "% Amount".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2938: PL - Introduce "Down payment fee" charge type [fineract]
Posted by "mariiaKraievska (via GitHub) via issues" <is...@fineract.apache.org>.
mariiaKraievska commented on PR #6723:
URL: https://github.com/apache/fineract/pull/6723#issuecomment-6603194960
> Hi @mariiaKraievska, thanks for the PR. It's a big one but the test coverage is solid: the `DownPaymentFees` unit tests, `LoanDisbursementServiceTest` and the e2e feature cover the same-day tranche cases nicely.
>
> A few things before this can go in:
>
> * `regression-safety` is red, and it's caused by this PR. Instance #1 runs the PR's e2e runner against the baseline backend. The global initializer now creates two charges with `chargeTimeType=17`, which baseline rejects (`chargeTimeType must be one of [ 1, 2, 8, 9, 12 ]`), so the whole run dies in the initializer. Can we create the down payment charges in the feature's own steps instead of in `ChargeGlobalInitializerStep`? That keeps the global data compatible with the previous version.
> * Liquibase numbering: `0276` is claimed by #6739 (`0276_add_payment_detail_to_share_account_transactions.xml`) and #6286 (`0276_add_unique_constraint_tax_component_and_group_name.xml`) as well. #6766 and #6792 carry the same file because they're stacked on this one, so they're fine. Whoever merges second has to renumber, so pls keep an eye on it.
> * A couple of questions inline about the FK and the business events.
>
> Thanks.
>
> ### fineract-e2e-tests-runner/src/test/java/org/apache/fineract/test/initializer/global/ChargeGlobalInitializerStep.java:182
> ```java
> + () -> TestContext.INSTANCE.set(TestContextKey.CHARGE_FOR_LOAN_DOWN_PAYMENT_FEE_CREATE_RESPONSE,
> + createChargeIfNotExists(charges, CHARGE_APPLIES_TO_LOAN, ChargeProductType.LOAN_DOWN_PAYMENT_FEE.getName(),
> + CHARGE_TIME_TYPE_DOWN_PAYMENT, CHARGE_CALCULATION_TYPE_FLAT, CHARGE_AMOUNT_DOWN_PAYMENT_FLAT, true, false)),
> ```
>
> > This is what breaks `regression-safety` Instance #1. The baseline backend doesn't know time type 17, so the initializer fails before any scenario runs. Let's create these charges lazily from the `LoanChargesDownPayment` feature steps.
>
> ### fineract-provider/src/main/resources/db/changelog/tenant/parts/0276_add_disbursement_detail_to_loan_charge.xml:72
> ```
> + <addForeignKeyConstraint baseColumnNames="loan_disbursement_detail_id" baseTableName="m_loan_charge"
> + constraintName="FK_m_loan_charge_m_loan_disbursement_detail" deferrable="false"
> + initiallyDeferred="false" onDelete="RESTRICT" onUpdate="RESTRICT" referencedColumnNames="id"
> ```
>
> > With `RESTRICT` here, what happens in `closeDisbursements` (write-off / close of a multi-disbursal loan with undisbursed tranches)? `loan.removeDisbursementDetail()` orphan-removes the undisbursed tranches, but their down payment fees are still on the loan and still point at them. I'd expect a constraint violation there, or at best active fees left with no down payment period. Same question for `clearDisbursementDetails()` in `LoanAssemblerImpl`. Can we cover the close-with-undisbursed-tranche case in a test?
> > Minor: the license header is in the file twice (lines 4 and 24). Also this is the `0276` clash mentioned above.
>
> ### fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanDisbursementService.java:415
> ```java
> + if (fee == null) {
> + createDownPaymentFee(loan, chargeDefinition, tranche, dueDate);
> + } else {
> + notifyLoanAddCharge(fee);
> + }
> ```
>
> > Doesn't this raise `LoanAddChargeBusinessEvent` twice for the same charge? Take a tranche added through `PUT /loans/{id}/disbursements`, or through a modify application that doesn't resend the charges. `addDownPaymentFeesForTranche` -> `createDownPaymentFee` already fires the event when the fee is created. Then on disbursement of that tranche, `ensureDownPaymentFees` finds the fee and fires it again. Undo disbursal + re-disburse looks like the same story. Event consumers will see two "charge added" events for one charge. I think we should only notify for fees that haven't raised it yet (the ones that came in with the application). What do you think?
>
> ### fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanCharge.java:269
> ```java
> + @SuppressWarnings("ReferenceEquality")
> + public boolean isDownPaymentFeeOf(final LoanDisbursementDetails tranche) {
> + return isDueAtDownPayment() && tranche != null && this.disbursementDetail == tranche;
> + }
> ```
>
> > I'm not convinced relying on Hibernate instance identity is a safe long-term choice. It only holds while the fee and `Loan.disbursementDetails` were loaded in the same persistence context, and someone making the `@ManyToOne` lazy later (it's eager now only because of this) silently breaks the pairing. Can we compare by id when both sides have one, and only fall back to identity for not-yet-persisted tranches? Not blocking, just want to hear your take.
>
> ### fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanChargeAssembler.java:209
> ```java
> if (ChargeTimeType.TRANCHE_DISBURSEMENT.getValue().equals(chargeDefinition.getChargeTimeType())) {
> + final ExternalId chargeExternalId = externalIdFactory.create(externalIdStr);
> ```
>
> > Bugfix? I assume this is because all tranche disbursement charges of one charge entry shared the same generated external id. Fine to keep, but it isn't related to the down payment fee. Pls mention it in the commit message / JIRA at least.
Thanks, all addressed.
1. **regression-safety**: the down payment charges and the product that uses them moved from the global initializers to an idempotent `Background` step in `LoanChargesDownPayment.feature`.
2. **Liquibase**: renumbered to `0278`
3. **FK / `closeDisbursements`**: `removeDisbursementDetail()` removes nothing (`removeIf` on a filtered copy), so no FK violation. The real gap was the fee of an undisbursed tranche, which got written off. Close/write-off now deactivate those fees (e2e added). `clearDisbursementDetails()` now removes the fees of the cleared tranches. Duplicate license header removed.
4. **Events**: one charge event per command that changes the fee (Add / Update / Delete, fees compared by id before and after), so no duplicate Add.
5. **`isDownPaymentFeeOf`**: compares ids, identity only for unsaved tranches.
6. **External id**: yes, an unrelated fix (`m_loan_charge.external_id` is unique, tranche charges shared one generated id). Mentioned it in the PR description under “Changes outside the feature”.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org