Skip to content

Commit

Permalink
5823-app - Delivery contract with same product but different attributes
Browse files Browse the repository at this point in the history
* Port thw complete method IFlatrateBL.isAllowedToOverlapWithOtherTerms to this branch
* FlatrateBL allow contract with type TYPE_CONDITIONS_Procurement to overlap
* Add a bit of javadoc to explain the issue
#5823

(cherry picked from commit 2e37119)

solved Conflicts:
	de.metas.contracts/src/main/java/de/metas/contracts/IFlatrateBL.java
	de.metas.contracts/src/main/java/de/metas/contracts/impl/FlatrateBL.java
  • Loading branch information
metas-ts committed Nov 26, 2019
1 parent 21ffbd6 commit d498dc2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
Expand Up @@ -198,11 +198,21 @@ I_C_Flatrate_Term createTerm(IContextAware context,
void voidIt(I_C_Flatrate_Term term);

/**
* Check if there are terms for the same that have a time period overlapping with the given term and match with the same product or product category.
* Return {@code true} if the given term (by virtue of its conditions-type) does not define a set of invoice candidates that "belong" to it.
* Examples for ICs that belong to a contract in this sense are e.g. ICs that shall trigger a refund, a commission payment or are empties (e.g. empty pallets).
* In all this cases, a completed term matches a set of ICs and for every given ICs, we need to make sure that max. one term matches it.
*
* Also see {@link #hasOverlappingTerms(I_C_Flatrate_Term)}.
*/
boolean isAllowedToOverlapWithOtherTerms(I_C_Flatrate_Term term);

/**
* Check if there are terms for the same bPartner that have a time period overlapping with the given term and match with the same product or product category.
* <p>
* Note that overlapping need to be prevented for those types of terms (like refund contracts or refundable contracts) to which newly created invoice candidates need to be mapped.
* Overlapping is no problem for subscription contracts.
*
* @param term
* @return
* Also see {@link #isAllowedToOverlapWithOtherTerms(I_C_Flatrate_Term)}.
*/
boolean hasOverlappingTerms(final I_C_Flatrate_Term term);

Expand Down
Expand Up @@ -155,7 +155,7 @@ public interface IFlatrateDAO extends ISingletonService
void updateQtyActualFromDataEntry(I_C_Flatrate_DataEntry dataEntry);

/**
* Retrieves the flatrate term matching the given invoice candidate or <code>null</code>.<br>
* Retrieves the flatrate term matching the given invoice candidate (or {@code code>}) by using {@link I_C_Flatrate_Matching} Records.<br>
* Basically calls {@link #retrieveTerms(Properties, int, Timestamp, int, int, int, String)}, but discards all terms that have <code>IsSimulation=Y</code>.
*
* @return the term or <code>null</code>
Expand Down
Expand Up @@ -1553,17 +1553,19 @@ public void complete(final I_C_Flatrate_Term term)
@Override
public void completeIfValid(final I_C_Flatrate_Term term)
{
final boolean hasOverlappingTerms = hasOverlappingTerms(term);
if (hasOverlappingTerms)
if (!isAllowedToOverlapWithOtherTerms(term))
{
final boolean hasOverlappingTerms = hasOverlappingTerms(term);
if (hasOverlappingTerms)
{

Loggables.get().addLog(Services.get(IMsgBL.class).getMsg(
Env.getCtx(),
MSG_HasOverlapping_Term,
new Object[] { term.getC_Flatrate_Term_ID(), term.getBill_BPartner().getValue() }));
return;
Loggables.get().addLog(Services.get(IMsgBL.class).getMsg(
Env.getCtx(),
MSG_HasOverlapping_Term,
new Object[] { term.getC_Flatrate_Term_ID(), term.getBill_BPartner().getValue() }));
return;
}
}

complete(term);
}

Expand All @@ -1575,6 +1577,18 @@ public void voidIt(final I_C_Flatrate_Term term)

}

@Override
public boolean isAllowedToOverlapWithOtherTerms(@NonNull final I_C_Flatrate_Term term)
{
final String typeConditions = term.getType_Conditions();

// These contract types do not match "other" ICs such as ICs that trigger a commission, or IC that belong to a vendor's empty package (pallette/TU).
// Therefore they can overlap without causing us any problems.
final boolean allowedToOverlapWithOtherTerms = X_C_Flatrate_Term.TYPE_CONDITIONS_Subscription.equals(typeConditions)
|| X_C_Flatrate_Term.TYPE_CONDITIONS_Procurement.equals(typeConditions);
return allowedToOverlapWithOtherTerms;
}

@Override
public boolean hasOverlappingTerms(final I_C_Flatrate_Term newTerm)
{
Expand Down
Expand Up @@ -493,6 +493,10 @@ public void preventOverlappingTerms_OnComplete(final I_C_Flatrate_Term term)
// services
final IFlatrateBL flatrateBL = Services.get(IFlatrateBL.class);

if (flatrateBL.isAllowedToOverlapWithOtherTerms(term))
{
return;
}
final boolean hasOverlappingTerms = flatrateBL.hasOverlappingTerms(term);
if (hasOverlappingTerms)
{
Expand All @@ -518,7 +522,7 @@ private void setMasterEndDate(final I_C_Flatrate_Term term)

term.setMasterEndDate(masterEndDate);
}

private Timestamp computeMasterEndDateIfC_FlatrateTerm_Next_IDChanged(@NonNull final I_C_Flatrate_Term term, Timestamp masterEndDate)
{
if (InterfaceWrapperHelper.isValueChanged(term, I_C_Flatrate_Term.COLUMNNAME_C_FlatrateTerm_Next_ID) && !term.isAutoRenew())
Expand All @@ -532,7 +536,7 @@ private Timestamp computeMasterEndDateIfC_FlatrateTerm_Next_IDChanged(@NonNull f
masterEndDate = term.getEndDate();
}
}

return masterEndDate;
}
}

0 comments on commit d498dc2

Please sign in to comment.