details: https://code.openbravo.com/erp/devel/pi/rev/53dc443d6e17 changeset: 30854:53dc443d6e17 user: David Miguelez <david.miguelez <at> openbravo.com> date: Fri Dec 09 12:28:25 2016 +0100 summary: [UOM Management] Code Review fixes.
*Fixes wrong license in Trigger *Moves check in trigger to a check constraint in a Table *Minor fixes in Java file. diffstat: src-db/database/model/tables/M_PRODUCT_AUM.xml | 1 + src-db/database/model/triggers/M_PRODUCT_AUM_TRG.xml | 39 ++++++----------- src/org/openbravo/materialmgmt/UOMUtil.java | 43 ++++++++++--------- 3 files changed, 39 insertions(+), 44 deletions(-) diffs (211 lines): diff -r d008b46f932c -r 53dc443d6e17 src-db/database/model/tables/M_PRODUCT_AUM.xml --- a/src-db/database/model/tables/M_PRODUCT_AUM.xml Mon Dec 05 09:13:06 2016 -0500 +++ b/src-db/database/model/tables/M_PRODUCT_AUM.xml Fri Dec 09 12:28:25 2016 +0100 @@ -86,6 +86,7 @@ <unique-column name="M_PRODUCT_ID"/> <unique-column name="C_UOM_ID"/> </unique> + <check name="M_PRODUCT_AUM_RATE_CHECK"><![CDATA[CONVERSIONRATE > 0]]></check> <check name="M_PRODUCT_UOM_CHK"><![CDATA[ISACTIVE IN ('Y', 'N')]]></check> </table> </database> diff -r d008b46f932c -r 53dc443d6e17 src-db/database/model/triggers/M_PRODUCT_AUM_TRG.xml --- a/src-db/database/model/triggers/M_PRODUCT_AUM_TRG.xml Mon Dec 05 09:13:06 2016 -0500 +++ b/src-db/database/model/triggers/M_PRODUCT_AUM_TRG.xml Fri Dec 09 12:28:25 2016 +0100 @@ -3,28 +3,23 @@ <trigger name="M_PRODUCT_AUM_TRG" table="M_PRODUCT_AUM" fires="before" insert="true" update="true" delete="false" foreach="row"> <body><![CDATA[ /************************************************************************* - * The contents of this file are subject to the Compiere Public - * License 1.1 ("License"); You may not use this file except in - * compliance with the License. You may obtain a copy of the License in - * the legal folder of your Openbravo installation. - * Software distributed under the License is distributed on an - * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing rights - * and limitations under the License. - * The Original Code is Compiere ERP & Business Solution - * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc. - * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, - * parts created by ComPiere are Copyright (C) ComPiere, Inc.; - * All Rights Reserved. - * Contributor(s): Openbravo SLU - * Contributions are Copyright (C) 2016 Openbravo, S.L.U. - * - * Specifically, this derivative work is based upon the following Compiere - * file and version. - *************************************************************************/ +* The contents of this file are subject to the Openbravo Public License +* Version 1.1 (the "License"), being the Mozilla Public License +* Version 1.1 with a permitted attribution clause; you may not use this +* file except in compliance with the License. You may obtain a copy of +* the License at http://www.openbravo.com/legal/license.html +* Software distributed under the License is distributed on an "AS IS" +* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +* License for the specific language governing rights and limitations +* under the License. +* The Original Code is Openbravo ERP. +* The Initial Developer of the Original Code is Openbravo SLU +* All portions are Copyright (C) 2016 Openbravo SLU +* All Rights Reserved. +* Contributor(s): ______________________________________. +************************************************************************/ v_Count NUMBER; -v_Match BOOLEAN; v_GTINALLOWEDCHAR VARCHAR(60) := 'QWERTYUIOPASDFGHJKLZXCVBNM0123456789'; BEGIN @@ -32,10 +27,6 @@ IF AD_isTriggerEnabled()='N' THEN RETURN; END IF; - IF (:new.conversionrate = 0) THEN - RAISE_APPLICATION_ERROR(-20000, '@ConversionrateGTZero@'); - END IF; - SELECT count(*) INTO v_Count FROM dual diff -r d008b46f932c -r 53dc443d6e17 src/org/openbravo/materialmgmt/UOMUtil.java --- a/src/org/openbravo/materialmgmt/UOMUtil.java Mon Dec 05 09:13:06 2016 -0500 +++ b/src/org/openbravo/materialmgmt/UOMUtil.java Fri Dec 09 12:28:25 2016 +0100 @@ -38,7 +38,6 @@ import org.openbravo.erpCommon.utility.FieldProviderFactory; import org.openbravo.erpCommon.utility.OBMessageUtils; import org.openbravo.erpCommon.utility.PropertyException; -import org.openbravo.model.ad.system.Client; import org.openbravo.model.common.enterprise.DocumentType; import org.openbravo.model.common.plm.Product; import org.openbravo.model.common.plm.ProductAUM; @@ -74,6 +73,7 @@ */ public static String getDefaultAUMForDocument(String mProductId, String documentTypeId) { + // Do not check Organization access OBContext.setAdminMode(false); try { if (mProductId == null || documentTypeId == null) { @@ -115,11 +115,13 @@ return null; } String finalAUM = ""; + // Do not check Organization access OBContext.setAdminMode(false); try { OBCriteria<ProductAUM> pAUMCriteria = OBDal.getInstance().createCriteria(ProductAUM.class); - pAUMCriteria.add(Restrictions.and(Restrictions.eq("product.id", mProductId), Restrictions.eq( - isSoTrx ? ProductAUM.PROPERTY_SALES : ProductAUM.PROPERTY_PURCHASE, UOM_PRIMARY))); + pAUMCriteria.add(Restrictions.eq("product.id", mProductId)); + pAUMCriteria.add(Restrictions.eq(isSoTrx ? ProductAUM.PROPERTY_SALES + : ProductAUM.PROPERTY_PURCHASE, UOM_PRIMARY)); Product product = OBDal.getInstance().get(Product.class, mProductId); finalAUM = product.getUOM().getId(); ProductAUM primaryAum = (ProductAUM) pAUMCriteria.uniqueResult(); @@ -143,6 +145,7 @@ */ public static List<UOM> getAvailableUOMsForDocument(String mProductId, String docTypeId) { List<UOM> lUom = new ArrayList<UOM>(); + // Do not check Organization access OBContext.setAdminMode(false); try { if (mProductId == null || docTypeId == null) { @@ -150,9 +153,10 @@ } DocumentType docType = OBDal.getInstance().get(DocumentType.class, docTypeId); OBCriteria<ProductAUM> pAUMCriteria = OBDal.getInstance().createCriteria(ProductAUM.class); - pAUMCriteria.add(Restrictions.and(Restrictions.eq("product.id", mProductId), Restrictions.ne( - docType.isSalesTransaction() ? ProductAUM.PROPERTY_SALES : ProductAUM.PROPERTY_PURCHASE, - UOM_NOT_APPLICABLE))); + pAUMCriteria.add(Restrictions.eq("product.id", mProductId)); + pAUMCriteria.add(Restrictions.ne(docType.isSalesTransaction() ? ProductAUM.PROPERTY_SALES + : ProductAUM.PROPERTY_PURCHASE, UOM_NOT_APPLICABLE)); + pAUMCriteria.addOrderBy("uOM.name", true); Product product = OBDal.getInstance().get(Product.class, mProductId); List<ProductAUM> pAUMList = pAUMCriteria.list(); for (ProductAUM pAUM : pAUMList) { @@ -182,6 +186,7 @@ private static BigDecimal getConvertedQty(String mProductId, BigDecimal qty, String toUOMId, boolean reverse) throws OBException { BigDecimal strQty = qty; + // Do not check Organization access OBContext.setAdminMode(false); try { Product product = OBDal.getInstance().get(Product.class, mProductId); @@ -201,11 +206,11 @@ try { ProductAUM conversion = (ProductAUM) productAUMConversionCriteria.uniqueResult(); if (conversion == null) { - throw new OBException(OBMessageUtils.messageBD(new DalConnectionProvider(), + throw new OBException(OBMessageUtils.messageBD(new DalConnectionProvider(false), "NoAUMDefined", OBContext.getOBContext().getLanguage().getLanguage())); } BigDecimal rate = conversion.getConversionRate(); - UOM uom = OBDal.getInstance().get(UOM.class, conversion.getUOM().getId()); + UOM uom = conversion.getUOM(); if (reverse) { strQty = qty.divide(rate, uom.getStandardPrecision().intValue(), RoundingMode.HALF_UP); } else { @@ -213,7 +218,7 @@ RoundingMode.HALF_UP); } } catch (NonUniqueResultException e) { - throw new OBException(OBMessageUtils.messageBD(new DalConnectionProvider(), + throw new OBException(OBMessageUtils.messageBD(new DalConnectionProvider(false), "DuplicateAUM", OBContext.getOBContext().getLanguage().getLanguage())); } } @@ -269,19 +274,13 @@ */ public static boolean isUomManagementEnabled() { String propertyValue = "N"; - OBContext.setAdminMode(false); try { - try { - Client systemClient = OBDal.getInstance().get(Client.class, "0"); - propertyValue = Preferences.getPreferenceValue(UOM_PROPERTY, true, systemClient, null, - null, null, null); - } catch (PropertyException e) { - log4j.debug("Preference UomManagement not found", e); - } - } finally { - OBContext.restorePreviousMode(); + propertyValue = Preferences.getPreferenceValue(UOM_PROPERTY, true, "0", null, null, null, + null); + } catch (PropertyException e) { + log4j.debug("Preference UomManagement not found", e); } - return (propertyValue!= null && propertyValue.equals("Y")); + return (propertyValue != null && propertyValue.equals("Y")); } /** @@ -299,6 +298,7 @@ if (productId == null || productId.isEmpty() || docTypeId == null || docTypeId.isEmpty()) { return FieldProviderFactory.getFieldProviderArray(result); } + // Do not check Organization access OBContext.setAdminMode(false); try { String id = getDefaultAUMForDocument(productId, docTypeId); @@ -328,6 +328,7 @@ if (productId == null || productId.isEmpty() || docTypeId == null || docTypeId.isEmpty()) { return FieldProviderFactory.getFieldProviderArray(result); } + // Do not check Organization access OBContext.setAdminMode(false); try { List<UOM> availableUOM = getAvailableUOMsForDocument(productId, docTypeId); @@ -351,10 +352,12 @@ if (productId == null || productId.isEmpty()) { return FieldProviderFactory.getFieldProviderArray(result); } + // Do not check Organization access OBContext.setAdminMode(false); try { OBCriteria<ProductUOM> pUomCriteria = OBDal.getInstance().createCriteria(ProductUOM.class); pUomCriteria.add(Restrictions.eq("product.id", productId)); + pUomCriteria.addOrderBy("uOM.name", true); List<ProductUOM> pUomList = pUomCriteria.list(); for (ProductUOM pUom : pUomList) { resultMap = new HashMap<>(); ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today.http://sdm.link/xeonphi _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits