details: https://code.openbravo.com/erp/devel/pi/rev/9d3e6c2af297 changeset: 32292:9d3e6c2af297 user: Armaignac <collazoandy4 <at> gmail.com> date: Fri Jun 09 11:44:54 2017 -0400 summary: Fixes issue 36061: BOM Production is working for non stocked products
A stocked product filter was added to the create product transaction loop details: https://code.openbravo.com/erp/devel/pi/rev/e4a51675b08b changeset: 32293:e4a51675b08b user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Mon Jun 12 12:34:23 2017 +0200 summary: Related to issue 36061: Code review improvements Avoid NPE when calculating the cost of a production which consumes a non stocked product, as non stocked product will not have a related M_Transaction. For taking the cost of this non stocked transaction, we should look for a standard cost, same as we do in DocLine_Material.getProductCosts(). diffstat: src-db/database/model/functions/M_PRODUCTION_RUN.xml | 4 +- src/org/openbravo/costing/CostingAlgorithm.java | 31 +++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diffs (65 lines): diff -r 506566991e96 -r e4a51675b08b src-db/database/model/functions/M_PRODUCTION_RUN.xml --- a/src-db/database/model/functions/M_PRODUCTION_RUN.xml Fri Jun 09 20:40:34 2017 +0000 +++ b/src-db/database/model/functions/M_PRODUCTION_RUN.xml Mon Jun 12 12:34:23 2017 +0200 @@ -625,9 +625,11 @@ SELECT pl.M_ProductionLine_ID, pl.AD_Client_ID, pl.AD_Org_ID, p.MovementDate, pl.M_Product_ID, pl.M_AttributeSetInstance_ID, pl.MovementQty, pl.M_Locator_ID, pl.M_Product_UOM_ID, pl.QuantityOrder, pl.C_UOM_ID, pl.LINE - FROM M_PRODUCTION p, M_PRODUCTIONLINE pl, M_PRODUCTIONPLAN pp + FROM M_PRODUCTION p, M_PRODUCTIONLINE pl, M_PRODUCTIONPLAN pp, M_PRODUCT pro WHERE p.M_Production_ID=pp.M_Production_ID AND pp.M_ProductionPlan_ID=pl.M_ProductionPlan_ID + AND pl.M_PRODUCT_ID = pro.M_PRODUCT_ID + AND pro.ISSTOCKED = 'Y' AND pp.M_Production_ID=v_Record_ID ORDER BY pp.Line, pl.Line ) LOOP diff -r 506566991e96 -r e4a51675b08b src/org/openbravo/costing/CostingAlgorithm.java --- a/src/org/openbravo/costing/CostingAlgorithm.java Fri Jun 09 20:40:34 2017 +0000 +++ b/src/org/openbravo/costing/CostingAlgorithm.java Mon Jun 12 12:34:23 2017 +0200 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2012-2016 Openbravo SLU + * All portions are Copyright (C) 2012-2017 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************* @@ -488,16 +488,27 @@ // Reload from database in case previous partTrx cost calculation has cleared the session. prodLine = (ProductionLine) OBDal.getInstance().getProxy(ProductionLine.ENTITY_NAME, prodLine.getId()); - MaterialTransaction partTransaction = prodLine.getMaterialMgmtMaterialTransactionList() - .get(0); - // Reload from database in case previous partTrx cost calculation has cleared the session. - partTransaction = OBDal.getInstance().get(MaterialTransaction.class, partTransaction.getId()); - // Calculate transaction cost if it is not calculated yet. - BigDecimal trxCost = CostingUtils.getTransactionCost(partTransaction, - transaction.getTransactionProcessDate(), true, costCurrency); - if (trxCost == null) { - throw new OBException("@NoCostCalculated@: " + partTransaction.getIdentifier()); + + BigDecimal trxCost; + List<MaterialTransaction> trxList = prodLine.getMaterialMgmtMaterialTransactionList(); + if (trxList.isEmpty()) { + // If there isn't any material transaction get the default cost of the product. + trxCost = CostingUtils.getStandardCost(prodLine.getProduct(), costOrg, + transaction.getTransactionProcessDate(), costDimensions, costCurrency).multiply( + prodLine.getMovementQuantity().abs()); + } else { + MaterialTransaction partTransaction = trxList.get(0); + // Reload from database in case previous partTrx cost calculation has cleared the session. + partTransaction = OBDal.getInstance().get(MaterialTransaction.class, + partTransaction.getId()); + // Calculate transaction cost if it is not calculated yet. + trxCost = CostingUtils.getTransactionCost(partTransaction, + transaction.getTransactionProcessDate(), true, costCurrency); + if (trxCost == null) { + throw new OBException("@NoCostCalculated@: " + partTransaction.getIdentifier()); + } } + totalCost = totalCost.add(trxCost); } return totalCost; ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits