[costAdj] Negative Stock Correction implementation
authorMiguel A. Alsasua <miguel.alsasua@openbravo.com>
Tue, 26 Aug 2014 15:08:12 +0200
changeset 24821 2e15f45c46c0
parent 24820 a3f691cbe0ef
child 24822 f08c52d2d396
[costAdj] Negative Stock Correction implementation
src-db/database/model/tables/M_COSTADJUSTMENTLINE.xml
src-db/database/sourcedata/AD_COLUMN.xml
src-db/database/sourcedata/AD_ELEMENT.xml
src-db/database/sourcedata/AD_FIELD.xml
src-db/database/sourcedata/AD_REF_LIST.xml
src/org/openbravo/costing/AverageCostAdjustment.java
src/org/openbravo/costing/CostingAlgorithmAdjustmentImp.java
src/org/openbravo/costing/CostingServer.java
src/org/openbravo/costing/CostingUtils.java
src/org/openbravo/costing/StandardCostAdjustment.java
--- a/src-db/database/model/tables/M_COSTADJUSTMENTLINE.xml	Tue Aug 26 08:26:56 2014 +0200
+++ b/src-db/database/model/tables/M_COSTADJUSTMENTLINE.xml	Tue Aug 26 15:08:12 2014 +0200
@@ -81,6 +81,14 @@
         <default><![CDATA[Y]]></default>
         <onCreateDefault><![CDATA['Y']]></onCreateDefault>
       </column>
+      <column name="ISBACKDATEDTRX" primaryKey="false" required="false" type="CHAR" size="1" autoIncrement="false">
+        <default><![CDATA[N]]></default>
+        <onCreateDefault/>
+      </column>
+      <column name="ISNEGATIVESTOCKCORRECTION" primaryKey="false" required="false" type="CHAR" size="1" autoIncrement="false">
+        <default><![CDATA[N]]></default>
+        <onCreateDefault/>
+      </column>
       <foreign-key foreignTable="C_CURRENCY" name="C_COSTADJLINE_C_CURRENCY">
         <reference local="C_CURRENCY_ID" foreign="C_CURRENCY_ID"/>
       </foreign-key>
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Tue Aug 26 08:26:56 2014 +0200
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Tue Aug 26 15:08:12 2014 +0200
@@ -242649,6 +242649,40 @@
 <!--537CBE50378747DC854D9CDFDDC96E59-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--537CBE50378747DC854D9CDFDDC96E59--></AD_COLUMN>
 
+<!--5388EC611F144C0FAE99BC692551E180--><AD_COLUMN>
+<!--5388EC611F144C0FAE99BC692551E180-->  <AD_COLUMN_ID><![CDATA[5388EC611F144C0FAE99BC692551E180]]></AD_COLUMN_ID>
+<!--5388EC611F144C0FAE99BC692551E180-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--5388EC611F144C0FAE99BC692551E180-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--5388EC611F144C0FAE99BC692551E180-->  <NAME><![CDATA[Is Backdated Trx]]></NAME>
+<!--5388EC611F144C0FAE99BC692551E180-->  <COLUMNNAME><![CDATA[Isbackdatedtrx]]></COLUMNNAME>
+<!--5388EC611F144C0FAE99BC692551E180-->  <AD_TABLE_ID><![CDATA[34E79323CEC847C2A9ED2C8430AC73D1]]></AD_TABLE_ID>
+<!--5388EC611F144C0FAE99BC692551E180-->  <AD_REFERENCE_ID><![CDATA[20]]></AD_REFERENCE_ID>
+<!--5388EC611F144C0FAE99BC692551E180-->  <FIELDLENGTH><![CDATA[1]]></FIELDLENGTH>
+<!--5388EC611F144C0FAE99BC692551E180-->  <DEFAULTVALUE><![CDATA[N]]></DEFAULTVALUE>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--5388EC611F144C0FAE99BC692551E180-->  <SEQNO><![CDATA[210]]></SEQNO>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--5388EC611F144C0FAE99BC692551E180-->  <AD_ELEMENT_ID><![CDATA[8B75148375784C6CA79F9ED69828D9F0]]></AD_ELEMENT_ID>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--5388EC611F144C0FAE99BC692551E180-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--5388EC611F144C0FAE99BC692551E180-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--5388EC611F144C0FAE99BC692551E180-->  <POSITION><![CDATA[21]]></POSITION>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--5388EC611F144C0FAE99BC692551E180-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--5388EC611F144C0FAE99BC692551E180-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--5388EC611F144C0FAE99BC692551E180-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--5388EC611F144C0FAE99BC692551E180--></AD_COLUMN>
+
 <!--5395A0F40CD24B91A64BF7DC1FC6C202--><AD_COLUMN>
 <!--5395A0F40CD24B91A64BF7DC1FC6C202-->  <AD_COLUMN_ID><![CDATA[5395A0F40CD24B91A64BF7DC1FC6C202]]></AD_COLUMN_ID>
 <!--5395A0F40CD24B91A64BF7DC1FC6C202-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -290800,6 +290834,40 @@
 <!--8D0DC9E1C9F5B172E040007F01012587-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
 <!--8D0DC9E1C9F5B172E040007F01012587--></AD_COLUMN>
 
+<!--8D1A87A0EA3F413F90E00086A2C38F2A--><AD_COLUMN>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <AD_COLUMN_ID><![CDATA[8D1A87A0EA3F413F90E00086A2C38F2A]]></AD_COLUMN_ID>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <NAME><![CDATA[Is Negative Stock Correction]]></NAME>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <COLUMNNAME><![CDATA[Isnegativestockcorrection]]></COLUMNNAME>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <AD_TABLE_ID><![CDATA[34E79323CEC847C2A9ED2C8430AC73D1]]></AD_TABLE_ID>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <AD_REFERENCE_ID><![CDATA[20]]></AD_REFERENCE_ID>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <FIELDLENGTH><![CDATA[1]]></FIELDLENGTH>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <DEFAULTVALUE><![CDATA[N]]></DEFAULTVALUE>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISKEY><![CDATA[N]]></ISKEY>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISPARENT><![CDATA[N]]></ISPARENT>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISMANDATORY><![CDATA[N]]></ISMANDATORY>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISUPDATEABLE><![CDATA[Y]]></ISUPDATEABLE>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISIDENTIFIER><![CDATA[N]]></ISIDENTIFIER>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <SEQNO><![CDATA[220]]></SEQNO>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISTRANSLATED><![CDATA[N]]></ISTRANSLATED>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISSELECTIONCOLUMN><![CDATA[N]]></ISSELECTIONCOLUMN>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <AD_ELEMENT_ID><![CDATA[283F24933D6F4F989B13C66D6AEE6B3E]]></AD_ELEMENT_ID>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISSESSIONATTR><![CDATA[N]]></ISSESSIONATTR>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISSECONDARYKEY><![CDATA[N]]></ISSECONDARYKEY>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISDESENCRYPTABLE><![CDATA[N]]></ISDESENCRYPTABLE>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <DEVELOPMENTSTATUS><![CDATA[RE]]></DEVELOPMENTSTATUS>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <POSITION><![CDATA[22]]></POSITION>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISTRANSIENT><![CDATA[N]]></ISTRANSIENT>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISAUTOSAVE><![CDATA[Y]]></ISAUTOSAVE>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <VALIDATEONNEW><![CDATA[Y]]></VALIDATEONNEW>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <IMAGESIZEVALUESACTION><![CDATA[N]]></IMAGESIZEVALUESACTION>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A-->  <ISUSEDSEQUENCE><![CDATA[N]]></ISUSEDSEQUENCE>
+<!--8D1A87A0EA3F413F90E00086A2C38F2A--></AD_COLUMN>
+
 <!--8D34A048C2274A2581074DB0418AE215--><AD_COLUMN>
 <!--8D34A048C2274A2581074DB0418AE215-->  <AD_COLUMN_ID><![CDATA[8D34A048C2274A2581074DB0418AE215]]></AD_COLUMN_ID>
 <!--8D34A048C2274A2581074DB0418AE215-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_ELEMENT.xml	Tue Aug 26 08:26:56 2014 +0200
+++ b/src-db/database/sourcedata/AD_ELEMENT.xml	Tue Aug 26 15:08:12 2014 +0200
@@ -21472,6 +21472,18 @@
 <!--271064362EBE4E0AA76CE3A26D1253E2-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
 <!--271064362EBE4E0AA76CE3A26D1253E2--></AD_ELEMENT>
 
+<!--283F24933D6F4F989B13C66D6AEE6B3E--><AD_ELEMENT>
+<!--283F24933D6F4F989B13C66D6AEE6B3E-->  <AD_ELEMENT_ID><![CDATA[283F24933D6F4F989B13C66D6AEE6B3E]]></AD_ELEMENT_ID>
+<!--283F24933D6F4F989B13C66D6AEE6B3E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--283F24933D6F4F989B13C66D6AEE6B3E-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--283F24933D6F4F989B13C66D6AEE6B3E-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--283F24933D6F4F989B13C66D6AEE6B3E-->  <COLUMNNAME><![CDATA[Isnegativestockcorrection]]></COLUMNNAME>
+<!--283F24933D6F4F989B13C66D6AEE6B3E-->  <NAME><![CDATA[Is Negative Stock Correction]]></NAME>
+<!--283F24933D6F4F989B13C66D6AEE6B3E-->  <PRINTNAME><![CDATA[Is Negative Stock Correction]]></PRINTNAME>
+<!--283F24933D6F4F989B13C66D6AEE6B3E-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--283F24933D6F4F989B13C66D6AEE6B3E-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
+<!--283F24933D6F4F989B13C66D6AEE6B3E--></AD_ELEMENT>
+
 <!--289767DD703142019B02C7D17AADF16F--><AD_ELEMENT>
 <!--289767DD703142019B02C7D17AADF16F-->  <AD_ELEMENT_ID><![CDATA[289767DD703142019B02C7D17AADF16F]]></AD_ELEMENT_ID>
 <!--289767DD703142019B02C7D17AADF16F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -28205,6 +28217,18 @@
 <!--8B70020E54854A83811D5B65DDADC8BE-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
 <!--8B70020E54854A83811D5B65DDADC8BE--></AD_ELEMENT>
 
+<!--8B75148375784C6CA79F9ED69828D9F0--><AD_ELEMENT>
+<!--8B75148375784C6CA79F9ED69828D9F0-->  <AD_ELEMENT_ID><![CDATA[8B75148375784C6CA79F9ED69828D9F0]]></AD_ELEMENT_ID>
+<!--8B75148375784C6CA79F9ED69828D9F0-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--8B75148375784C6CA79F9ED69828D9F0-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--8B75148375784C6CA79F9ED69828D9F0-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--8B75148375784C6CA79F9ED69828D9F0-->  <COLUMNNAME><![CDATA[Isbackdatedtrx]]></COLUMNNAME>
+<!--8B75148375784C6CA79F9ED69828D9F0-->  <NAME><![CDATA[Is Backdated Trx]]></NAME>
+<!--8B75148375784C6CA79F9ED69828D9F0-->  <PRINTNAME><![CDATA[Is Backdated Trx]]></PRINTNAME>
+<!--8B75148375784C6CA79F9ED69828D9F0-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--8B75148375784C6CA79F9ED69828D9F0-->  <ISGLOSSARY><![CDATA[N]]></ISGLOSSARY>
+<!--8B75148375784C6CA79F9ED69828D9F0--></AD_ELEMENT>
+
 <!--8BCFEC1D2693D1A8E040007F010135A9--><AD_ELEMENT>
 <!--8BCFEC1D2693D1A8E040007F010135A9-->  <AD_ELEMENT_ID><![CDATA[8BCFEC1D2693D1A8E040007F010135A9]]></AD_ELEMENT_ID>
 <!--8BCFEC1D2693D1A8E040007F010135A9-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_FIELD.xml	Tue Aug 26 08:26:56 2014 +0200
+++ b/src-db/database/sourcedata/AD_FIELD.xml	Tue Aug 26 15:08:12 2014 +0200
@@ -186960,6 +186960,32 @@
 <!--21A794A3A99943948A5A66ED6C3D8F9F-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--21A794A3A99943948A5A66ED6C3D8F9F--></AD_FIELD>
 
+<!--21C8EBCAFA304343B9D1DB7B7727BC57--><AD_FIELD>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <AD_FIELD_ID><![CDATA[21C8EBCAFA304343B9D1DB7B7727BC57]]></AD_FIELD_ID>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <NAME><![CDATA[Is Backdated Trx]]></NAME>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <AD_TAB_ID><![CDATA[06DCB72BB6D24F82BCDA5FFF8EA0425C]]></AD_TAB_ID>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <AD_COLUMN_ID><![CDATA[5388EC611F144C0FAE99BC692551E180]]></AD_COLUMN_ID>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <DISPLAYLENGTH><![CDATA[1]]></DISPLAYLENGTH>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <SEQNO><![CDATA[110]]></SEQNO>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--21C8EBCAFA304343B9D1DB7B7727BC57--></AD_FIELD>
+
 <!--21CAFF3D185E4C44871C70921424DE55--><AD_FIELD>
 <!--21CAFF3D185E4C44871C70921424DE55-->  <AD_FIELD_ID><![CDATA[21CAFF3D185E4C44871C70921424DE55]]></AD_FIELD_ID>
 <!--21CAFF3D185E4C44871C70921424DE55-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -215040,6 +215066,32 @@
 <!--60B7D5ABB5FD47608ACB13EC89966A6B-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--60B7D5ABB5FD47608ACB13EC89966A6B--></AD_FIELD>
 
+<!--60B8F52D22AF4885B043E6A2F6921427--><AD_FIELD>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <AD_FIELD_ID><![CDATA[60B8F52D22AF4885B043E6A2F6921427]]></AD_FIELD_ID>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <NAME><![CDATA[Is Negative Stock Correction]]></NAME>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <AD_TAB_ID><![CDATA[06DCB72BB6D24F82BCDA5FFF8EA0425C]]></AD_TAB_ID>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <AD_COLUMN_ID><![CDATA[8D1A87A0EA3F413F90E00086A2C38F2A]]></AD_COLUMN_ID>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <IGNOREINWAD><![CDATA[N]]></IGNOREINWAD>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <ISDISPLAYED><![CDATA[Y]]></ISDISPLAYED>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <DISPLAYLENGTH><![CDATA[1]]></DISPLAYLENGTH>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <SEQNO><![CDATA[120]]></SEQNO>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <ISSAMELINE><![CDATA[N]]></ISSAMELINE>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <ISFIELDONLY><![CDATA[N]]></ISFIELDONLY>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <ISENCRYPTED><![CDATA[N]]></ISENCRYPTED>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <SHOWINRELATION><![CDATA[N]]></SHOWINRELATION>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <ISFIRSTFOCUSEDFIELD><![CDATA[N]]></ISFIRSTFOCUSEDFIELD>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <STARTINODDCOLUMN><![CDATA[N]]></STARTINODDCOLUMN>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
+<!--60B8F52D22AF4885B043E6A2F6921427-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
+<!--60B8F52D22AF4885B043E6A2F6921427--></AD_FIELD>
+
 <!--60DF138727B64DD687494FE0DBEDF5D9--><AD_FIELD>
 <!--60DF138727B64DD687494FE0DBEDF5D9-->  <AD_FIELD_ID><![CDATA[60DF138727B64DD687494FE0DBEDF5D9]]></AD_FIELD_ID>
 <!--60DF138727B64DD687494FE0DBEDF5D9-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_REF_LIST.xml	Tue Aug 26 08:26:56 2014 +0200
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml	Tue Aug 26 15:08:12 2014 +0200
@@ -9846,6 +9846,17 @@
 <!--7574AC93C7DA4C068DAED8221325F76C-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--7574AC93C7DA4C068DAED8221325F76C--></AD_REF_LIST>
 
+<!--75783276ADAE4179B04F67452F00A388--><AD_REF_LIST>
+<!--75783276ADAE4179B04F67452F00A388-->  <AD_REF_LIST_ID><![CDATA[75783276ADAE4179B04F67452F00A388]]></AD_REF_LIST_ID>
+<!--75783276ADAE4179B04F67452F00A388-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--75783276ADAE4179B04F67452F00A388-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--75783276ADAE4179B04F67452F00A388-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--75783276ADAE4179B04F67452F00A388-->  <VALUE><![CDATA[NSC]]></VALUE>
+<!--75783276ADAE4179B04F67452F00A388-->  <NAME><![CDATA[Negative Stock Correction]]></NAME>
+<!--75783276ADAE4179B04F67452F00A388-->  <AD_REFERENCE_ID><![CDATA[EB3568484660488FA112CBBB2C1D2780]]></AD_REFERENCE_ID>
+<!--75783276ADAE4179B04F67452F00A388-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--75783276ADAE4179B04F67452F00A388--></AD_REF_LIST>
+
 <!--76080A4F927440E281BE12C669FA1CD0--><AD_REF_LIST>
 <!--76080A4F927440E281BE12C669FA1CD0-->  <AD_REF_LIST_ID><![CDATA[76080A4F927440E281BE12C669FA1CD0]]></AD_REF_LIST_ID>
 <!--76080A4F927440E281BE12C669FA1CD0-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/costing/AverageCostAdjustment.java	Tue Aug 26 08:26:56 2014 +0200
+++ b/src/org/openbravo/costing/AverageCostAdjustment.java	Tue Aug 26 15:08:12 2014 +0200
@@ -81,22 +81,23 @@
       }
     }
 
-    Date trxDate = costAdjLine.getTransactionDate();
-    if (trxDate == null) {
-      trxDate = basetrx.getTransactionProcessDate();
-    }
+    Date trxDate = basetrx.getTransactionProcessDate();
+
     Costing costing = AverageAlgorithm.getProductCost(trxDate, basetrx.getProduct(),
         getCostDimensions(), getCostOrg());
     // Modify isManufacturingProduct flag in case it has changed at some point.
     isManufacturingProduct = ((String) DalUtil.getId(costing.getOrganization())).equals("0");
     BigDecimal cost = costing.getCost();
 
-    BigDecimal currentStock = getCurrentStock();
+    BigDecimal currentStock = CostingUtils.getCurrentStock(getCostOrg(), getTransaction(),
+        getCostDimensions(), isManufacturingProduct);
+
     BigDecimal currentValueAmt = getCurrentValuedStock();
     if (currentStock.signum() != 0) {
       cost = currentValueAmt.add(adjustmentBalance).divide(currentStock, costCurPrecission,
           RoundingMode.HALF_UP);
     }
+
     ScrollableResults trxs = getRelatedTransactions();
     String strCurrentCurId = strCostCurrencyId;
     try {
@@ -160,6 +161,23 @@
             cost = currentValueAmt.add(adjustmentBalance).divide(currentStock, costCurPrecission,
                 RoundingMode.HALF_UP);
           }
+          // stock was negative and cost distinct that trx cost then Negative Stock Correction is
+          // added
+          BigDecimal expectedCost = cost.multiply(trx.getMovementQuantity().abs());
+
+          if (currentStock.compareTo(trx.getMovementQuantity()) < 0 && cost.compareTo(trxCost) != 0) {
+            adjustmentBalance = adjustmentBalance.add(cost.subtract(trxCost).multiply(
+                new BigDecimal(trx.getMovementQuantity().signum())));
+            // If there is a difference insert a cost adjustment line.
+            CostAdjustmentLine newCAL = insertCostAdjustmentLine(trx,
+                expectedCost.subtract(trxCost), getCostAdjLine());
+            newCAL.setNegativeStockCorrection(true);
+            // newCAL.setBackdatedTrx(true);
+            newCAL.setRelatedTransactionAdjusted(true);
+            cost = trxCost.divide(trx.getMovementQuantity(), costCurPrecission,
+                RoundingMode.HALF_UP);
+          }
+
           Costing curCosting = trx.getMaterialMgmtCostingList().get(0);
           if (curCosting.getCost().compareTo(cost) == 0) {
             // new cost hasn't changed, following transactions will have the same cost, so no more
@@ -231,8 +249,8 @@
     // Calculate the average cost on the transaction's movement date and adjust the cost if needed.
     MaterialTransaction trx = getTransaction();
     CostAdjustmentLine costAdjLine = getCostAdjLine();
-    Costing costing = AverageAlgorithm.getProductCost(costAdjLine.getTransactionDate(),
-        trx.getProduct(), getCostDimensions(), getCostOrg());
+
+    Costing costing = getTrxProductCost(trx, getCostDimensions(), getCostOrg());
     BigDecimal cost = costing.getCost();
     Currency costCurrency = getCostCurrency();
     if (costing.getCurrency() != costCurrency) {
@@ -309,58 +327,6 @@
   }
 
   /**
-   * Calculates the stock of the product on the given date and for the given cost dimensions. It
-   * only takes transactions that have its cost calculated.
-   */
-  private BigDecimal getCurrentStock() {
-    Organization org = getCostOrg();
-    MaterialTransaction trx = getTransaction();
-    HashMap<CostDimension, BaseOBObject> costDimensions = getCostDimensions();
-
-    // Get child tree of organizations.
-    OrganizationStructureProvider osp = OBContext.getOBContext().getOrganizationStructureProvider(
-        trx.getClient().getId());
-    Set<String> orgs = osp.getChildTree(org.getId(), true);
-    if (isManufacturingProduct) {
-      orgs = osp.getChildTree("0", false);
-      costDimensions = CostingUtils.getEmptyDimensions();
-    }
-
-    StringBuffer select = new StringBuffer();
-    select
-        .append(" select sum(trx." + MaterialTransaction.PROPERTY_MOVEMENTQUANTITY + ") as stock");
-    select.append(" from " + MaterialTransaction.ENTITY_NAME + " as trx");
-    select.append("   join trx." + MaterialTransaction.PROPERTY_STORAGEBIN + " as locator");
-    select.append(" where trx." + MaterialTransaction.PROPERTY_PRODUCT + " = :product");
-    // Include only transactions that have its cost calculated. Should be all.
-    select.append("   and trx." + MaterialTransaction.PROPERTY_ISCOSTCALCULATED + " = true");
-    // Consider only transactions with movement date equal or lower than the movement date of the
-    // adjusted transaction. But for transactions with the same movement date only those with a
-    // transaction date equal or before the process date of the adjusted transaction.
-    select.append("   and (trx." + MaterialTransaction.PROPERTY_MOVEMENTDATE + " < :mvtdate");
-    select.append("     or (trx." + MaterialTransaction.PROPERTY_MOVEMENTDATE + " = :mvtdate");
-    select.append("   and trx." + MaterialTransaction.PROPERTY_TRANSACTIONPROCESSDATE
-        + " <= :trxdate ))");
-    if (costDimensions.get(CostDimension.Warehouse) != null) {
-      select.append("  and locator." + Locator.PROPERTY_WAREHOUSE + ".id = :warehouse");
-    }
-    select.append("   and trx." + MaterialTransaction.PROPERTY_ORGANIZATION + ".id in (:orgs)");
-    Query trxQry = OBDal.getInstance().getSession().createQuery(select.toString());
-    trxQry.setParameter("product", trx.getProduct());
-    trxQry.setParameter("mvtdate", trx.getMovementDate());
-    trxQry.setParameter("trxdate", trx.getTransactionProcessDate());
-    if (costDimensions.get(CostDimension.Warehouse) != null) {
-      trxQry.setParameter("warehouse", costDimensions.get(CostDimension.Warehouse).getId());
-    }
-    trxQry.setParameterList("orgs", orgs);
-    Object stock = trxQry.uniqueResult();
-    if (stock != null) {
-      return (BigDecimal) stock;
-    }
-    return BigDecimal.ZERO;
-  }
-
-  /**
    * Calculates the value of the stock of the product on the given date, for the given cost
    * dimensions and for the given currency. It only takes transactions that have its cost
    * calculated.
@@ -449,4 +415,82 @@
         .getInstance().getProxy(CostAdjustmentLine.ENTITY_NAME, strCostAdjLineId)));
     return (CostAdjustmentLine) critCAL.uniqueResult();
   }
+
+  @Override
+  void calculateNegativeStockCorrectionAdjustmentAmount() {
+    MaterialTransaction basetrx = getTransaction();
+    BigDecimal currentStock = CostingUtils.getCurrentStock(getCostOrg(), getTransaction(),
+        getCostDimensions(), isManufacturingProduct);
+    BigDecimal currentValueAmt = getCurrentValuedStock();
+    int precission = getCostCurrency().getCostingPrecision().intValue();
+
+    BigDecimal trxCost = CostAdjustmentUtils.getTrxCost(getCostAdjLine().getCostAdjustment(),
+        basetrx, false);
+    BigDecimal trxUnitCost = trxCost.divide(basetrx.getMovementQuantity(), precission);
+    BigDecimal totalStock = currentStock.add(basetrx.getMovementQuantity());
+    // BigDecimal adjustAmt = totalStock.multiply(trxUnitCost).subtract(trxCost)
+    // .subtract(currentValueAmt);
+    BigDecimal adjustAmt = currentStock.multiply(trxUnitCost).subtract(currentValueAmt);
+
+    CostAdjustmentLine costAdjLine = getCostAdjLine();
+    costAdjLine.setCurrency((Currency) OBDal.getInstance().getProxy(Currency.ENTITY_NAME,
+        strCostCurrencyId));
+    costAdjLine.setAdjustmentAmount(adjustAmt);
+    OBDal.getInstance().save(costAdjLine);
+
+  }
+
+  /**
+   * Calculates the value of the stock of the product on the given date, for the given cost
+   * dimensions and for the given currency. It only takes transactions that have its cost
+   * calculated.
+   */
+  protected static Costing getTrxProductCost(MaterialTransaction trx,
+      HashMap<CostDimension, BaseOBObject> costDimensions, Organization costOrg) {
+
+    // Get child tree of organizations.
+    OrganizationStructureProvider osp = OBContext.getOBContext().getOrganizationStructureProvider(
+        costOrg.getClient().getId());
+    Set<String> orgs = osp.getChildTree(costOrg.getId(), true);
+
+    StringBuffer select = new StringBuffer();
+    select.append(" select c ");
+
+    select.append(" from " + Costing.ENTITY_NAME + " as c");
+    select.append("  join c." + TransactionCost.PROPERTY_INVENTORYTRANSACTION + " as trx");
+    select.append("  join trx." + MaterialTransaction.PROPERTY_STORAGEBIN + " as locator");
+
+    select.append(" where trx." + MaterialTransaction.PROPERTY_PRODUCT + ".id = :product");
+    // Consider only transactions with movement date equal or lower than the movement date of the
+    // adjusted transaction. But for transactions with the same movement date only those with a
+    // transaction date equal or before the process date of the adjusted transaction.
+    select.append("   and (trx." + MaterialTransaction.PROPERTY_MOVEMENTDATE + " < :mvtdate");
+    select.append("     or (trx." + MaterialTransaction.PROPERTY_MOVEMENTDATE + " = :mvtdate");
+    select.append("   and trx." + MaterialTransaction.PROPERTY_TRANSACTIONPROCESSDATE
+        + " <= :trxdate ))");
+    // Include only transactions that have its cost calculated
+    select.append("   and trx." + MaterialTransaction.PROPERTY_ISCOSTCALCULATED + " = true");
+    if (costDimensions.get(CostDimension.Warehouse) != null) {
+      select.append("  and locator." + Locator.PROPERTY_WAREHOUSE + ".id = :warehouse");
+    }
+    select.append("   and trx." + MaterialTransaction.PROPERTY_ORGANIZATION + ".id in (:orgs)");
+    select.append(" order by trx." + MaterialTransaction.PROPERTY_MOVEMENTDATE + ", trx."
+        + MaterialTransaction.PROPERTY_TRANSACTIONPROCESSDATE);
+
+    Query trxQry = OBDal.getInstance().getSession().createQuery(select.toString());
+    trxQry.setParameter("product", trx.getProduct().getId());
+    trxQry.setParameter("mvtdate", trx.getMovementDate());
+    trxQry.setParameter("trxdate", trx.getTransactionProcessDate());
+
+    if (costDimensions.get(CostDimension.Warehouse) != null) {
+      trxQry.setParameter("warehouse", costDimensions.get(CostDimension.Warehouse).getId());
+    }
+    trxQry.setParameterList("orgs", orgs);
+    @SuppressWarnings("unchecked")
+    List<Costing> o = trxQry.list();
+    if (o.size() == 0) {
+      return null;
+    }
+    return o.get(0);
+  }
 }
--- a/src/org/openbravo/costing/CostingAlgorithmAdjustmentImp.java	Tue Aug 26 08:26:56 2014 +0200
+++ b/src/org/openbravo/costing/CostingAlgorithmAdjustmentImp.java	Tue Aug 26 15:08:12 2014 +0200
@@ -26,7 +26,7 @@
 import java.util.HashMap;
 import java.util.List;
 
-import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.ApplicationScoped;
 
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.costing.CostingAlgorithm.CostDimension;
@@ -49,7 +49,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@RequestScoped
+@ApplicationScoped
 public abstract class CostingAlgorithmAdjustmentImp {
   protected static Logger log4j = LoggerFactory.getLogger(CostingAlgorithmAdjustmentImp.class);
   protected String strCostAdjLineId;
@@ -108,8 +108,13 @@
     CostAdjustmentLine costAdjLine = getCostAdjLine();
 
     // Backdated transactions are inserted with a null adjustment amount.
-    if (costAdjLine.getAdjustmentAmount() == null) {
-      calculateAdjustmentAmount();
+    if (costAdjLine.isBackdatedTrx()) {
+      calculateBackdatedAdjustmentAmount();
+    }
+
+    // Negative stock correction are inserted with a null adjustment amount.
+    if (costAdjLine.isNegativeStockCorrection()) {
+      calculateNegativeStockCorrectionAdjustmentAmount();
     }
 
     if (costAdjLine.isSource()) {
@@ -279,9 +284,11 @@
 
   }
 
+  abstract void calculateNegativeStockCorrectionAdjustmentAmount();
+
   abstract void getRelatedTransactionsByAlgorithm();
 
-  protected void calculateAdjustmentAmount() {
+  protected void calculateBackdatedAdjustmentAmount() {
     BigDecimal adjAmt = BigDecimal.ZERO;
     // Incoming transactions does not modify the calculated cost
     switch (trxType) {
--- a/src/org/openbravo/costing/CostingServer.java	Tue Aug 26 08:26:56 2014 +0200
+++ b/src/org/openbravo/costing/CostingServer.java	Tue Aug 26 15:08:12 2014 +0200
@@ -43,6 +43,7 @@
 import org.openbravo.model.common.enterprise.DocumentType;
 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.CostingRule;
 import org.openbravo.model.materialmgmt.cost.LCReceipt;
 import org.openbravo.model.materialmgmt.cost.LandedCost;
@@ -235,9 +236,38 @@
       CostAdjustment costAdjustmentHeader = CostAdjustmentUtils.insertCostAdjustmentHeader(
           transaction.getOrganization(), "BDT"); // BDT= Backdated transaction
 
-      CostAdjustmentUtils.insertCostAdjustmentLine(transaction, costAdjustmentHeader, null,
-          Boolean.TRUE, OBDateUtils.getEndOfDay(transaction.getMovementDate()),
-          transaction.getMovementDate());
+      CostAdjustmentLine cal = CostAdjustmentUtils.insertCostAdjustmentLine(transaction,
+          costAdjustmentHeader, null, Boolean.TRUE,
+          OBDateUtils.getEndOfDay(transaction.getMovementDate()), transaction.getMovementDate());
+      cal.setBackdatedTrx(Boolean.TRUE);
+      OBDal.getInstance().save(cal);
+
+      try {
+        JSONObject message = CostAdjustmentProcess.doProcessCostAdjustment(costAdjustmentHeader);
+
+        if (message.get("severity") != "success") {
+          throw new OBException(OBMessageUtils.parseTranslation("@ErrorProcessingCostAdj@") + ": "
+              + costAdjustmentHeader.getDocumentNo() + " - " + message.getString("text"));
+        }
+      } catch (JSONException e) {
+        throw new OBException(OBMessageUtils.parseTranslation("@ErrorProcessingCostAdj@"));
+      }
+    }
+
+    // check if negative stock correction should be done
+
+    boolean modifiesAvg = AverageAlgorithm.modifiesAverage(TrxType.getTrxType(transaction));
+    BigDecimal currentStock = CostingUtils.getCurrentStock(getOrganization(), transaction,
+        getCostingAlgorithm().costDimensions, transaction.getProduct().isProduction());
+    // the stock preivous to transaction was negative
+    if (currentStock.compareTo(transaction.getMovementQuantity()) < 0 && modifiesAvg) {
+
+      CostAdjustment costAdjustmentHeader = CostAdjustmentUtils.insertCostAdjustmentHeader(
+          transaction.getOrganization(), "NSC"); // NSC= Negative Stock Correction
+
+      CostAdjustmentLine cal = CostAdjustmentUtils.insertCostAdjustmentLine(transaction,
+          costAdjustmentHeader, null, Boolean.TRUE, transaction.getTransactionProcessDate(), null);
+      cal.setNegativeStockCorrection(Boolean.TRUE);
 
       try {
         JSONObject message = CostAdjustmentProcess.doProcessCostAdjustment(costAdjustmentHeader);
--- a/src/org/openbravo/costing/CostingUtils.java	Tue Aug 26 08:26:56 2014 +0200
+++ b/src/org/openbravo/costing/CostingUtils.java	Tue Aug 26 15:08:12 2014 +0200
@@ -542,4 +542,54 @@
     }
     return costRules.get(0);
   }
+
+  /**
+   * Calculates the stock of the product on the given date and for the given cost dimensions. It
+   * only takes transactions that have its cost calculated.
+   */
+  public static BigDecimal getCurrentStock(Organization org, MaterialTransaction trx,
+      HashMap<CostDimension, BaseOBObject> costDimensions, boolean isManufacturingProduct) {
+
+    // Get child tree of organizations.
+    OrganizationStructureProvider osp = OBContext.getOBContext().getOrganizationStructureProvider(
+        trx.getClient().getId());
+    Set<String> orgs = osp.getChildTree(org.getId(), true);
+    if (isManufacturingProduct) {
+      orgs = osp.getChildTree("0", false);
+      costDimensions = CostingUtils.getEmptyDimensions();
+    }
+
+    StringBuffer select = new StringBuffer();
+    select
+        .append(" select sum(trx." + MaterialTransaction.PROPERTY_MOVEMENTQUANTITY + ") as stock");
+    select.append(" from " + MaterialTransaction.ENTITY_NAME + " as trx");
+    select.append("   join trx." + MaterialTransaction.PROPERTY_STORAGEBIN + " as locator");
+    select.append(" where trx." + MaterialTransaction.PROPERTY_PRODUCT + " = :product");
+    // Include only transactions that have its cost calculated. Should be all.
+    select.append("   and trx." + MaterialTransaction.PROPERTY_ISCOSTCALCULATED + " = true");
+    // Consider only transactions with movement date equal or lower than the movement date of the
+    // adjusted transaction. But for transactions with the same movement date only those with a
+    // transaction date equal or before the process date of the adjusted transaction.
+    select.append("   and (trx." + MaterialTransaction.PROPERTY_MOVEMENTDATE + " < :mvtdate");
+    select.append("     or (trx." + MaterialTransaction.PROPERTY_MOVEMENTDATE + " = :mvtdate");
+    select.append("   and trx." + MaterialTransaction.PROPERTY_TRANSACTIONPROCESSDATE
+        + " <= :trxdate ))");
+    if (costDimensions.get(CostDimension.Warehouse) != null) {
+      select.append("  and locator." + Locator.PROPERTY_WAREHOUSE + ".id = :warehouse");
+    }
+    select.append("   and trx." + MaterialTransaction.PROPERTY_ORGANIZATION + ".id in (:orgs)");
+    Query trxQry = OBDal.getInstance().getSession().createQuery(select.toString());
+    trxQry.setParameter("product", trx.getProduct());
+    trxQry.setParameter("mvtdate", trx.getMovementDate());
+    trxQry.setParameter("trxdate", trx.getTransactionProcessDate());
+    if (costDimensions.get(CostDimension.Warehouse) != null) {
+      trxQry.setParameter("warehouse", costDimensions.get(CostDimension.Warehouse).getId());
+    }
+    trxQry.setParameterList("orgs", orgs);
+    Object stock = trxQry.uniqueResult();
+    if (stock != null) {
+      return (BigDecimal) stock;
+    }
+    return BigDecimal.ZERO;
+  }
 }
--- a/src/org/openbravo/costing/StandardCostAdjustment.java	Tue Aug 26 08:26:56 2014 +0200
+++ b/src/org/openbravo/costing/StandardCostAdjustment.java	Tue Aug 26 15:08:12 2014 +0200
@@ -196,6 +196,10 @@
   }
 
   @Override
+  void calculateNegativeStockCorrectionAdjustmentAmount() {
+  }
+
+  @Override
   protected void addCostDependingTrx(CostAdjustmentLine costAdjLine) {
     // Do nothing.
     // All transactions are calculated using the current standard cost so there is no need to