Search in sources :

Example 1 with I_PP_Product_BOM

use of org.eevolution.model.I_PP_Product_BOM in project metasfresh-webui-api by metasfresh.

the class OrderLineQuickInputProcessor method explodePhantomBOM.

private List<OrderLineCandidate> explodePhantomBOM(final OrderLineCandidate initialCandidate) {
    final ProductId bomProductId = initialCandidate.getProductId();
    final I_PP_Product_BOM bom = bomsRepo.getDefaultBOMByProductId(bomProductId).orElse(null);
    if (bom == null) {
        return ImmutableList.of(initialCandidate);
    }
    final BOMUse bomUse = BOMUse.ofNullableCode(bom.getBOMUse());
    if (!BOMUse.Phantom.equals(bomUse)) {
        return ImmutableList.of(initialCandidate);
    }
    GroupId compensationGroupId = null;
    final ArrayList<OrderLineCandidate> result = new ArrayList<>();
    final List<I_PP_Product_BOMLine> bomLines = bomsRepo.retrieveLines(bom);
    for (final I_PP_Product_BOMLine bomLine : bomLines) {
        final ProductBOMLineId bomLineId = ProductBOMLineId.ofRepoId(bomLine.getPP_Product_BOMLine_ID());
        final ProductId bomLineProductId = ProductId.ofRepoId(bomLine.getM_Product_ID());
        final BigDecimal bomLineQty = bomsService.computeQtyRequired(bomLine, bomProductId, initialCandidate.getQty());
        final AttributeSetInstanceId bomLineAsiId = AttributeSetInstanceId.ofRepoIdOrNone(bomLine.getM_AttributeSetInstance_ID());
        final ImmutableAttributeSet attributes = asiBL.getImmutableAttributeSetById(bomLineAsiId);
        if (compensationGroupId == null) {
            compensationGroupId = orderGroupsRepo.createNewGroupId(GroupCreateRequest.builder().orderId(initialCandidate.getOrderId()).name(productBL.getProductName(bomProductId)).build());
        }
        result.add(initialCandidate.toBuilder().productId(bomLineProductId).attributes(attributes).qty(bomLineQty).compensationGroupId(compensationGroupId).explodedFromBOMLineId(bomLineId).build());
    }
    return result;
}
Also used : AttributeSetInstanceId(org.adempiere.mm.attributes.AttributeSetInstanceId) ArrayList(java.util.ArrayList) ProductId(de.metas.product.ProductId) HUPIItemProductId(de.metas.handlingunits.HUPIItemProductId) BigDecimal(java.math.BigDecimal) GroupId(de.metas.order.compensationGroup.GroupId) I_PP_Product_BOM(org.eevolution.model.I_PP_Product_BOM) ImmutableAttributeSet(org.adempiere.mm.attributes.api.ImmutableAttributeSet) ProductBOMLineId(org.eevolution.api.ProductBOMLineId) BOMUse(org.eevolution.api.BOMUse) I_PP_Product_BOMLine(org.eevolution.model.I_PP_Product_BOMLine)

Example 2 with I_PP_Product_BOM

use of org.eevolution.model.I_PP_Product_BOM in project metasfresh-webui-api by metasfresh.

the class CableSalesOrderLineQuickInputProcessor method getBOMProductId.

private ProductId getBOMProductId(ICablesOrderLineQuickInput quickInputModel) {
    final ProductId plugProduct1Id = ProductId.ofRepoId(quickInputModel.getPlug1_Product_ID());
    final ProductId plugProduct2Id = ProductId.ofRepoId(quickInputModel.getPlug2_Product_ID());
    final ProductId cableProductId = ProductId.ofRepoId(quickInputModel.getCable_Product_ID());
    final IProductBOMDAO productBOMsRepo = Services.get(IProductBOMDAO.class);
    final List<I_PP_Product_BOM> boms = productBOMsRepo.retrieveBOMsContainingExactProducts(plugProduct1Id.getRepoId(), cableProductId.getRepoId(), plugProduct2Id.getRepoId());
    if (boms.isEmpty()) {
        throw new AdempiereException("@NotFound@ @PP_Product_BOM_ID@");
    } else if (boms.size() > 1) {
        final String bomValues = boms.stream().map(I_PP_Product_BOM::getValue).collect(Collectors.joining(", "));
        throw new AdempiereException("More than one BOMs found: " + bomValues);
    } else {
        final I_PP_Product_BOM bom = boms.get(0);
        return ProductId.ofRepoId(bom.getM_Product_ID());
    }
}
Also used : I_PP_Product_BOM(org.eevolution.model.I_PP_Product_BOM) AdempiereException(org.adempiere.exceptions.AdempiereException) IProductBOMDAO(org.eevolution.api.IProductBOMDAO) ProductId(de.metas.product.ProductId)

Aggregations

ProductId (de.metas.product.ProductId)2 I_PP_Product_BOM (org.eevolution.model.I_PP_Product_BOM)2 HUPIItemProductId (de.metas.handlingunits.HUPIItemProductId)1 GroupId (de.metas.order.compensationGroup.GroupId)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 AttributeSetInstanceId (org.adempiere.mm.attributes.AttributeSetInstanceId)1 ImmutableAttributeSet (org.adempiere.mm.attributes.api.ImmutableAttributeSet)1 BOMUse (org.eevolution.api.BOMUse)1 IProductBOMDAO (org.eevolution.api.IProductBOMDAO)1 ProductBOMLineId (org.eevolution.api.ProductBOMLineId)1 I_PP_Product_BOMLine (org.eevolution.model.I_PP_Product_BOMLine)1