Fixes issue 42092: Balanced posting when adjusting a return receipt
authorMark Molina <mark.molina@doceleguas.com>
Tue, 29 Oct 2019 21:42:45 -0300
changeset 36724 2e969cbadcac
parent 36723 085c0d82531f
child 36725 dcd5ec559020
Fixes issue 42092: Balanced posting when adjusting a return receipt

When a Goods Receipt Return was adjusted a balance in Warehouse Differences and
Invoice Price Variance account was generated. As only the cost adjustments generated
by Price Difference Correction process are posted on the Invoice Price Difference account
all other adjustments done to receipts are posted on Warehouse Differences account.

The correct behaviour should be: If the adjustment is unit cost the account used should
be the Invoice Price Difference account independently of the cost adjustment source process.
src/org/openbravo/erpCommon/ad_forms/DocCostAdjustment.java
src/org/openbravo/erpCommon/ad_forms/DocLineCostAdjustment_data.xsql
src/org/openbravo/erpCommon/ad_forms/DocLine_CostAdjustment.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocCostAdjustment.java	Thu Nov 07 09:12:27 2019 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocCostAdjustment.java	Tue Oct 29 21:42:45 2019 -0300
@@ -107,6 +107,7 @@
         docLine.m_C_BPartner_ID = data[i].cBpartnerId;
         docLine.setSourceProcess(data[i].sourceProcess);
         docLine.setIsSource("Y".equals(data[i].issource));
+        docLine.setIsUnitCost("Y".equals(data[i].isunitcost));
         // -- Source Amounts
         String amt = data[i].adjustmentAmount;
         docLine.setAmount(amt);
@@ -209,8 +210,8 @@
       } else if (transactionType.equals(DocLine_CostAdjustment.TRXTYPE_RECEIPT)) {
         Account acct = null;
         // Inventory Asset DR
-        if (line.getIsSource() && ("PDC").equals(line.getSourceProcess())) { // Price Diff
-          // Correction
+        if (line.isUnitCost()) {
+          // Price Diff Correction
           // Invoice Price Variance CR
           acct = p.getAccount(ProductInfo.ACCTTYPE_P_IPV, as, conn);
         } else if (line.getIsSource() && ("LC").equals(line.getSourceProcess())) {
--- a/src/org/openbravo/erpCommon/ad_forms/DocLineCostAdjustment_data.xsql	Thu Nov 07 09:12:27 2019 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLineCostAdjustment_data.xsql	Tue Oct 29 21:42:45 2019 -0300
@@ -12,7 +12,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-2017 Openbravo SLU
+ * All portions are Copyright (C) 2014-2019 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -32,7 +32,7 @@
         CAL.M_COSTADJUSTMENT_ID, CAL.M_TRANSACTION_ID, CAL.ADJUSTMENT_AMOUNT, 
         CAL.ISSOURCE, CAL.NEEDSPOSTING, CAL.DATEACCT, CAL.ISRELATEDTRXADJUSTED, CAL.PARENT_COSTADJUSTMENTLINE_ID,
         T.M_PRODUCT_ID, L.M_WAREHOUSE_ID, CAL.C_CURRENCY_ID, CA.SOURCE_PROCESS AS SOURCE_PROCESS, 
-        IO.C_BPARTNER_ID AS C_BPARTNER_ID
+        IO.C_BPARTNER_ID AS C_BPARTNER_ID, CAL.ISUNITCOST
         FROM M_COSTADJUSTMENTLINE CAL, M_COSTADJUSTMENT CA, M_LOCATOR L, 
         M_TRANSACTION T LEFT JOIN M_INOUTLINE IOL ON T.M_INOUTLINE_ID = IOL.M_INOUTLINE_ID
                         LEFT JOIN M_INOUT IO ON IOL.M_INOUT_ID = IO.M_INOUT_ID
--- a/src/org/openbravo/erpCommon/ad_forms/DocLine_CostAdjustment.java	Thu Nov 07 09:12:27 2019 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLine_CostAdjustment.java	Tue Oct 29 21:42:45 2019 -0300
@@ -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-2019 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -46,6 +46,7 @@
   private String warehouseId;
   private String sourceProcess;
   private boolean isSource;
+  private boolean isUnitCost;
 
   public static final String TRXTYPE_SHIPMENT = "SMT";
   public static final String TRXTYPE_RECEIPT = "RCT";
@@ -203,6 +204,14 @@
     return transactionNegative;
   } // setAmounts
 
+  public boolean isUnitCost() {
+    return isUnitCost;
+  }
+
+  public void setIsUnitCost(boolean isUnitCost) {
+    this.isUnitCost = isUnitCost;
+  }
+
   /**
    * Line Account from Product (or Charge).
    *