details:   https://code.openbravo.com/erp/devel/pi/rev/70f14eb6163a
changeset: 27315:70f14eb6163a
user:      Alvaro Ferraz <alvaro.ferraz <at> openbravo.com>
date:      Fri Jul 17 15:02:18 2015 +0200
summary:   Fixes issue 29723: Avoid cost adjustmens in Landed Cost + Standard 
Algorithm

Cost Adjustments will not be created in landed cost created with Standard 
Algorithm.
Goods Receipt selector in Landed Cost window - Receipt tab, will only show 
receipts processed with current costing rule.
Landed Cost and Landed Cost Cost documents will create cost adjustment only if 
active costing rule does not use Standard Algorithm.
Landed Cost and Landed Cost Cost differences will be posted to a IPV account 
(instead of an Asset account) if used costing rule does not use Standard 
Algorithm.

details:   https://code.openbravo.com/erp/devel/pi/rev/f9fc3ff9fad2
changeset: 27316:f9fc3ff9fad2
user:      Alvaro Ferraz <alvaro.ferraz <at> openbravo.com>
date:      Thu Jul 16 11:31:58 2015 +0200
summary:   Related to issue 29723: Modify an assert in TestCosting

details:   https://code.openbravo.com/erp/devel/pi/rev/092bf17c3613
changeset: 27317:092bf17c3613
user:      David Miguelez <david.miguelez <at> openbravo.com>
date:      Thu Aug 13 12:03:24 2015 +0200
summary:   Related to Issue 29723. Code Review changes.
Modifies Query to improve performance.

diffstat:

 src-db/database/sourcedata/AD_AUXILIARINPUT.xml          |  11 +++++
 src-db/database/sourcedata/AD_FIELD.xml                  |   2 +-
 src-db/database/sourcedata/OBUISEL_SELECTOR.xml          |   2 +-
 src-test/src/org/openbravo/test/costing/TestCosting.java |   2 +-
 src/org/openbravo/costing/LCMatchingCancelHandler.java   |   9 +++-
 src/org/openbravo/costing/LCMatchingProcess.java         |  16 ++++++-
 src/org/openbravo/costing/LandedCostProcess.java         |  17 +++++++-
 src/org/openbravo/costing/ReactivateLandedCost.java      |  18 ++++++---
 src/org/openbravo/erpCommon/ad_forms/DocLCCost.java      |  31 ++++++++++++---
 src/org/openbravo/erpCommon/ad_forms/DocLandedCost.java  |  28 +++++++++++---
 10 files changed, 106 insertions(+), 30 deletions(-)

diffs (truncated from 340 to 300 lines):

diff -r 66762e6a74d2 -r 092bf17c3613 
src-db/database/sourcedata/AD_AUXILIARINPUT.xml
--- a/src-db/database/sourcedata/AD_AUXILIARINPUT.xml   Thu Aug 13 10:33:36 
2015 +0200
+++ b/src-db/database/sourcedata/AD_AUXILIARINPUT.xml   Thu Aug 13 12:03:24 
2015 +0200
@@ -3211,6 +3211,17 @@
 <!--A81DE6745CD547F088CCCA4A27E4B117-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--A81DE6745CD547F088CCCA4A27E4B117--></AD_AUXILIARINPUT>
 
+<!--A8CBEB3ABE9140D5A33334C1AC273517--><AD_AUXILIARINPUT>
+<!--A8CBEB3ABE9140D5A33334C1AC273517-->  
<AD_AUXILIARINPUT_ID><![CDATA[A8CBEB3ABE9140D5A33334C1AC273517]]></AD_AUXILIARINPUT_ID>
+<!--A8CBEB3ABE9140D5A33334C1AC273517-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A8CBEB3ABE9140D5A33334C1AC273517-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A8CBEB3ABE9140D5A33334C1AC273517-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A8CBEB3ABE9140D5A33334C1AC273517-->  
<AD_TAB_ID><![CDATA[F25CBC61CDD64F5E8A6FDC41C6E23C96]]></AD_TAB_ID>
+<!--A8CBEB3ABE9140D5A33334C1AC273517-->  <NAME><![CDATA[LCProcessed]]></NAME>
+<!--A8CBEB3ABE9140D5A33334C1AC273517-->  <CODE><![CDATA[@SQL=SELECT PROCESSED 
FROM M_LANDEDCOST WHERE M_LANDEDCOST_ID = @M_LANDEDCOST_ID@]]></CODE>
+<!--A8CBEB3ABE9140D5A33334C1AC273517-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--A8CBEB3ABE9140D5A33334C1AC273517--></AD_AUXILIARINPUT>
+
 <!--A937C82DEBEF4A5A998C89372C02915A--><AD_AUXILIARINPUT>
 <!--A937C82DEBEF4A5A998C89372C02915A-->  
<AD_AUXILIARINPUT_ID><![CDATA[A937C82DEBEF4A5A998C89372C02915A]]></AD_AUXILIARINPUT_ID>
 <!--A937C82DEBEF4A5A998C89372C02915A-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
diff -r 66762e6a74d2 -r 092bf17c3613 src-db/database/sourcedata/AD_FIELD.xml
--- a/src-db/database/sourcedata/AD_FIELD.xml   Thu Aug 13 10:33:36 2015 +0200
+++ b/src-db/database/sourcedata/AD_FIELD.xml   Thu Aug 13 12:03:24 2015 +0200
@@ -178567,7 +178567,7 @@
 <!--022DB9FBFB7E3B3FE050007F01000850-->  
<AD_COLUMN_ID><![CDATA[022DB885E9665700E050007F01000846]]></AD_COLUMN_ID>
 <!--022DB9FBFB7E3B3FE050007F01000850-->  
<IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
 <!--022DB9FBFB7E3B3FE050007F01000850-->  
<ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
-<!--022DB9FBFB7E3B3FE050007F01000850-->  
<DISPLAYLOGIC><![CDATA[@IsMatched@='N' & 
@M_Costadjustment_ID@!'']]></DISPLAYLOGIC>
+<!--022DB9FBFB7E3B3FE050007F01000850-->  
<DISPLAYLOGIC><![CDATA[@IsMatched@='N' & @LCProcessed@='Y']]></DISPLAYLOGIC>
 <!--022DB9FBFB7E3B3FE050007F01000850-->  
<DISPLAYLENGTH><![CDATA[1]]></DISPLAYLENGTH>
 <!--022DB9FBFB7E3B3FE050007F01000850-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--022DB9FBFB7E3B3FE050007F01000850-->  <SEQNO><![CDATA[1000]]></SEQNO>
diff -r 66762e6a74d2 -r 092bf17c3613 
src-db/database/sourcedata/OBUISEL_SELECTOR.xml
--- a/src-db/database/sourcedata/OBUISEL_SELECTOR.xml   Thu Aug 13 10:33:36 
2015 +0200
+++ b/src-db/database/sourcedata/OBUISEL_SELECTOR.xml   Thu Aug 13 12:03:24 
2015 +0200
@@ -1035,7 +1035,7 @@
 <!--F3CDEE79343F4746A2FEE8C60EBEC0BF-->  <NAME><![CDATA[Receipts]]></NAME>
 <!--F3CDEE79343F4746A2FEE8C60EBEC0BF-->  
<AD_REFERENCE_ID><![CDATA[E68CCF4495A34ED7902293A930386B93]]></AD_REFERENCE_ID>
 <!--F3CDEE79343F4746A2FEE8C60EBEC0BF-->  
<AD_TABLE_ID><![CDATA[319]]></AD_TABLE_ID>
-<!--F3CDEE79343F4746A2FEE8C60EBEC0BF-->  
<WHERECLAUSE><![CDATA[e.salesTransaction = false AND e.documentStatus = 'CO' 
AND exists ( select 1 from MaterialMgmtShipmentInOutLine m where 
m.shipmentReceipt.id=e.id and m.movementQuantity >= 0 )]]></WHERECLAUSE>
+<!--F3CDEE79343F4746A2FEE8C60EBEC0BF-->  
<WHERECLAUSE><![CDATA[e.salesTransaction = false AND e.documentStatus = 'CO' 
AND exists ( select 1 from MaterialMgmtShipmentInOutLine m where 
m.shipmentReceipt.id=e.id and m.movementQuantity >= 0 ) AND exists (select 1 
from MaterialMgmtMaterialTransaction t, CostingRule r where 
t.goodsShipmentLine.shipmentReceipt.id=e.id and r.validated = 'Y' and 
ad_org_isinnaturaltree(r.organization.id, t.organization.id, t.client.id) = 'Y' 
and r.startingDate <= t.transactionProcessDate and r.endingDate is null ) 
]]></WHERECLAUSE>
 <!--F3CDEE79343F4746A2FEE8C60EBEC0BF-->  
<OBCLKER_TEMPLATE_ID><![CDATA[9314DE8599AD44E7BFC4CC50699042AB]]></OBCLKER_TEMPLATE_ID>
 <!--F3CDEE79343F4746A2FEE8C60EBEC0BF-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--F3CDEE79343F4746A2FEE8C60EBEC0BF-->  
<SUGGESTIONTEXTMATCHSTYLE><![CDATA[startsWith]]></SUGGESTIONTEXTMATCHSTYLE>
diff -r 66762e6a74d2 -r 092bf17c3613 
src-test/src/org/openbravo/test/costing/TestCosting.java
--- a/src-test/src/org/openbravo/test/costing/TestCosting.java  Thu Aug 13 
10:33:36 2015 +0200
+++ b/src-test/src/org/openbravo/test/costing/TestCosting.java  Thu Aug 13 
12:03:24 2015 +0200
@@ -11047,7 +11047,7 @@
       String type = "application/json;charset=UTF-8";
       String response = doRequest(url, content, 200, "POST", type);
       if (error == null) {
-        assertFalse(response.contains("success"));
+        assertTrue(response.contains("success"));
         assertFalse(response.contains("error"));
       } else {
         assertTrue(response.contains(error));
diff -r 66762e6a74d2 -r 092bf17c3613 
src/org/openbravo/costing/LCMatchingCancelHandler.java
--- a/src/org/openbravo/costing/LCMatchingCancelHandler.java    Thu Aug 13 
10:33:36 2015 +0200
+++ b/src/org/openbravo/costing/LCMatchingCancelHandler.java    Thu Aug 13 
12:03:24 2015 +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) 2014 Openbravo SLU
+ * All portions are Copyright (C) 2014-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -97,9 +97,12 @@
     JSONObject message = new JSONObject();
     if (lcCost.getMatchingCostAdjustment() != null) {
       message = 
CancelCostAdjustment.doCancelCostAdjustment(lcCost.getMatchingCostAdjustment());
-      lcCost = OBDal.getInstance().get(LandedCostCost.class, strLcCostId);
-      doDeleteReceiptLineAmtMatched(lcCost);
+    } else {
+      message.put("severity", "success");
+      message.put("title", OBMessageUtils.messageBD("Success"));
     }
+    lcCost = OBDal.getInstance().get(LandedCostCost.class, strLcCostId);
+    doDeleteReceiptLineAmtMatched(lcCost);
 
     // Reload in case the cancel cost adjustment has cleared the session.
     lcCost = OBDal.getInstance().get(LandedCostCost.class, strLcCostId);
diff -r 66762e6a74d2 -r 092bf17c3613 
src/org/openbravo/costing/LCMatchingProcess.java
--- a/src/org/openbravo/costing/LCMatchingProcess.java  Thu Aug 13 10:33:36 
2015 +0200
+++ b/src/org/openbravo/costing/LCMatchingProcess.java  Thu Aug 13 12:03:24 
2015 +0200
@@ -27,6 +27,7 @@
 import javax.enterprise.inject.Instance;
 import javax.inject.Inject;
 
+import org.apache.commons.lang.StringUtils;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
 import org.hibernate.Query;
@@ -41,6 +42,7 @@
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
+import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.model.materialmgmt.cost.CostAdjustment;
 import org.openbravo.model.materialmgmt.cost.CostAdjustmentLine;
 import org.openbravo.model.materialmgmt.cost.LCDistributionAlgorithm;
@@ -93,9 +95,17 @@
 
       if (lcCost.isMatchingAdjusted() && 
lcCost.getAmount().compareTo(matchedAmt) != 0) {
         distributeAmounts(lcCost);
-        String strMatchCAId = generateCostAdjustment(lcCost.getId(), message);
-        lcCost.setMatchingCostAdjustment((CostAdjustment) 
OBDal.getInstance().getProxy(
-            CostAdjustment.ENTITY_NAME, strMatchCAId));
+        lcCost = OBDal.getInstance().get(LandedCostCost.class, lcCost.getId());
+        // If active costing rule uses Standard Algorithm, cost adjustment 
will not be created
+        Organization org = OBContext.getOBContext()
+            .getOrganizationStructureProvider(lcCost.getClient().getId())
+            .getLegalEntity(lcCost.getOrganization());
+        if (!StringUtils.equals(CostingUtils.getCostDimensionRule(org, new 
Date())
+            .getCostingAlgorithm().getJavaClassName(), 
"org.openbravo.costing.StandardAlgorithm")) {
+          String strMatchCAId = generateCostAdjustment(lcCost.getId(), 
message);
+          lcCost.setMatchingCostAdjustment((CostAdjustment) 
OBDal.getInstance().getProxy(
+              CostAdjustment.ENTITY_NAME, strMatchCAId));
+        }
         OBDal.getInstance().save(lcCost);
       }
 
diff -r 66762e6a74d2 -r 092bf17c3613 
src/org/openbravo/costing/LandedCostProcess.java
--- a/src/org/openbravo/costing/LandedCostProcess.java  Thu Aug 13 10:33:36 
2015 +0200
+++ b/src/org/openbravo/costing/LandedCostProcess.java  Thu Aug 13 12:03:24 
2015 +0200
@@ -28,6 +28,7 @@
 import javax.enterprise.inject.Instance;
 import javax.inject.Inject;
 
+import org.apache.commons.lang.StringUtils;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
 import org.hibernate.Query;
@@ -48,6 +49,7 @@
 import org.openbravo.model.common.currency.ConversionRate;
 import org.openbravo.model.common.currency.ConversionRateDoc;
 import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.model.materialmgmt.cost.CostAdjustment;
 import org.openbravo.model.materialmgmt.cost.CostAdjustmentLine;
 import org.openbravo.model.materialmgmt.cost.LCDistributionAlgorithm;
@@ -94,14 +96,23 @@
       log.debug("Start Distribute Amounts");
       distributeAmounts(landedCost);
       log.debug("Start generateCostAdjustment");
-      CostAdjustment ca = generateCostAdjustment(landedCost.getId(), message);
 
       landedCost = OBDal.getInstance().get(LandedCost.class, 
landedCost.getId());
-      landedCost.setCostAdjustment(ca);
+
+      // If active costing rule uses Standard Algorithm, cost adjustment will 
not be created
+      Organization org = OBContext.getOBContext()
+          .getOrganizationStructureProvider(landedCost.getClient().getId())
+          .getLegalEntity(landedCost.getOrganization());
+      if (!StringUtils.equals(CostingUtils.getCostDimensionRule(org, new 
Date())
+          .getCostingAlgorithm().getJavaClassName(), 
"org.openbravo.costing.StandardAlgorithm")) {
+        CostAdjustment ca = generateCostAdjustment(landedCost.getId(), 
message);
+        landedCost.setCostAdjustment(ca);
+        message.put("documentNo", ca.getDocumentNo());
+      }
+
       landedCost.setDocumentStatus("CO");
       landedCost.setProcessed(Boolean.TRUE);
       OBDal.getInstance().save(landedCost);
-      message.put("documentNo", ca.getDocumentNo());
     } catch (JSONException ignore) {
     } finally {
       OBContext.restorePreviousMode();
diff -r 66762e6a74d2 -r 092bf17c3613 
src/org/openbravo/costing/ReactivateLandedCost.java
--- a/src/org/openbravo/costing/ReactivateLandedCost.java       Thu Aug 13 
10:33:36 2015 +0200
+++ b/src/org/openbravo/costing/ReactivateLandedCost.java       Thu Aug 13 
12:03:24 2015 +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) 2014 Openbravo SLU
+ * All portions are Copyright (C) 2014-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -74,12 +74,18 @@
   public static JSONObject doReactivateLandedCost(LandedCost landedCost) 
throws OBException,
       JSONException {
     String strLCostId = landedCost.getId();
+    JSONObject message = null;
 
-    JSONObject message = CancelCostAdjustment
-        .doCancelCostAdjustment(landedCost.getCostAdjustment());
-
-    if (!"success".equals(message.get("severity"))) {
-      return message;
+    // Cancel cost adjustment only if exists
+    if (landedCost.getCostAdjustment() != null) {
+      message = 
CancelCostAdjustment.doCancelCostAdjustment(landedCost.getCostAdjustment());
+      if (!"success".equals(message.get("severity"))) {
+        return message;
+      }
+    } else {
+      message = new JSONObject();
+      message.put("severity", "success");
+      message.put("title", OBMessageUtils.messageBD("Success"));
     }
 
     String strPartialMessage = "";
diff -r 66762e6a74d2 -r 092bf17c3613 
src/org/openbravo/erpCommon/ad_forms/DocLCCost.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocLCCost.java       Thu Aug 13 
10:33:36 2015 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLCCost.java       Thu Aug 13 
12:03:24 2015 +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) 2014 Openbravo SLU
+ * All portions are Copyright (C) 2014-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -24,14 +24,18 @@
 
 import javax.servlet.ServletException;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.costing.CostingUtils;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.model.common.currency.Currency;
+import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.model.materialmgmt.cost.LandedCostCost;
 
 public class DocLCCost extends AcctServer {
 
@@ -55,8 +59,8 @@
     super(AD_Client_ID, AD_Org_ID, connectionProvider);
   }
 
-  public void loadObjectFieldProvider(ConnectionProvider conn,
-      @SuppressWarnings("hiding") String AD_Client_ID, String Id) throws 
ServletException {
+  public void loadObjectFieldProvider(ConnectionProvider conn, 
@SuppressWarnings("hiding")
+  String AD_Client_ID, String Id) throws ServletException {
     setObjectFieldProvider(DocLCCostData.selectRegistro(conn, AD_Client_ID, 
Id));
   }
 
@@ -258,9 +262,24 @@
 
           ProductInfo p = new ProductInfo(line4.m_M_Product_ID, conn);
 
-          fact.createLine(line4, p.getAccount(ProductInfo.ACCTTYPE_P_Asset, 
as, conn),
-              line4.m_C_Currency_ID, amtCredit, amtDebit, Fact_Acct_Group_ID, 
nextSeqNo(SeqNo),
-              DocumentType, line4.m_DateAcct, null, conn);
+          // If transaction uses Standard Algorithm IPD account will be used, 
else Asset account
+          LandedCostCost landedCostCost = 
OBDal.getInstance().get(LandedCostCost.class,
+              line.m_TrxHeader_ID);
+          Organization org = OBContext.getOBContext()
+              
.getOrganizationStructureProvider(landedCostCost.getClient().getId())
+              .getLegalEntity(landedCostCost.getOrganization());
+          Account account = null;
+          if (StringUtils.equals(
+              CostingUtils.getCostDimensionRule(org, 
landedCostCost.getCreationDate())
+                  .getCostingAlgorithm().getJavaClassName(),
+              "org.openbravo.costing.StandardAlgorithm")) {
+            account = p.getAccount(ProductInfo.ACCTTYPE_P_IPV, as, conn);
+          } else {
+            account = p.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn);
+          }
+
+          fact.createLine(line4, account, line4.m_C_Currency_ID, amtCredit, 
amtDebit,
+              Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, 
line4.m_DateAcct, null, conn);
 
         }
 
diff -r 66762e6a74d2 -r 092bf17c3613 
src/org/openbravo/erpCommon/ad_forms/DocLandedCost.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocLandedCost.java   Thu Aug 13 
10:33:36 2015 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLandedCost.java   Thu Aug 13 
12:03:24 2015 +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) 2014 Openbravo SLU
+ * All portions are Copyright (C) 2014-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -24,11 +24,15 @@
 
 import javax.servlet.ServletException;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.SequenceIdData;
+import org.openbravo.model.materialmgmt.cost.LCReceiptLineAmt;

------------------------------------------------------------------------------
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to