Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set Sales Order Line's ProductDescription as Product BOM's description
- Loading branch information
Showing
8 changed files
with
193 additions
and
21 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...ion/src/main/sql/postgresql/system/10-de.metas.adempiere/5500270_sys_gh4535_sysconfig.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- 2018-08-30T16:54:27.918 | ||
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator | ||
INSERT INTO AD_SysConfig (Value,EntityType,AD_Client_ID,CreatedBy,UpdatedBy,IsActive,ConfigurationLevel,AD_SysConfig_ID,Description,AD_Org_ID,Name,Created,Updated) VALUES ('N','D',0,100,100,'Y','S',541230,'See https://github.com/metasfresh/metasfresh/issues/4535',0,'de.metas.order.sales.line.SetBOMDescription',TO_TIMESTAMP('2018-08-30 16:54:27','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2018-08-30 16:54:27','YYYY-MM-DD HH24:MI:SS')) | ||
; | ||
|
||
-- 2018-08-30T16:54:32.319 | ||
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator | ||
-- UPDATE AD_SysConfig SET Value='Y',Updated=TO_TIMESTAMP('2018-08-30 16:54:32','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_SysConfig_ID=541230; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
de.metas.business/src/main/java/org/eevolution/api/impl/ProductBOMDescriptionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package org.eevolution.api.impl; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import org.adempiere.uom.api.IUOMDAO; | ||
import org.adempiere.util.NumberUtils; | ||
import org.adempiere.util.Services; | ||
import org.compiere.model.I_C_UOM; | ||
import org.compiere.model.I_M_Product; | ||
import org.eevolution.api.IProductBOMDAO; | ||
import org.eevolution.model.I_PP_Product_BOM; | ||
import org.eevolution.model.I_PP_Product_BOMLine; | ||
|
||
import com.google.common.base.Predicates; | ||
|
||
import de.metas.product.IProductDAO; | ||
import de.metas.product.ProductId; | ||
import lombok.NonNull; | ||
|
||
/* | ||
* #%L | ||
* de.metas.business | ||
* %% | ||
* Copyright (C) 2018 metas GmbH | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 2 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-2.0.html>. | ||
* #L% | ||
*/ | ||
|
||
final class ProductBOMDescriptionBuilder | ||
{ | ||
public static ProductBOMDescriptionBuilder newInstance() | ||
{ | ||
return new ProductBOMDescriptionBuilder(); | ||
} | ||
|
||
private final IProductDAO productsRepo = Services.get(IProductDAO.class); | ||
private final IProductBOMDAO bomsRepo = Services.get(IProductBOMDAO.class); | ||
private final IUOMDAO uomsRepo = Services.get(IUOMDAO.class); | ||
|
||
private ProductBOMDescriptionBuilder() | ||
{ | ||
} | ||
|
||
public String build(@NonNull final ProductId productId) | ||
{ | ||
final I_M_Product bomProduct = productsRepo.getById(productId); | ||
final I_PP_Product_BOM bom = bomsRepo.retrieveDefaultBOM(bomProduct); | ||
if (bom == null || !bom.isActive()) | ||
{ | ||
return null; | ||
} | ||
|
||
return bomsRepo.retrieveLines(bom) | ||
.stream() | ||
.map(this::toBOMLineString) | ||
.filter(Predicates.notNull()) | ||
.collect(Collectors.joining("\r\n")); | ||
} | ||
|
||
private String toBOMLineString(final I_PP_Product_BOMLine bomLine) | ||
{ | ||
if (!bomLine.isActive()) | ||
{ | ||
return null; | ||
} | ||
|
||
final I_M_Product product = productsRepo.getById(bomLine.getM_Product_ID()); | ||
final String qtyStr = toBOMLineQtyAndUOMString(bomLine); | ||
|
||
return new StringBuilder() | ||
.append(product.getValue()) | ||
.append(" ") | ||
.append(product.getName()) | ||
.append(" ") | ||
.append(qtyStr) | ||
.toString(); | ||
} | ||
|
||
private String toBOMLineQtyAndUOMString(final I_PP_Product_BOMLine bomLine) | ||
{ | ||
if (bomLine.isQtyPercentage()) | ||
{ | ||
return NumberUtils.stripTrailingDecimalZeros(bomLine.getQtyBatch()) + "%"; | ||
} | ||
else | ||
{ | ||
final StringBuilder qtyStr = new StringBuilder(); | ||
qtyStr.append(NumberUtils.stripTrailingDecimalZeros(bomLine.getQtyBOM())); | ||
|
||
final int uomId = bomLine.getC_UOM_ID(); | ||
if (uomId > 0) | ||
{ | ||
final I_C_UOM uom = uomsRepo.getById(uomId); | ||
qtyStr.append(" ").append(uom.getUOMSymbol()); | ||
} | ||
|
||
return qtyStr.toString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters