Skip to content

Commit

Permalink
fix for the LU PI's lookup code
Browse files Browse the repository at this point in the history
FRESH-1504 #181 Transforming HU in Handling Unit Editor
  • Loading branch information
metas-ts committed Mar 9, 2017
1 parent 07e0f8f commit 03bae85
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.metas.ui.web.handlingunits.process;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
Expand Down Expand Up @@ -622,23 +623,28 @@ private LookupValuesList getM_HU_PI_Item_ID()
}

final HUDocumentView tuRow = getSingleSelectedRow();
final I_M_HU_PI tuPI = Services.get(IHandlingUnitsBL.class).getEffectivePIVersion(tuRow.getM_HU()).getM_HU_PI();
final I_M_HU tuHU = tuRow.getM_HU();
final I_M_HU_PI tuPI = Services.get(IHandlingUnitsBL.class).getEffectivePIVersion(tuHU).getM_HU_PI();

final List<I_M_HU_PI_Item> luPIItems = Services.get(IQueryBL.class).createQueryBuilder(I_M_HU_PI_Item.class, this)
.addOnlyActiveRecordsFilter()
.addEqualsFilter(I_M_HU_PI_Item.COLUMN_Included_HU_PI_ID, tuPI.getM_HU_PI_ID())
.addOnlyActiveRecordsFilter()
.addInArrayFilter(I_M_HU_PI_Item.COLUMN_C_BPartner_ID, null, tuHU.getC_BPartner_ID())
.create()
.list();

return luPIItems.stream()
.filter(luPIItem -> luPIItem.getM_HU_PI_Version().isCurrent() && luPIItem.getM_HU_PI_Version().isActive() && luPIItem.getM_HU_PI_Version().getM_HU_PI().isActive())
.map(luPIItem -> IntegerLookupValue.of(luPIItem.getM_HU_PI_Item_ID(), buildHUPIItemString(luPIItem)))
.sorted(Comparator.comparing(IntegerLookupValue::getDisplayName))
.collect(LookupValuesList.collect());
}

private String buildHUPIItemString(final I_M_HU_PI_Item huPIItem)
{
return StringUtils.formatMessage("{} ({} x {})", huPIItem.getM_HU_PI_Version().getName(), huPIItem.getQty(), huPIItem.getIncluded_HU_PI().getName());
return StringUtils.formatMessage("{} ({} x {})",
huPIItem.getM_HU_PI_Version().getName(),
huPIItem.getQty().setScale(0, RoundingMode.HALF_UP), // it's always integer quantities
huPIItem.getIncluded_HU_PI().getName());
}
}

0 comments on commit 03bae85

Please sign in to comment.