details:   https://code.openbravo.com/erp/devel/main/rev/41da1089077d
changeset: 25086:41da1089077d
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Wed Nov 05 13:43:25 2014 +0100
summary:   fixed bug 28085: FK drop down filters don't work on 
Organization/Client windows

  The problem was due the generated query, it applied client/organization 
security
  assuming organization and client were in another entities.

  The fix cheks these special cases to do the security query based on that base
  entities.

details:   https://code.openbravo.com/erp/devel/main/rev/15da04333c20
changeset: 25087:15da04333c20
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Wed Nov 05 13:49:09 2014 +0100
summary:   related to bug 28085: added test case

  test case covering FK drop down datasource in Organization table

details:   https://code.openbravo.com/erp/devel/main/rev/bbb2d1af75d9
changeset: 25088:bbb2d1af75d9
user:      Augusto Mauch <augusto.mauch <at> openbravo.com>
date:      Thu Nov 06 17:53:38 2014 +0100
summary:   Fixes issue 28099: '.' works as date separator

If a dot was used as date separator, the dates were shown empty in the UI. This 
was caused by this implementation of the isSeparator function:

  isSeparator: function (str, position) {
    return str.charAt(position) === '-' || str.charAt(position) === '\\' || 
str.charAt(position) === '/';
  },

The list of possible separators was hardcoded, and it did not take into the 
account the dot. This has been fixed by also checking the value returned by the 
OB.Utilities.Date.getDateSeparator function, that given a date format it 
returns its separator.

details:   https://code.openbravo.com/erp/devel/main/rev/1792be8ea532
changeset: 25089:1792be8ea532
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Thu Oct 30 18:57:32 2014 +0100
summary:   Fixes issue 28029: Negative Stock Correction adjustments not marked 
as Unit Cost

details:   https://code.openbravo.com/erp/devel/main/rev/19f3c1ff3434
changeset: 25090:19f3c1ff3434
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Thu Oct 30 19:39:59 2014 +0100
summary:   Fixes issue 27945: Remove Inventory Amount Update option from Landed 
Cost Window

The item in the ad_ref_list has been deactivated.

details:   https://code.openbravo.com/erp/devel/main/rev/12ddfeeb9f34
changeset: 25091:12ddfeeb9f34
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Tue Nov 04 10:20:30 2014 +0100
summary:   Fixes issue 28019: Recalculate the cost at the end of 
averageCostAdjustment

The extra lines in Costing tab in this case are correct, because there is an 
out transaction (movement from), and these transactions they dont modify the 
average cost.
Also, at the end of the Average Cost Adjustment the last cost has to be 
recalculated in order to prevent more out transactions with bad cost until 
another in transaction happens that recalculates the cost.

details:   https://code.openbravo.com/erp/devel/main/rev/878e435bebab
changeset: 25092:878e435bebab
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Tue Nov 04 17:55:30 2014 +0100
summary:   Related to issue 28029: Prevent extra negative stock adjustment line

AverageCostAdjustment it was creating an extra negative stock adjustment line 
when there was already an adjustment line of negative stock. This was happening 
on a receipt with previuos stock in negative, that leaves the stock still in 
negative after the completion of the receipt.
To prevent this and extra check has been added in AverageCostAdjustment: If 
baseCAL is of type negative stock, then dont add a new negative stock line.

details:   https://code.openbravo.com/erp/devel/main/rev/c48f330efd55
changeset: 25093:c48f330efd55
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Fri Nov 07 13:36:16 2014 +0100
summary:   Fixes Issue 28114: Remove cost re-calculation related to output 
transactions

The cost recalculation related to adjustments on output transactions has been 
removed because it was causing amounts rounding issues and because of this 
extra records in Costing tab were being created. This recalculation was being 
doing because of reported issue 28019.

details:   https://code.openbravo.com/erp/devel/main/rev/d261feca402e
changeset: 25094:d261feca402e
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Mon Nov 10 16:01:05 2014 +0100
summary:   Related to issue 27966: LCCost should be init. in the beginning of 
the process

details:   https://code.openbravo.com/erp/devel/main/rev/803569a1bc95
changeset: 25095:803569a1bc95
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Tue Nov 11 09:54:03 2014 +0100
summary:   Fixes Issue 28121: Used Costing Precision instead of Standard 
Precision in LC

In Distribution by Amount Algorithm of Landed Cost, Costing Precision should be 
used instead of Standard Precision. The recommended Costing Precision is 4.
Also the Line No. of Cost Adjustment Lines has been fixed when creating a 
Landed Cost Adjustment.

details:   https://code.openbravo.com/erp/devel/main/rev/07f8935fe976
changeset: 25096:07f8935fe976
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Tue Nov 11 10:00:36 2014 +0100
summary:   Fixes Bug 27998: Negative Stock Correction adjustments now are 
properly created

Due to Issue 27946, each time that an adjustment is created it is checked if a 
Negative Stock Correction adjustment is needed, and if so, it is created. So 
now, in Costing Server, before creating any Negative Stock Correction it is 
checked if another Cost Adjustment has been created, and if it is, this step is 
skipped.

details:   https://code.openbravo.com/erp/devel/main/rev/9e656be29ab5
changeset: 25097:9e656be29ab5
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Tue Nov 11 17:20:36 2014 +0100
summary:   Fixes bug 28113: Use costing Price to calculate Adjustment Amount

In some cases the transaction price it was not being properly calculated in 
order to calculate the negative stock correction amounts. Starting from now the 
Net Unit Price field of Costing tab will be used in Cost Adjustments. To get 
the transaction price this Net Unit Price will be used.

details:   https://code.openbravo.com/erp/devel/main/rev/0fd1ee2ea44f
changeset: 25098:0fd1ee2ea44f
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Wed Nov 12 11:56:25 2014 +0100
summary:   Related to Issue 28113: Add some missing currency roundings

details:   https://code.openbravo.com/erp/devel/main/rev/0de23f5bc94c
changeset: 25099:0de23f5bc94c
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Wed Nov 12 12:19:40 2014 +0100
summary:   Fixes Bug 28115: Is Cost Permanent transactions added as input in 
Costing tab

details:   https://code.openbravo.com/erp/devel/main/rev/ce0b69914bd3
changeset: 25100:ce0b69914bd3
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Wed Nov 12 13:14:57 2014 +0100
summary:   Fixes Bug 28148: Landed Cost Adjustment Lines created ordered by 
trxprocessdate

details:   https://code.openbravo.com/erp/devel/main/rev/a3bb9ecd7fa1
changeset: 25101:a3bb9ecd7fa1
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Thu Nov 13 12:46:25 2014 +0100
summary:   Related to Issue 28115: Fix recal of trxPrice in M_Costing

details:   https://code.openbravo.com/erp/devel/main/rev/589a0a49bf28
changeset: 25102:589a0a49bf28
user:      Unai Martirena <unai.martirena <at> openbravo.com>
date:      Thu Nov 13 12:48:51 2014 +0100
summary:   Related to Issue 28115: Set isPermanent true when Costing is 
permanent

details:   https://code.openbravo.com/erp/devel/main/rev/f0602f463b1d
changeset: 25103:f0602f463b1d
user:      Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date:      Thu Nov 13 10:52:31 2014 +0100
summary:   Related to issue 28155.Related to issue 28157.Use conversionRateDocs

Some documents might include custom conversion rates. The FinancialUtils
utility class is extended with a new method that receives a List of rates
defined at document level. The existing method now calls the new one setting
an empty list on the new parameter.

details:   https://code.openbravo.com/erp/devel/main/rev/f2034dcb2bf4
changeset: 25104:f2034dcb2bf4
user:      Gorka Ion Damián <gorkaion.damian <at> openbravo.com>
date:      Thu Nov 13 11:01:31 2014 +0100
summary:   Fixed issue 28155. Use custom conversion rate of documents.

Use new getConvertedAmount with the list of conversion rated defined for the
invoice.
Create a Invoice object to ease method readability.

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js
 |    4 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
    |    9 +
 
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
                        |   24 +-
 src-db/database/sourcedata/AD_REF_LIST.xml                                     
                                    |    2 +-
 src-test/src/org/openbravo/test/AllWebserviceTests.java                        
                                    |    4 +-
 src-test/src/org/openbravo/test/datasource/FKDropDownDatasource.java           
                                    |   61 +++
 src/org/openbravo/costing/AverageCostAdjustment.java                           
                                    |  165 ++++++---
 src/org/openbravo/costing/CostingServer.java                                   
                                    |   14 +-
 src/org/openbravo/costing/LandedCostDistributionByAmount.java                  
                                    |    4 +-
 src/org/openbravo/costing/LandedCostProcess.java                               
                                    |    7 +
 src/org/openbravo/costing/PriceDifferenceProcess.java                          
                                    |   18 +-
 src/org/openbravo/financial/FinancialUtils.java                                
                                    |   49 ++-
 12 files changed, 285 insertions(+), 76 deletions(-)

diffs (truncated from 704 to 300 lines):

diff -r 6ba7ca08c0d7 -r f2034dcb2bf4 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js
        Fri Nov 14 08:41:21 2014 +0000
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js
        Thu Nov 13 11:01:31 2014 +0100
@@ -52,7 +52,7 @@
 
     dateFormatUpper = this.dateFormat.toUpperCase();
     length = dateFormatUpper.length;
-    this.dateSeparator = this.dateFormat.toUpperCase().replace(/D/g, 
'').replace(/M/g, '').replace(/Y/g, '').substr(0, 1);
+    this.dateSeparator = OB.Utilities.Date.getDateSeparator(this.dateFormat);
 
     for (i = 0; i < length; i++) {
       if (this.isSeparator(dateFormatUpper, i)) {
@@ -224,7 +224,7 @@
   },
 
   isSeparator: function (str, position) {
-    return str.charAt(position) === '-' || str.charAt(position) === '\\' || 
str.charAt(position) === '/';
+    return str.charAt(position) === '-' || str.charAt(position) === '\\' || 
str.charAt(position) === '/' || str.charAt(position) === 
OB.Utilities.Date.getDateSeparator(OB.Format.date);
   },
 
   hasSeparator: function (str) {
diff -r 6ba7ca08c0d7 -r f2034dcb2bf4 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
   Fri Nov 14 08:41:21 2014 +0000
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
   Thu Nov 13 11:01:31 2014 +0100
@@ -473,4 +473,13 @@
     newDate.setHours(newDate.getHours() + 1);
   }
   return newDate;
+};
+
+//** {{{ OB.Utilities.Date.getDateSeparator }}} **
+//
+// Returns the date separator
+OB.Utilities.Date.getDateSeparator = function (dateFormat) {
+  // obtains the date separator by selecting the first characters that is not 
'D', 'M' or 'Y'
+  return dateFormat.toUpperCase().replace(/D/g, '').replace(/M/g, 
'').replace(/Y/g, '').substr(0, 1);
+
 };
\ No newline at end of file
diff -r 6ba7ca08c0d7 -r f2034dcb2bf4 
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
--- 
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
       Fri Nov 14 08:41:21 2014 +0000
+++ 
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
       Thu Nov 13 11:01:31 2014 +0100
@@ -54,7 +54,9 @@
 import org.openbravo.model.ad.datamodel.Table;
 import org.openbravo.model.ad.domain.Reference;
 import org.openbravo.model.ad.domain.ReferencedTable;
+import org.openbravo.model.ad.system.Client;
 import org.openbravo.model.ad.ui.Tab;
+import org.openbravo.model.common.enterprise.Organization;
 import org.openbravo.service.db.DalConnectionProvider;
 
 /**
@@ -216,9 +218,27 @@
 
     if (subEntity != null) {
       // if there's subentity, process it as a subquery with "exists"
-      String subEntityClientOrg = " and e.organization.id "
+
+      String orgPath;
+      if (subEntity.getMappingClass().isAssignableFrom(Organization.class)) {
+        // special case subentity is Organization, so no extra path required 
to get it
+        orgPath = "e";
+      } else {
+        orgPath = "e.organization";
+      }
+
+      String subEntityClientOrg = " and " + orgPath + ".id "
           + 
createInClause(OBContext.getOBContext().getReadableOrganizations());
-      subEntityClientOrg += " and e.client.id "
+
+      String clientPath;
+      if (subEntity.getMappingClass().isAssignableFrom(Client.class)) {
+        // special case subentity is Client, so no extra path required to get 
it
+        clientPath = "e";
+      } else {
+        clientPath = "e.client";
+      }
+
+      subEntityClientOrg += " and " + clientPath + ".id "
           + createInClause(OBContext.getOBContext().getReadableClients());
 
       AdvancedQueryBuilder subEntityQueryBuilder = 
subDataEntityQueryService.getQueryBuilder();
diff -r 6ba7ca08c0d7 -r f2034dcb2bf4 src-db/database/sourcedata/AD_REF_LIST.xml
--- a/src-db/database/sourcedata/AD_REF_LIST.xml        Fri Nov 14 08:41:21 
2014 +0000
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml        Thu Nov 13 11:01:31 
2014 +0100
@@ -9974,7 +9974,7 @@
 <!--78ED41661F55422786E4109B62FCC5D0-->  
<AD_REF_LIST_ID><![CDATA[78ED41661F55422786E4109B62FCC5D0]]></AD_REF_LIST_ID>
 <!--78ED41661F55422786E4109B62FCC5D0-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
 <!--78ED41661F55422786E4109B62FCC5D0-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
-<!--78ED41661F55422786E4109B62FCC5D0-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--78ED41661F55422786E4109B62FCC5D0-->  <ISACTIVE><![CDATA[N]]></ISACTIVE>
 <!--78ED41661F55422786E4109B62FCC5D0-->  <VALUE><![CDATA[IAU]]></VALUE>
 <!--78ED41661F55422786E4109B62FCC5D0-->  <NAME><![CDATA[Inventory Amount 
Update]]></NAME>
 <!--78ED41661F55422786E4109B62FCC5D0-->  
<AD_REFERENCE_ID><![CDATA[EB3568484660488FA112CBBB2C1D2780]]></AD_REFERENCE_ID>
diff -r 6ba7ca08c0d7 -r f2034dcb2bf4 
src-test/src/org/openbravo/test/AllWebserviceTests.java
--- a/src-test/src/org/openbravo/test/AllWebserviceTests.java   Fri Nov 14 
08:41:21 2014 +0000
+++ b/src-test/src/org/openbravo/test/AllWebserviceTests.java   Thu Nov 13 
11:01:31 2014 +0100
@@ -21,6 +21,7 @@
 
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
+import org.openbravo.test.datasource.FKDropDownDatasource;
 import org.openbravo.test.datasource.ProductSelectorDataSourceTest;
 import org.openbravo.test.datasource.SelectorFieldPropertySelectorDSTest;
 import org.openbravo.test.datasource.TestCSVEncoding;
@@ -46,6 +47,7 @@
     TestCSVEncoding.class, //
     SelectorFieldPropertySelectorDSTest.class, //
     ProductSelectorDataSourceTest.class, //
-    TestComboDatasource.class })
+    TestComboDatasource.class, //
+    FKDropDownDatasource.class })
 public class AllWebserviceTests {
 }
diff -r 6ba7ca08c0d7 -r f2034dcb2bf4 
src-test/src/org/openbravo/test/datasource/FKDropDownDatasource.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/test/datasource/FKDropDownDatasource.java      
Thu Nov 13 11:01:31 2014 +0100
@@ -0,0 +1,61 @@
+/*
+ *************************************************************************
+ * 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) 2014 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.datasource;
+
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.codehaus.jettison.json.JSONObject;
+import org.junit.Test;
+
+/**
+ * Test cases to check behavior of FK filter drop downs
+ * 
+ * @author alostale
+ *
+ */
+public class FKDropDownDatasource extends BaseDataSourceTestNoDal {
+
+  /**
+   * Drop down FK filter in Organization dataset is a special case because org 
filtering must be
+   * done in the base entity.
+   * 
+   * See issue 28085
+   */
+  @Test
+  public void filterFKInOrganization() throws Exception {
+    Map<String, String> params = new HashMap<String, String>();
+
+    params.put("tabId", "143");
+    params.put("_distinct", "organizationType");
+    params.put("_operationType", "fetch");
+    params.put("_startRow", "0");
+    params.put("_endRow", "75");
+    JSONObject resp = new 
JSONObject(doRequest("/org.openbravo.service.datasource/Organization",
+        params, 200, "POST")).getJSONObject("response");
+
+    assertThat("response status", resp.getInt("status"), is(0));
+    assertThat("number of rows", resp.getInt("totalRows"), greaterThan(0));
+  }
+}
diff -r 6ba7ca08c0d7 -r f2034dcb2bf4 
src/org/openbravo/costing/AverageCostAdjustment.java
--- a/src/org/openbravo/costing/AverageCostAdjustment.java      Fri Nov 14 
08:41:21 2014 +0000
+++ b/src/org/openbravo/costing/AverageCostAdjustment.java      Thu Nov 13 
11:01:31 2014 +0100
@@ -127,12 +127,13 @@
           RoundingMode.HALF_UP);
     }
     log.debug("Starting average cost {}", cost == null ? "not cost" : 
cost.toPlainString());
-    if (AverageAlgorithm.modifiesAverage(trxType) && cost != null) {
+    if (cost != null && (AverageAlgorithm.modifiesAverage(trxType) || 
!baseCAL.isBackdatedTrx())) {
       BigDecimal trxCost = CostAdjustmentUtils.getTrxCost(basetrx, false, 
getCostCurrency());
-      BigDecimal trxPrice = trxCost.add(adjustmentBalance).divide(
+      BigDecimal trxPrice = 
trxCost.add(adjustmentBalance.multiply(signMultiplier)).divide(
           basetrx.getMovementQuantity().abs(), costCurPrecission, 
RoundingMode.HALF_UP);
       if (checkNegativeStockCorrection && 
currentStock.compareTo(basetrx.getMovementQuantity()) < 0
-          && cost.compareTo(trxPrice) != 0) {
+          && cost.compareTo(trxPrice) != 0 && 
!baseCAL.isNegativeStockCorrection()
+          && AverageAlgorithm.modifiesAverage(trxType)) {
         // stock was negative and cost different than trx price then Negative 
Stock Correction
         // is added
         BigDecimal trxSignMultiplier = new 
BigDecimal(basetrx.getMovementQuantity().signum());
@@ -142,29 +143,62 @@
         adjustmentBalance = 
adjustmentBalance.add(negCorrAmt.multiply(trxSignMultiplier));
         // If there is a difference insert a cost adjustment line.
         CostAdjustmentLine newCAL = insertCostAdjustmentLine(basetrx, 
negCorrAmt, null);
-        newCAL.setNegativeStockCorrection(true);
-        newCAL.setRelatedTransactionAdjusted(true);
+        newCAL.setNegativeStockCorrection(Boolean.TRUE);
+        newCAL.setRelatedTransactionAdjusted(Boolean.TRUE);
         newCAL.setUnitCost(Boolean.FALSE);
         OBDal.getInstance().save(newCAL);
         cost = trxPrice;
         log.debug("Negative stock correction. Amount: {}, new cost {}", 
negCorrAmt.toPlainString(),
             cost.toPlainString());
       }
+      if (basetrx.getMaterialMgmtCostingList().size() == 0) {
+        Date newDate = new Date();
+        Date dateTo = costing.getEndingDate();
+        costing.setEndingDate(newDate);
+        OBDal.getInstance().save(costing);
+        Costing newCosting = OBProvider.getInstance().get(Costing.class);
+        newCosting.setCost(cost);
+        newCosting.setCurrency((Currency) 
OBDal.getInstance().getProxy(Currency.ENTITY_NAME,
+            strCostCurrencyId));
+        newCosting.setStartingDate(newDate);
+        newCosting.setEndingDate(dateTo);
+        newCosting.setInventoryTransaction(basetrx);
+        newCosting.setProduct(basetrx.getProduct());
+        if (isManufacturingProduct) {
+          newCosting.setOrganization((Organization) 
OBDal.getInstance().getProxy(
+              Organization.ENTITY_NAME, "0"));
+        } else {
+          newCosting.setOrganization((Organization) 
OBDal.getInstance().getProxy(
+              Organization.ENTITY_NAME, strCostOrgId));
+        }
+        newCosting.setQuantity(basetrx.getMovementQuantity());
+        newCosting.setTotalMovementQuantity(currentStock);
+        newCosting.setPrice(trxPrice);
+        newCosting.setCostType("AVA");
+        newCosting.setManual(Boolean.FALSE);
+        newCosting.setPermanent(Boolean.TRUE);
+        newCosting.setProduction(trxType == TrxType.ManufacturingProduced);
+        newCosting.setWarehouse((Warehouse) 
getCostDimensions().get(CostDimension.Warehouse));
+        OBDal.getInstance().save(newCosting);
+        OBDal.getInstance().flush();
+      } else {
+        Costing curCosting = basetrx.getMaterialMgmtCostingList().get(0);
+        if (curCosting.getCost().compareTo(cost) != 0) {
+          // Update existing costing
+          curCosting.setPermanent(Boolean.FALSE);
+          OBDal.getInstance().save(curCosting);
+          OBDal.getInstance().flush();
+          if (curCosting.getOriginalCost() == null) {
+            curCosting.setOriginalCost(curCosting.getCost());
+          }
+          curCosting.setCost(cost);
+          curCosting.setPrice(trxPrice);
+          curCosting.setPermanent(Boolean.TRUE);
+          OBDal.getInstance().flush();
+          OBDal.getInstance().save(curCosting);
+        }
+      }
 
-      Costing curCosting = basetrx.getMaterialMgmtCostingList().get(0);
-      if (curCosting.getCost().compareTo(cost) != 0) {
-        // Update existing costing
-        curCosting.setPermanent(Boolean.FALSE);
-        OBDal.getInstance().save(curCosting);
-        OBDal.getInstance().flush();
-        if (curCosting.getOriginalCost() == null) {
-          curCosting.setOriginalCost(curCosting.getCost());
-        }
-        curCosting.setCost(cost);
-        curCosting.setPermanent(Boolean.TRUE);
-        OBDal.getInstance().flush();
-        OBDal.getInstance().save(curCosting);
-      }
     }
 
     // Modify isManufacturingProduct flag in case it has changed at some point.
@@ -245,8 +279,10 @@
             continue;
           }
           log.debug("New average cost: {}", cost.toPlainString());
-          BigDecimal trxPrice = 
trxCost.add(trxAdjAmt).divide(trx.getMovementQuantity().abs(),
-              costCurPrecission, RoundingMode.HALF_UP);
+          Costing curCosting = trx.getMaterialMgmtCostingList().get(0);
+          BigDecimal trxPrice = 
curCosting.getPrice().multiply(trx.getMovementQuantity().abs())
+              .add(trxAdjAmt)
+              .divide(trx.getMovementQuantity().abs(), costCurPrecission, 
RoundingMode.HALF_UP);
 
           if (checkNegativeStockCorrection && 
currentStock.compareTo(trx.getMovementQuantity()) < 0
               && cost.compareTo(trxPrice) != 0) {
@@ -259,8 +295,8 @@
             trxAdjAmt = trxAdjAmt.add(negCorrAmt.multiply(trxSignMultiplier));
             // If there is a difference insert a cost adjustment line.
             CostAdjustmentLine newCAL = insertCostAdjustmentLine(trx, 
negCorrAmt, null);
-            newCAL.setNegativeStockCorrection(true);
-            newCAL.setRelatedTransactionAdjusted(true);
+            newCAL.setNegativeStockCorrection(Boolean.TRUE);
+            newCAL.setRelatedTransactionAdjusted(Boolean.TRUE);
             newCAL.setUnitCost(Boolean.FALSE);

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to