Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subtracted value on interim contract #17931

Merged
merged 48 commits into from
May 16, 2024

Conversation

adi-stefan
Copy link
Contributor

@adi-stefan adi-stefan commented Apr 23, 2024

ModCntr_Settings: interestrate & addinterestdays
ModCntr_InvoicingGroup: totalinterest

Moved ModCntr_InvoicingGroup & ModCntr_InvoicingGroup_Product to contracts
.uomId(uomId)
.build();

final I_C_Flatrate_Term interimContractRecord = flatrateBL.getById(createLogRequest.getContractId());
Copy link
Contributor

Choose a reason for hiding this comment

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

adi-stefan and others added 24 commits April 25, 2024 09:56
…lence_uat_SVInterimContract

# Conflicts:
#	backend/de.metas.contracts/src/main/java/de/metas/contracts/modular/computing/purchasecontract/interim/InterimInvoiceLineLog.java
#	backend/de.metas.contracts/src/main/java/de/metas/contracts/modular/computing/purchasecontract/subtractedvalue/interim/SVInterimComputingMethod.java
…lence_uat_SVInterimContract

# Conflicts:
#	backend/de.metas.contracts/src/main/java-gen/de/metas/contracts/model/X_ModCntr_Log.java
#	backend/de.metas.contracts/src/main/java-gen/de/metas/contracts/model/X_ModCntr_Settings.java
#	backend/de.metas.contracts/src/main/java/de/metas/contracts/modular/ModularContractPriceService.java
#	backend/de.metas.contracts/src/main/java/de/metas/contracts/modular/computing/purchasecontract/interim/InterimInvoiceLineLog.java
#	backend/de.metas.contracts/src/main/java/de/metas/contracts/modular/computing/purchasecontract/subtractedvalue/interim/SVInterimComputingMethod.java
#	backend/de.metas.contracts/src/main/java/de/metas/contracts/modular/log/ModularContractLogDAO.java
…mns to windows in Invoicing Group and Modular contract settings
- Removed `Balance`
- Added `C_Currency_ID`
- Renamed `Interest` to `InterestScore`
Changed ModCntr_Compute_Interest process to:
- default p_InterestToDistribute & p_InterestToDistributeCurrencyId based on currently selected p_InvoicingGroupId
- support no selection on ModCntr_Compute_Interest
- Added ModCntr_Compute_Interest to menu and added missing params
@Override
public boolean applies(final @NonNull TableRecordReference recordRef, @NonNull final LogEntryContractType logEntryContractType)
{
if (logEntryContractType.isModularContractType() && recordRef.getTableName().equals(I_M_Shipping_NotificationLine.Table_Name))
Copy link
Member

Choose a reason for hiding this comment

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

minor: we have .equalsByTableName

Check.assumeNotNull(invoice.getAmount(), "Invoices with no amount should've been skipped already! LogId="
+ invoice.getId());

final Instant conversionDate = Instant.now();
Copy link
Member

Choose a reason for hiding this comment

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

pls avoid using Instant.now()!

pls introduce the run date as a field in InterestBonusComputationRequest.

More, you might want to refactor all code from this Service into some InterestBonusComputationCommand.

}

@NonNull
public synchronized AllocationItem allocate(@NonNull final AllocationItem shippingNotification)
Copy link
Member

Choose a reason for hiding this comment

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

why these methods are synchronized?

Copy link
Contributor

Choose a reason for hiding this comment

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

bc I'm chaning its state, I want to make sure if at any given point this class ends up being used in a concurrent manner, it won't get messy

.toBigDecimal()
.multiply(bonusInterestRate)
.multiply(NumberUtils.asBigDecimal(interestDays))
.divide(NumberUtils.asBigDecimal(360), RoundingMode.HALF_UP);
Copy link
Member

Choose a reason for hiding this comment

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

pls use BigDecimal.valueOf; extract it as constant and document why is 360


if (currentInvoiceAllocations.canAllocate(currentShippingNotification))
{
currentShippingNotification = currentInvoiceAllocations.allocate(currentShippingNotification);
Copy link
Member

Choose a reason for hiding this comment

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

pls check, currentShippingNotification might be null

Copy link
Contributor

@cp-ps cp-ps May 16, 2024

Choose a reason for hiding this comment

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

it can't get pass canAllocate if it's null

@@ -145,24 +141,16 @@ public ComputingResponse compute(final @NonNull ComputingRequest request)
.contractModuleId(request.getModularContractModuleId())
.lockOwner(request.getLockOwner())
.build();
final ModularContractLogEntriesList modularContractLogEntries = modularContractLogService.getModularContractLogEntries(query);
if (modularContractLogEntries.isEmpty())
final PInstanceId pInstanceId = modularContractLogService.getModularContractLogEntrySelection(query);
Copy link
Member

Choose a reason for hiding this comment

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

super minor: IMHO u can call it selectionId instead pInstanceId (which sounds weird) :)

@@ -321,7 +322,7 @@ private InvoiceAllocations initInvoiceAllocations(
Check.assumeNotNull(invoice.getAmount(), "Invoices with no amount should've been skipped already! LogId="
+ invoice.getId());

final Instant conversionDate = Instant.now();
final Instant conversionDate = SystemTime.asInstant();
Copy link
Member

Choose a reason for hiding this comment

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

SystemTime.asInstant() is way better than Instant.now().... but pls try avoiding it as much as possible.

What stops you from getting the "computingDate" from request/param?

adi-stefan and others added 4 commits May 16, 2024 15:07
…act' into inner_silence_uat_SVInterimContract

# Conflicts:
#	backend/de.metas.contracts/src/main/java/de/metas/contracts/modular/interest/InterestComputationWorkPackageProcessor.java
public static final int TOTAL_DAYS_OF_FISCAL_YEAR = 360;
private final ModularLogInterestRepository interestRepository = SpringContextHolder.instance.getBean(ModularLogInterestRepository.class);
private final ModularContractLogService modularContractLogService = SpringContextHolder.instance.getBean(ModularContractLogService.class);
private final MoneyService moneyService = SpringContextHolder.instance.getBean(MoneyService.class);
Copy link
Member

Choose a reason for hiding this comment

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

pls avoid getBean. U can have those as ctor params

@@ -53,7 +56,7 @@ public static BigDecimal computeScore(@NonNull final Money amount, final int int
{
final BigDecimal amountAsBD = amount.toBigDecimal();

return amountAsBD.multiply(NumberUtils.asBigDecimal(interestDays))
.divide(NumberUtils.asBigDecimal(100), amountAsBD.scale(), RoundingMode.HALF_UP);
return amountAsBD.multiply(BigDecimal.valueOf(interestDays))
Copy link
Member

Choose a reason for hiding this comment

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

this looks like a percentage :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks, I assure you it is not :)

@@ -106,7 +106,7 @@ private void computeAndDistributeInterest(@NonNull final InterestComputationRequ

final InitialInterestAllocationResult result = createInterestRecords(request);
final BigDecimal interestDistributionPercent = request.getInterestToDistribute().toBigDecimal()
.divide(result.getTotalInterestScore(), result.getTotalInterestScore().scale(), RoundingMode.HALF_UP);
.divide(result.getTotalInterestScore(), request.getInterestScale(), RoundingMode.HALF_UP);
Copy link
Member

Choose a reason for hiding this comment

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

why not using Percent?

@@ -41,6 +41,7 @@ public class InterestComputationRequest
@NonNull Money interestToDistribute;
@NonNull LockOwner lockOwner;
@NonNull ComputingMethodType computingMethodType;
@NonNull Integer interestScale;
Copy link
Member

Choose a reason for hiding this comment

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

shall we use CurrencyPrecision instead of Integer?
(TBH not sure what interestScale means)

@cp-ps cp-ps merged commit d9cbbbb into inner_silence_uat May 16, 2024
13 of 14 checks passed
@cp-ps cp-ps deleted the inner_silence_uat_SVInterimContract branch May 16, 2024 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants