Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

FINERACT-2284: Enforce Charge Rounding using Money rounding rules - #5940

Merged
adamsaghy merged 1 commit into
apache:developfrom
Dhanno98:FINERACT-2284/enforce-charge-rounding
Jul 15, 2026
Merged

adamsaghy merged 1 commit into
apache:developfrom
Dhanno98:FINERACT-2284/enforce-charge-rounding

Conversation

@Dhanno98

@Dhanno98 Dhanno98 commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

FINERACT-2284: Enforce charge rounding using Money rounding rules

This PR fixes charge amount handling across Fineract by ensuring that charge values are rounded using the application's configured currency rules before they are persisted or processed.

Previously, several charge flows stored or processed raw BigDecimal values directly. As a result, charge amounts could bypass currency rounding settings such as:

  • digitsAfterDecimal
  • inMultiplesOf

This led to inconsistent behavior between charge calculations and other monetary operations that already rely on Money.

This PR standardizes charge amount handling by using Money for charge rounding across all supported charge types:

  • Loan Charges
  • Savings Account Charges
  • Share Account Charges
  • Client Charges

In addition, if a charge amount rounds to zero after applying currency rules, the charge is no longer persisted or created.

Functional Changes

Loan Charges

  • Applied currency rounding when enforcing minimum and maximum charge caps.
  • Ensured installment fee calculations and charge updates persist rounded values.
  • Prevented zero-value loan charges from being persisted.

Savings Account Charges

  • Applied currency rounding through Money.
  • Prevented persistence of flat charges whose final rounded value is zero.

Share Account Charges

  • Applied currency rounding when deriving charge amounts.
  • Applied currency rounding when updating charge amounts for additional share transactions.
  • Prevented creation of charge transactions for charges whose rounded value is zero.
  • Prevented zero-value activation, purchase, and redemption charge transactions from being generated.

Client Charges

  • Applied currency rounding before charge creation.
  • Prevented persistence of client charges whose rounded value becomes zero after rounding.

API Documentation

Updated Swagger/OpenAPI schemas where required to improve request model documentation and examples.

Why This Change

Fineract already provides currency-specific monetary rules through Money, including support for:

  • Currency precision (digitsAfterDecimal)
  • Rounding increments (inMultiplesOf)

Charges should follow the same monetary rules as all other financial amounts.

By enforcing rounding consistently:

  • Charge calculations become predictable.
  • Persisted charge values match configured currency behavior.
  • Zero-value charges generated by rounding are avoided.
  • Charge processing remains consistent across all portfolio modules.

Test Coverage

Added integration test coverage for all supported charge types:

  • LoanChargeRoundingTest
  • SavingsAccountChargeRoundingTest
  • ShareAccountChargeRoundingTest
  • ClientChargeRoundingTest

The tests verify:

  • Charge amounts respect configured currency rounding rules.
  • inMultiplesOf and digitsAfterDecimal rounding is enforced.
  • Rounded values are persisted correctly.
  • Charges that round to zero are not created or persisted.

Verification

Executed the complete charge rounding integration test suite successfully.

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Write the commit message as per our guidelines
  • 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 for verifying the changes made.
  • Follow our 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". Large changes can be made in a branch, with assistance. Ask for help on the developer mailing list.

Your assigned reviewer(s) will follow our guidelines for code reviews.

@Dhanno98
Dhanno98 force-pushed the FINERACT-2284/enforce-charge-rounding branch 2 times, most recently from 38bd72e to 8009f8c Compare June 6, 2026 18:06

@adamsaghy adamsaghy left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stopped review at half time.. I dont like this approach, neither i think it is correct.

The introduced 0 amount handling is incorrect. 0 amount is incorrect outcome and charge cannot be created with this value, but nevertheless, we cannot accept the charge creation action and after not create the charge. This is incorrect and unwanted behaviour:

  • Add proper validation (first thing to do)
  • Calculate the amount, if it is incorrect (like 0 amount) -> Raise error and explain the issue!
  • Remove the unnecessary flags and checks... it makes the code hard to read and maintained...
  • Remove the unrelated changes, the PR should focus on 1 thing only!

@Dhanno98

Copy link
Copy Markdown
Contributor Author

@adamsaghy Thanks for your suggestions! I am working on the fix.

@Dhanno98

Copy link
Copy Markdown
Contributor Author

Hi @adamsaghy,
I have updated the charge attachment flows locally to reject charges whose calculated amount becomes 0 after applying account currency rounding rules, instead of returning silently.

I have a question regarding future charges such as Savings Account Percentage of Withdrawal Charges and Share Account Redeem Charges.

In these cases, the charge is attached successfully first and the amount is calculated only when the business transaction occurs. If the calculated charge amount becomes 0 after rounding, what is the expected behavior:

  1. Reject the business transaction (withdrawal/redeem) with a validation error.
  2. Allow the transaction but skip creating/applying the charge similar to silent return.
  3. Keep the current behavior and allow a 0 value charge result.

Could you please clarify the expected behavior for these future-charge scenarios so I can align the implementation consistently across Savings and Shares?

Thank you!

@adamsaghy

Copy link
Copy Markdown
Contributor

Hi @adamsaghy, I have updated the charge attachment flows locally to reject charges whose calculated amount becomes 0 after applying account currency rounding rules, instead of returning silently.

I have a question regarding future charges such as Savings Account Percentage of Withdrawal Charges and Share Account Redeem Charges.

In these cases, the charge is attached successfully first and the amount is calculated only when the business transaction occurs. If the calculated charge amount becomes 0 after rounding, what is the expected behavior:

  1. Reject the business transaction (withdrawal/redeem) with a validation error.
  2. Allow the transaction but skip creating/applying the charge similar to silent return.
  3. Keep the current behavior and allow a 0 value charge result.

Could you please clarify the expected behavior for these future-charge scenarios so I can align the implementation consistently across Savings and Shares?

Thank you!

@bharathc27 fyi

@Dhanno98 let me review

@adamsaghy

Copy link
Copy Markdown
Contributor

Hi @adamsaghy, I have updated the charge attachment flows locally to reject charges whose calculated amount becomes 0 after applying account currency rounding rules, instead of returning silently.

I have a question regarding future charges such as Savings Account Percentage of Withdrawal Charges and Share Account Redeem Charges.

In these cases, the charge is attached successfully first and the amount is calculated only when the business transaction occurs. If the calculated charge amount becomes 0 after rounding, what is the expected behavior:

  1. Reject the business transaction (withdrawal/redeem) with a validation error.
  2. Allow the transaction but skip creating/applying the charge similar to silent return.
  3. Keep the current behavior and allow a 0 value charge result.

Could you please clarify the expected behavior for these future-charge scenarios so I can align the implementation consistently across Savings and Shares?

Thank you!

I see no changes, no reply on my questions and concerns.. i have stopped reviewing the PR at half time...

@Dhanno98

Dhanno98 commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @adamsaghy, I have updated the charge attachment flows locally to reject charges whose calculated amount becomes 0 after applying account currency rounding rules, instead of returning silently.
I have a question regarding future charges such as Savings Account Percentage of Withdrawal Charges and Share Account Redeem Charges.
In these cases, the charge is attached successfully first and the amount is calculated only when the business transaction occurs. If the calculated charge amount becomes 0 after rounding, what is the expected behavior:

  1. Reject the business transaction (withdrawal/redeem) with a validation error.
  2. Allow the transaction but skip creating/applying the charge similar to silent return.
  3. Keep the current behavior and allow a 0 value charge result.

Could you please clarify the expected behavior for these future-charge scenarios so I can align the implementation consistently across Savings and Shares?
Thank you!

I see no changes, no reply on my questions and concerns.. i have stopped reviewing the PR at half time...

Hi @adamsaghy,

Sorry for the confusion. When I wrote that I had updated the charge attachment flows locally, I meant that the changes were only completed in my local branch and had not yet been pushed or amended into the PR.

My intention was to first finish addressing all of your review comments, validate everything thoroughly, and then push a single updated commit together with replies to each review comment. Because of that, I had not yet responded individually to the review feedback.

I realize now that my comment made it sound like the PR had already been updated, which was not the case. Sorry for causing you to spend time reopening the review.

I am currently working through all of the review comments and will push the updated changes together with responses shortly.

Regarding the future-charge scenarios, that question was meant as a design clarification while implementing the remaining changes so I can keep the behavior consistent across Savings and Shares. This is the only thing that I need to understand and resolve and then I will ammend the commit.

Thank you for your patience and for the detailed review feedback.

@adamsaghy

Copy link
Copy Markdown
Contributor

Hi @adamsaghy, I have updated the charge attachment flows locally to reject charges whose calculated amount becomes 0 after applying account currency rounding rules, instead of returning silently.
I have a question regarding future charges such as Savings Account Percentage of Withdrawal Charges and Share Account Redeem Charges.
In these cases, the charge is attached successfully first and the amount is calculated only when the business transaction occurs. If the calculated charge amount becomes 0 after rounding, what is the expected behavior:

  1. Reject the business transaction (withdrawal/redeem) with a validation error.
  2. Allow the transaction but skip creating/applying the charge similar to silent return.
  3. Keep the current behavior and allow a 0 value charge result.

Could you please clarify the expected behavior for these future-charge scenarios so I can align the implementation consistently across Savings and Shares?
Thank you!

I see no changes, no reply on my questions and concerns.. i have stopped reviewing the PR at half time...

Hi @adamsaghy,

Sorry for the confusion. When I wrote that I had updated the charge attachment flows locally, I meant that the changes were only completed in my local branch and had not yet been pushed or amended into the PR.

My intention was to first finish addressing all of your review comments, validate everything thoroughly, and then push a single updated commit together with replies to each review comment. Because of that, I had not yet responded individually to the review feedback.

I realize now that my comment made it sound like the PR had already been updated, which was not the case. Sorry for causing you to spend time reopening the review.

I am currently working through all of the review comments and will push the updated changes together with responses shortly.

Regarding the future-charge scenarios, that question was meant as a design clarification while implementing the remaining changes so I can keep the behavior consistent across Savings and Shares. This is the only thing that I need to understand and resolve and then I will ammend the commit.

Thank you for your patience and for the detailed review feedback.

Thank you for the clarification ;)

Regarding zero amount: Lets use option 1 Reject the business transaction (withdrawal/redeem) with a validation error.

@Dhanno98

Copy link
Copy Markdown
Contributor Author

Hi @adamsaghy, I have updated the charge attachment flows locally to reject charges whose calculated amount becomes 0 after applying account currency rounding rules, instead of returning silently.
I have a question regarding future charges such as Savings Account Percentage of Withdrawal Charges and Share Account Redeem Charges.
In these cases, the charge is attached successfully first and the amount is calculated only when the business transaction occurs. If the calculated charge amount becomes 0 after rounding, what is the expected behavior:

  1. Reject the business transaction (withdrawal/redeem) with a validation error.
  2. Allow the transaction but skip creating/applying the charge similar to silent return.
  3. Keep the current behavior and allow a 0 value charge result.

Could you please clarify the expected behavior for these future-charge scenarios so I can align the implementation consistently across Savings and Shares?
Thank you!

I see no changes, no reply on my questions and concerns.. i have stopped reviewing the PR at half time...

Hi @adamsaghy,
Sorry for the confusion. When I wrote that I had updated the charge attachment flows locally, I meant that the changes were only completed in my local branch and had not yet been pushed or amended into the PR.
My intention was to first finish addressing all of your review comments, validate everything thoroughly, and then push a single updated commit together with replies to each review comment. Because of that, I had not yet responded individually to the review feedback.
I realize now that my comment made it sound like the PR had already been updated, which was not the case. Sorry for causing you to spend time reopening the review.
I am currently working through all of the review comments and will push the updated changes together with responses shortly.
Regarding the future-charge scenarios, that question was meant as a design clarification while implementing the remaining changes so I can keep the behavior consistent across Savings and Shares. This is the only thing that I need to understand and resolve and then I will ammend the commit.
Thank you for your patience and for the detailed review feedback.

Thank you for the clarification ;)

Regarding zero amount: Lets use option 1 Reject the business transaction (withdrawal/redeem) with a validation error.

Thank you for the clarification.

Just to confirm the expected behavior for percentage-based future charges:

Suppose a Savings Account has a "Percentage of Withdrawal" charge configured as 0.5%.

When the charge is attached to the account, the percentage value (0.5%) is stored successfully because the actual charge amount is not yet known.

Later, if a withdrawal of 100 is performed and the account currency uses 0 decimal places (for example JPY), the calculated charge amount would be:

0.5% × 100 = 0.5

which would then round to 0 according to the currency rounding rules.

With option 1, my understanding is that the withdrawal transaction itself should be rejected with a validation error because the calculated charge amount becomes zero after rounding.

Is that the intended behavior, even though the withdrawal amount itself is valid and only the associated charge rounds to zero?

I just want to confirm this edge case before implementing the validation in the future-charge flows.

@adamsaghy

Copy link
Copy Markdown
Contributor

Hi @adamsaghy, I have updated the charge attachment flows locally to reject charges whose calculated amount becomes 0 after applying account currency rounding rules, instead of returning silently.
I have a question regarding future charges such as Savings Account Percentage of Withdrawal Charges and Share Account Redeem Charges.
In these cases, the charge is attached successfully first and the amount is calculated only when the business transaction occurs. If the calculated charge amount becomes 0 after rounding, what is the expected behavior:

  1. Reject the business transaction (withdrawal/redeem) with a validation error.
  2. Allow the transaction but skip creating/applying the charge similar to silent return.
  3. Keep the current behavior and allow a 0 value charge result.

Could you please clarify the expected behavior for these future-charge scenarios so I can align the implementation consistently across Savings and Shares?
Thank you!

I see no changes, no reply on my questions and concerns.. i have stopped reviewing the PR at half time...

Hi @adamsaghy,
Sorry for the confusion. When I wrote that I had updated the charge attachment flows locally, I meant that the changes were only completed in my local branch and had not yet been pushed or amended into the PR.
My intention was to first finish addressing all of your review comments, validate everything thoroughly, and then push a single updated commit together with replies to each review comment. Because of that, I had not yet responded individually to the review feedback.
I realize now that my comment made it sound like the PR had already been updated, which was not the case. Sorry for causing you to spend time reopening the review.
I am currently working through all of the review comments and will push the updated changes together with responses shortly.
Regarding the future-charge scenarios, that question was meant as a design clarification while implementing the remaining changes so I can keep the behavior consistent across Savings and Shares. This is the only thing that I need to understand and resolve and then I will ammend the commit.
Thank you for your patience and for the detailed review feedback.

Thank you for the clarification ;)
Regarding zero amount: Lets use option 1 Reject the business transaction (withdrawal/redeem) with a validation error.

Thank you for the clarification.

Just to confirm the expected behavior for percentage-based future charges:

Suppose a Savings Account has a "Percentage of Withdrawal" charge configured as 0.5%.

When the charge is attached to the account, the percentage value (0.5%) is stored successfully because the actual charge amount is not yet known.

Later, if a withdrawal of 100 is performed and the account currency uses 0 decimal places (for example JPY), the calculated charge amount would be:

0.5% × 100 = 0.5

which would then round to 0 according to the currency rounding rules.

With option 1, my understanding is that the withdrawal transaction itself should be rejected with a validation error because the calculated charge amount becomes zero after rounding.

Is that the intended behavior, even though the withdrawal amount itself is valid and only the associated charge rounds to zero?

I just want to confirm this edge case before implementing the validation in the future-charge flows.

With this use case, it’s not as straightforward as it seems. I might have been overly strict here. Just because the charge is too small, we still want to allow the withdrawal. So, if the calculated charge is zero, we simply ignore it and don’t create it.

@bharathc27, what are your thoughts on this?

@bharathcgowda

bharathcgowda commented Jun 18, 2026 •

Copy link
Copy Markdown

@adamsaghy @Dhanno98 In any entity and scenario if the calculated charge amount is zero (after rounding) that charge should not be created.
In your latest example, "Allow the transaction but skip creating/applying the charge, similar to silent return," sounds right to me.
Any transactions associated with charges should not be affected. Hence withdraw transaction happens with no charge posting in the above example

@Dhanno98

Copy link
Copy Markdown
Contributor Author

@adamsaghy @Dhanno98 In any entity and scenario if the calculated charge amount is zero (after rounding) that charge should not be created. In your latest example, "Allow the transaction but skip creating/applying the charge, similar to silent return," sounds right to me. Any transactions associated with charges should not be affected. Hence withdraw transaction happens with no charge posting in the above example

Hi @bharathcgowda @adamsaghy
One follow-up question regarding future charges.

For percentage-based future charges (withdrawal/redeem), I understand that the charge definition should be stored and, when the calculated amount rounds to zero, the transaction should continue and the charge should simply not be applied.

For flat future charges (for example a Shares Flat Redeem Charge of 0.5 in a currency with 0 decimal places), the rounded charge amount is known to be zero already at attachment time and can never become non-zero later.

Currently, the existing behavior appears to allow such a Flat Redeem Charge to be attached to the share account without any validation. During the attachment flow, the configured charge amount (0.5 in this example) is stored as-is and no currency rounding is performed. The amount is only passed through Money.of() later during the redeem-shares flow, where the calculated charge amount becomes 0 and is effectively not applied.

For this scenario, what should be the expected behavior:

  1. Keep the current behavior: allow the charge to be attached as-is and, during redemption, simply ignore it if the rounded amount becomes 0, similar to Percentage of Redeem Charges.

  2. Round the flat redeem charge during attachment and reject it if the amount rounds to 0 by throwing a validation exception in the charge attachment flow itself.

@adamsaghy

Copy link
Copy Markdown
Contributor

@adamsaghy @Dhanno98 In any entity and scenario if the calculated charge amount is zero (after rounding) that charge should not be created. In your latest example, "Allow the transaction but skip creating/applying the charge, similar to silent return," sounds right to me. Any transactions associated with charges should not be affected. Hence withdraw transaction happens with no charge posting in the above example

Hi @bharathcgowda @adamsaghy One follow-up question regarding future charges.

For percentage-based future charges (withdrawal/redeem), I understand that the charge definition should be stored and, when the calculated amount rounds to zero, the transaction should continue and the charge should simply not be applied.

For flat future charges (for example a Shares Flat Redeem Charge of 0.5 in a currency with 0 decimal places), the rounded charge amount is known to be zero already at attachment time and can never become non-zero later.

Currently, the existing behavior appears to allow such a Flat Redeem Charge to be attached to the share account without any validation. During the attachment flow, the configured charge amount (0.5 in this example) is stored as-is and no currency rounding is performed. The amount is only passed through Money.of() later during the redeem-shares flow, where the calculated charge amount becomes 0 and is effectively not applied.

For this scenario, what should be the expected behavior:

  1. Keep the current behavior: allow the charge to be attached as-is and, during redemption, simply ignore it if the rounded amount becomes 0, similar to Percentage of Redeem Charges.
  2. Round the flat redeem charge during attachment and reject it if the amount rounds to 0 by throwing a validation exception in the charge attachment flow itself.

I dont think we should reject and throw error if charge became 0... @bharathcgowda thoughts?

@Dhanno98
Dhanno98 force-pushed the FINERACT-2284/enforce-charge-rounding branch from 8009f8c to 84f7719 Compare June 22, 2026 17:21
@Dhanno98
Dhanno98 force-pushed the FINERACT-2284/enforce-charge-rounding branch from 84f7719 to 8a82b79 Compare June 23, 2026 06:28
@Dhanno98

Copy link
Copy Markdown
Contributor Author

@adamsaghy @Dhanno98 In any entity and scenario if the calculated charge amount is zero (after rounding) that charge should not be created. In your latest example, "Allow the transaction but skip creating/applying the charge, similar to silent return," sounds right to me. Any transactions associated with charges should not be affected. Hence withdraw transaction happens with no charge posting in the above example

Hi @bharathcgowda @adamsaghy One follow-up question regarding future charges.
For percentage-based future charges (withdrawal/redeem), I understand that the charge definition should be stored and, when the calculated amount rounds to zero, the transaction should continue and the charge should simply not be applied.
For flat future charges (for example a Shares Flat Redeem Charge of 0.5 in a currency with 0 decimal places), the rounded charge amount is known to be zero already at attachment time and can never become non-zero later.
Currently, the existing behavior appears to allow such a Flat Redeem Charge to be attached to the share account without any validation. During the attachment flow, the configured charge amount (0.5 in this example) is stored as-is and no currency rounding is performed. The amount is only passed through Money.of() later during the redeem-shares flow, where the calculated charge amount becomes 0 and is effectively not applied.
For this scenario, what should be the expected behavior:

  1. Keep the current behavior: allow the charge to be attached as-is and, during redemption, simply ignore it if the rounded amount becomes 0, similar to Percentage of Redeem Charges.
  2. Round the flat redeem charge during attachment and reject it if the amount rounds to 0 by throwing a validation exception in the charge attachment flow itself.

I dont think we should reject and throw error if charge became 0... @bharathcgowda thoughts?

Thanks @adamsaghy.

The current implementation in this PR already follows that behavior for Share Redeem Charges and Savings Percentage Withdrawal Charges.

These charges continue to be attached and stored as configured. When they are later applied, the calculated charge amount goes through the existing Money rounding rules and, if the rounded amount becomes 0, the transaction proceeds normally and the charge is simply not applied.

So Share Flat Redeem Charges that eventually round to 0 during the Redeem Shares flow are currently not rejected during attachment.

I've also updated the PR with the latest changes and fixes.

@Dhanno98
Dhanno98 force-pushed the FINERACT-2284/enforce-charge-rounding branch from 8a82b79 to 1bcae1a Compare June 24, 2026 07:00
@adamsaghy

Copy link
Copy Markdown
Contributor

@Dhanno98 Please review the failing checks

@Dhanno98
Dhanno98 force-pushed the FINERACT-2284/enforce-charge-rounding branch from 1bcae1a to e87adeb Compare June 26, 2026 18:56
@Dhanno98

Copy link
Copy Markdown
Contributor Author

@Dhanno98 Please review the failing checks

Hi @adamsaghy ! I investigated the CI failures.

One of the failures (LoanWorkbookPopulatorTest.testLoanWorkbookPopulate) was reproducible locally only when ClientChargeRoundingTest was executed before it.

After tracing the failure, I found that ClientChargeRoundingTest created client charges using UUIDs in the charge name. Those UUIDs contained hyphens, which later became part of workbook named ranges created by LoanWorkbookPopulator, causing the subsequent workbook population test to fail.

I've updated the createFlatClientCharge() to remove the hyphens from the UUID while still keeping the names unique. After this change I verified that:

  • ClientChargeRoundingTest passes.
  • LoanWorkbookPopulatorTest passes even when run immediately after ClientChargeRoundingTest.

I've amended the PR with this fix.

The other CI failure (MariaDB Tests -> Build the image) also seems unrelated to this change. From the logs, it failed with:
java.net.UnknownHostException: registry-1.docker.io: Temporary failure in name resolution
Since the PostgreSQL and MySQL jobs passed, I think this might be a temporary CI/network issue rather than something caused by this PR.

@adamsaghy

Copy link
Copy Markdown
Contributor
  org.apache.fineract.integrationtests.bulkimport.populator.loan.LoanWorkbookPopulatorTest
  
    Test testLoanWorkbookPopulate() FAILED
  
    java.lang.AssertionError: 1 expectation failed.
    Expected status code <200> but was <500>.
        at org.apache.fineract.integrationtests.bulkimport.populator.loan.LoanWorkbookPopulatorTest.testLoanWorkbookPopulate(LoanWorkbookPopulatorTest.java:101)
  
  

@Dhanno98
Dhanno98 force-pushed the FINERACT-2284/enforce-charge-rounding branch 2 times, most recently from c4ef473 to a20e3a5 Compare June 29, 2026 17:31
@Dhanno98

Copy link
Copy Markdown
Contributor Author
  org.apache.fineract.integrationtests.bulkimport.populator.loan.LoanWorkbookPopulatorTest
  
    Test testLoanWorkbookPopulate() FAILED
  
    java.lang.AssertionError: 1 expectation failed.
    Expected status code <200> but was <500>.
        at org.apache.fineract.integrationtests.bulkimport.populator.loan.LoanWorkbookPopulatorTest.testLoanWorkbookPopulate(LoanWorkbookPopulatorTest.java:101)
  
  

I investigated the CI failure further.

Initially, I fixed the issue in ClientChargeRoundingTest because LoanWorkbookPopulatorTest was running immediately after it in the same shard, and that resolved the failure locally.

However, on the next CI run, LoanWorkbookPopulatorTest was scheduled in a different shard and this time it ran after SharesAccountChargeRoundingTest. The same failure occurred again with the same validation error about the generated charge name.

After reproducing this locally by running:

  • SharesAccountChargeRoundingTest → LoanWorkbookPopulatorTest
  • SavingsAccountChargeRoundingTest → LoanWorkbookPopulatorTest
  • LoanChargeRoundingTest → LoanWorkbookPopulatorTest

I found that all three reproduced the same problem.

The root cause is that these tests create charge names using UUID.randomUUID(), which includes hyphens. Those charge names remain in the database, and later LoanWorkbookPopulatorTest creates workbook named ranges from them. Excel named ranges don't allow hyphens, so the workbook generation fails.

I updated all of the newly added charge rounding tests to generate UUIDs without hyphens (UUID.randomUUID().toString().replace("-", "")). After that, I reran all of the above combinations locally, and LoanWorkbookPopulatorTest passed in every case.

Since LoanWorkbookPopulatorTest can be scheduled after any of these tests depending on shard assignment, fixing all of them was necessary rather than only ClientChargeRoundingTest.

@adamsaghy adamsaghy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, I see one real blocker: the PR fixes ShareAccountTransaction.createChargeTransaction() to use the rounded/applied amount, but activation charges still create ShareAccountChargePaidBy with charge.percentageOrAmount() in ShareAccountDataSerializer.

That means for a flat activation charge like 19.8 rounded to 20:
share transaction amount = 20
chargesPaid.amount = 19.8

That is dangerous because share accounting consumes chargesPaid.amount and checks that the charge-payment breakdown totals match the transaction amount. With accounting enabled, this can trip the “charges for shares have broken accounting code” integrity exception.

To be fixed: in the activation charge path, pass the derived amount into ShareAccountChargePaidBy, not charge.percentageOrAmount().

Please also add a test covering activation share charges with accounting enabled, because the current rounding tests appear to use non-accounting share products and won’t catch this.

@Dhanno98

Dhanno98 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Technically, I see one real blocker: the PR fixes ShareAccountTransaction.createChargeTransaction() to use the rounded/applied amount, but activation charges still create ShareAccountChargePaidBy with charge.percentageOrAmount() in ShareAccountDataSerializer.

That means for a flat activation charge like 19.8 rounded to 20: share transaction amount = 20 chargesPaid.amount = 19.8

That is dangerous because share accounting consumes chargesPaid.amount and checks that the charge-payment breakdown totals match the transaction amount. With accounting enabled, this can trip the “charges for shares have broken accounting code” integrity exception.

To be fixed: in the activation charge path, pass the derived amount into ShareAccountChargePaidBy, not charge.percentageOrAmount().

Please also add a test covering activation share charges with accounting enabled, because the current rounding tests appear to use non-accounting share products and won’t catch this.

Thanks for catching that! I'll update the activation charge path to use the derived amount and add an accounting-enabled test.

@Dhanno98

Dhanno98 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Hi @adamsaghy

While implementing the integration test for the accounting-rule-2 share product flow, I noticed that the
POST /products/share endpoint accepts the accounting mapping fields (shareReferenceId, shareSuspenseId, incomeFromFeeAccountId, shareEquityId) when called directly (via Postman), but these fields are missing from ProductsApiResourceSwagger.PostProductsTypeRequest.

Because of that, the generated PostProductsTypeRequest model also doesn't expose these fields, making it impossible to create an accounting-rule-2 share product through the generated Feign client used by the integration tests.

My understanding is that the Swagger request schema is incomplete rather than the backend implementation. My plan is to add these optional request fields to the OpenAPI schema and regenerate the client. Before doing that, I wanted to check whether this is the preferred approach, since it may affect the OpenAPI backward compatibility checks.

@adamsaghy

Copy link
Copy Markdown
Contributor

Hi @adamsaghy

While implementing the integration test for the accounting-rule-2 share product flow, I noticed that the POST /products/share endpoint accepts the accounting mapping fields (shareReferenceId, shareSuspenseId, incomeFromFeeAccountId, shareEquityId) when called directly (via Postman), but these fields are missing from ProductsApiResourceSwagger.PostProductsTypeRequest.

Because of that, the generated PostProductsTypeRequest model also doesn't expose these fields, making it impossible to create an accounting-rule-2 share product through the generated Feign client used by the integration tests.

My understanding is that the Swagger request schema is incomplete rather than the backend implementation. My plan is to add these optional request fields to the OpenAPI schema and regenerate the client. Before doing that, I wanted to check whether this is the preferred approach, since it may affect the OpenAPI backward compatibility checks.

Yes, please. Your understanding is correct. Swagger might be incomplete or incorrect in certain cases. However, the relevant information is always the incoming requests (fields), DTOs, and response DTOs.

@Dhanno98
Dhanno98 force-pushed the FINERACT-2284/enforce-charge-rounding branch 2 times, most recently from 50ef7d5 to 0e46f0c Compare July 3, 2026 15:11
@adamsaghy

Copy link
Copy Markdown
Contributor

@Dhanno98 Please rebase this PR

@Dhanno98
Dhanno98 force-pushed the FINERACT-2284/enforce-charge-rounding branch 2 times, most recently from 6737367 to bbc2558 Compare July 3, 2026 15:31
@Dhanno98

Dhanno98 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Hi @adamsaghy

Sorry about the confusion earlier. While cleaning up the PR I accidentally pushed a couple of unrelated files, so I first fixed that and then noticed your comment about rebasing. The PR has now been rebased onto the latest develop, and the current branch contains only the intended changes.

In addition to the original rounding fix, I made a few related improvements:

1. Fix for the rounded activation charge issue

The actual fix is in ShareAccountDataSerializer.createChargeTransaction(). Previously, ShareAccountChargePaidBy was created using the original charge amount:

new ShareAccountChargePaidBy(chargeTransaction, charge, charge.percentageOrAmount())

It now uses the rounded transaction amount:

new ShareAccountChargePaidBy(chargeTransaction, charge, amount)

This ensures that the persisted ShareAccountChargePaidBy.amount matches the rounded amount used by the transaction.

I also added an integration test, verifyActivationChargeRoundedCorrectlyWithAccountingEnabled(), in ShareAccountChargeRoundingTest which verifies:

  • activation charge rounding,
  • persisted charge amount,
  • accounting journal entries generated for the rounded charge.

To support this test using the generated client, I added the missing accounting account fields to PostProductsTypeRequest and added createEquityAccount() to FeignAccountHelper.

2. Generated client improvements

Since using the generated client for these commands is acceptable, I also exposed the missing request fields in:

  • PostAccountsTypeAccountIdRequest
  • PostClientsClientIdChargesRequest

After regenerating the client, I made use of these generated client requests for:

  • share account activation,
  • share redemption,
  • client charge application.

This makes the integration tests consistent with Fineract client usage instead of RestAssured.

@Dhanno98

Dhanno98 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

I went through the remaining failing CI job (run-api-backward-compatibility) to understand the failure.

From what I observed, the reported breaking changes are due to the generated client schema updates that I made for:

  • PostAccountsTypeAccountIdRequest (to expose the missing request fields required for share account activation/redemption), and
  • PostClientsClientIdChargesRequest (correcting amount to BigDecimal).

I also noticed that the additional fields added to PostProductsTypeRequest for accounting-enabled share product creation are additive and don't seem to be reported by the backward compatibility check.

It looks like the failure is specifically because the OpenAPI contract changed for the existing request models. Could you please let me know how you would like me to proceed?

@Dhanno98
Dhanno98 force-pushed the FINERACT-2284/enforce-charge-rounding branch from bbc2558 to fc80760 Compare July 10, 2026 11:45
@Dhanno98
Dhanno98 force-pushed the FINERACT-2284/enforce-charge-rounding branch from fc80760 to 745ae67 Compare July 10, 2026 11:54
@Dhanno98

Copy link
Copy Markdown
Contributor Author

I have reverted the unrelated Swagger changes so this PR now contains only the changes relevant to charge rounding. I also rebased the branch on the latest develop and the CI checks are now passing.
Please review when you have a moment.

@adamsaghy

Copy link
Copy Markdown
Contributor

I have reverted the unrelated Swagger changes so this PR now contains only the changes relevant to charge rounding. I also rebased the branch on the latest develop and the CI checks are now passing. Please review when you have a moment.

I am postponing to merge this till release of 1.15.0 is not finished

@adamsaghy adamsaghy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adamsaghy
adamsaghy merged commit 0be33be into apache:develop Jul 15, 2026
91 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants