chinmaya samantara created FINERACT-2991:
--------------------------------------------
Summary: Changing a loan product's external ID deletes its
advanced accounting mappings
Key: FINERACT-2991
URL: https://issues.apache.org/jira/browse/FINERACT-2991
Project: Apache Fineract
Issue Type: Bug
Reporter: chinmaya samantara
Assignee: chinmaya samantara
Updating only the external ID of a loan product is handled as a change of the
accounting rule. All GL account mappings of the product are deleted and
recreated from the request, so the advanced mappings (payment channel to fund
source, fees to income, penalties to income, charge-off reasons, ...) are lost
if the request does not repeat them. The response also shows the new external
ID under \{{accountingRule}}.
*Cause*
LoanProductUpdateUtil.update() puts the external ID change under the wrong key
(copy of the accounting rule block above it):
{code:java}
final String externalIdTypeParamName = "externalId";
if (command.isChangeInExternalIdParameterNamed(externalIdTypeParamName,
loanProduct.getExternalId())) {
final ExternalId newValue =
ExternalIdFactory.produce(command.stringValueOfParameterNamed(externalIdTypeParamName));
actualChanges.put(accountingTypeParamName, newValue); // should be
externalIdTypeParamName
loanProduct.setExternalId(newValue);
}
{code}
LoanProductWritePlatformServiceJpaRepositoryImpl.updateLoanProduct() then reads
\{{changes.containsKey("accountingRule")}} as "accounting rule changed" and
calls updateLoanProductToGLAccountMapping(accountingRuleChanged = true), which
deletes all mappings of the product and saves new ones from the request.
*Steps to reproduce* (develop, PostgreSQL)
1. Create a loan product with accounting rule 3 (accrual periodic), a payment
channel to fund source mapping and a fee to income account mapping.
2. PUT /loanproducts/\\{id} with the new externalId and the basic GL account
ids (accountingRule and the mandatory account ids).
3. GET /loanproducts/\\{id}: paymentChannelToFundSourceMappings and
feeToIncomeAccountMappings are empty.
Result on develop (0df2ef786f):
||Request||Response||Mappings (payment channel, fee income) before -> after||
|PUT \\{description} only|200, changes \\{description}|1, 1 -> 1, 1|
|PUT \\{externalId} only|400 "The parameter accountingRule is mandatory."|1, 1
-> 1, 1 (not updated)|
|PUT \\{externalId} + basic GL account ids|200, changes show the external ID
under "accountingRule"|1, 1 -> *0, 0*|
So the external ID can't be changed alone, and changing it with the account ids
silently removes the advanced mappings.
*Expected*: PUT \\{externalId} alone works, the change is reported as
externalId, and the accounting mappings are untouched.
*Fix*: \{{actualChanges.put(externalIdTypeParamName, newValue)}}, plus a unit
test.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)