Hi all.

We've been testing out Fineract-CN for a while now and encountered an issue
when trying to repay a loan from a teller (using fims).

Tracking down the source of the problem, I've found the following line in
portfolio's log:
Responding with a service error ServiceError{code=404, message='No charge
definition with the identifier repay-principal found.'}

Taking a look at teller and portfolio code, the problem seems to be as
follows:
1. Teller calls portfolioManager.getCostComponentsForAction(), which
returns cost components as expected.
2. Teller then calls portfolio again for every cost component and confirms
the charge definition identifier referenced is real by calling
portfolioManager.getChargeDefinition(). (This was introduced in this commit
<https://github.com/apache/fineract-cn-teller/commit/815b7db174e7e8207ed06e562991c682b391ef77>,
and really doesn't make much sense to me. If teller doesn't trust
getCostComponents then why is it trusting getChargeDefinition?)
3. Portfolio returns 404 when asked for the `repay-principal` charge
definition. This is because since this commit
<https://github.com/apache/fineract-cn-portfolio/commit/8568aa0938faab9ff5d6b74c1823863b0ce8781a>,
ChargeDefinitionRestController no longer deals with all charge definitions,
but only charges that are configurable. (The only configurable definitions
for loans are the fees. Other microservices currently have no way of
accessing the read-only non configurable charge definitions.)
4. Teller is supposed to catch this 404 and handle it gracefully by catching
the NotFoundException
<https://github.com/apache/fineract-cn-teller/blob/c7896d6fce218ddb1ca5a6f8c20a71c04834351e/service/src/main/java/org/apache/fineract/cn/teller/service/internal/service/helper/PortfolioService.java#L81>
and just logging a warning, but for some reason it's catching
org.apache.fineract.cn.office.api.v1.client.NotFoundException
<https://github.com/apache/fineract-cn-teller/blob/c7896d6fce218ddb1ca5a6f8c20a71c04834351e/service/src/main/java/org/apache/fineract/cn/teller/service/internal/service/helper/PortfolioService.java#L35>
instead of org.apache.fineract.cn.api.util.NotFoundException.

So the way I see it there are multiple ways to resolve this:
1. Have portfolio return non configurable charge definitions too.
2. Remove teller's (seemingly pointless) checking of charge definitions.
3. Fix the wrong exception being caught.

I have tested solution 3 and was able to repay a loan successfully. TBH the
right solution is probably to do all of these, but technically any one
would do.

Before submitting any pull requests, I'd like to know if my analysis of the
problem is correct. Has anyone else experienced this problem? Is our
installation misconfigured somehow? or is it just that nobody has actually
tried repaying a loan with the teller (is there a better way)?

Reply via email to