Skip to content

Commit

Permalink
#5628 Do not check relation if matching location is not set in query
Browse files Browse the repository at this point in the history
#5628 Partner relations don't work properly in sales order
  • Loading branch information
cristinamghita committed Oct 9, 2019
1 parent a6cd090 commit ea6317e
Showing 1 changed file with 21 additions and 18 deletions.
Expand Up @@ -1019,7 +1019,7 @@ public I_C_BPartner_Location retrieveBPartnerLocation(@NonNull final BPartnerLoc
}

queryBuilder.orderBy()
.addColumn(I_C_BPartner_Location.COLUMNNAME_C_BPartner_Location_ID);
.addColumn(I_C_BPartner_Location.COLUMNNAME_C_BPartner_Location_ID);

final I_C_BPartner_Location ownToLocation = queryBuilder
.create()
Expand All @@ -1031,34 +1031,37 @@ public I_C_BPartner_Location retrieveBPartnerLocation(@NonNull final BPartnerLoc
return ownToLocation;
}

final IQueryBuilder<I_C_BP_Relation> bpRelationQueryBuilder = Services.get(IQueryBL.class)
.createQueryBuilder(I_C_BP_Relation.class)
.addEqualsFilter(I_C_BP_Relation.COLUMNNAME_C_BPartner_ID, query.getBpartnerId())
.addEqualsFilter(getFilterColumnNameForType(query.getType()), true)
.addOnlyActiveRecordsFilter();
if (query.getRelationBPartnerLocationId() != null)
{

queryBuilder.orderBy()
final IQueryBuilder<I_C_BP_Relation> bpRelationQueryBuilder = Services.get(IQueryBL.class)
.createQueryBuilder(I_C_BP_Relation.class)
.addEqualsFilter(I_C_BP_Relation.COLUMNNAME_C_BPartner_ID, query.getBpartnerId())
.addEqualsFilter(getFilterColumnNameForType(query.getType()), true)
.addOnlyActiveRecordsFilter();

queryBuilder.orderBy()
.addColumn(I_C_BP_Relation.COLUMNNAME_C_BP_Relation_ID);

final Stream<BPRelation> relationsStream = bpRelationQueryBuilder
.create()
.stream()
.map(bpRelationRecord -> ofRelationRecord(bpRelationRecord));
final Stream<BPRelation> relationsStream = bpRelationQueryBuilder
.create()
.stream()

Optional<BPartnerLocationId> relBPLocationId = Optional.empty();

Optional<BPartnerLocationId> relBPLocationId = Optional.empty();
if (query.getRelationBPartnerLocationId() != null)
{
relBPLocationId = relationsStream
.filter(bpRelation -> Objects.equals(query.getRelationBPartnerLocationId(), bpRelation.getBplocationId()))
.map(bpRelation -> bpRelation.getTargetBPLocationId())
.findFirst();
}

if (relBPLocationId.isPresent())
{
return InterfaceWrapperHelper.load(relBPLocationId.get().getRepoId(), I_C_BPartner_Location.class);
if (relBPLocationId.isPresent())
{
return InterfaceWrapperHelper.load(relBPLocationId.get().getRepoId(), I_C_BPartner_Location.class);
}
}



// if no location was found based on relation, return own location, null or non-null
return ownToLocation;
}
Expand Down

0 comments on commit ea6317e

Please sign in to comment.