Fixes issue 37850: Stock Valuation of 0 in Product - Unit Cost tab if product is
authorDavid Miguelez <david.miguelez@openbravo.com>
Fri, 23 Feb 2018 08:45:53 +0100
changeset 33548 4949275527c9
parent 33547 c4ccb5d59890
child 33601 4a1f3df29564
Fixes issue 37850: Stock Valuation of 0 in Product - Unit Cost tab if product is
received in a warehouse created after unit cost is calculated

When a new transaction increase the product stock in a warehouse and doesn't exist
a stock valuation record to this warehouse the M_Transaction_Cost trigger can't
set the valuation cost because the stock is 0.

The flush to M_Transaction when the cost is calculated trigger the M_Update_Stock_Valuation
with the correct stock quantity and then the M_Transaction_Cost trigger can set the
valuation cost to the Stock Valuation created in the M_Transaction trigger.
src/org/openbravo/costing/CostingServer.java
--- a/src/org/openbravo/costing/CostingServer.java	Thu Feb 22 17:13:18 2018 +0000
+++ b/src/org/openbravo/costing/CostingServer.java	Fri Feb 23 08:45:53 2018 +0100
@@ -121,9 +121,15 @@
         transaction.setCurrency(currency);
         transaction.setCostCalculated(true);
         transaction.setCostingStatus("CC");
+        // Flush the changes in the Transaction to fire the Triggers in the database before creating
+        // the TransactionCost. If not done here, the Trigger for the TransactionCost will be
+        // launched before the one in the Transaction generating wrong data in some tables
+        OBDal.getInstance().flush();
         // insert on m_transaction_cost
         createTransactionCost();
         updateLastTransaction();
+        // Flush the changes in the TransactionCost and in the Transaction to fire the Triggers in
+        // the database before doing Cost Adjustments
         OBDal.getInstance().flush();
 
         setNotPostedTransaction();