diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 8e9cdbfc4d5285db423e62d7e7d355f3f4f3919b..16450fd9febdd73342ade22adeee88efa09fee87 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -599,7 +599,7 @@ abstract class CommonObject
         }
 
         $datecreate = dol_now();
-		
+
         // Socpeople must have already been added by some a trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error
         $TListeContacts=$this->liste_contact(-1, $source);
         $already_added=false;
@@ -611,11 +611,11 @@ abstract class CommonObject
 	        	}
 	        }
         }
-        
+
         if(!$already_added) {
-        	
+
         	$this->db->begin();
-        	
+
 	        // Insertion dans la base
 	        $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact";
 	        $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";
@@ -623,7 +623,7 @@ abstract class CommonObject
 	        $sql.= "'".$this->db->idate($datecreate)."'";
 	        $sql.= ", 4, ". $id_type_contact;
 	        $sql.= ")";
-	        
+
 	        $resql=$this->db->query($sql);
 	        if ($resql)
 	        {
@@ -636,7 +636,7 @@ abstract class CommonObject
 		                return -1;
 		            }
 	            }
-	
+
 	            $this->db->commit();
 	            return 1;
 	        }
@@ -3947,7 +3947,7 @@ abstract class CommonObject
 
 					// Now we add first model found in directories scanned
 	                $listofdir=explode(',',$dirtoscan);
-	                foreach($listofdir as $key=>$tmpdir)
+	                foreach($listofdir as $key => $tmpdir)
 	                {
 	                    $tmpdir=trim($tmpdir);
 	                    $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php
index f0dce5f37a132fbfbd1f1dcdd3694c4e3cbc053b..3d3e8339aca32e78abb347260480df5b95b13c3e 100644
--- a/htdocs/core/modules/DolibarrModules.class.php
+++ b/htdocs/core/modules/DolibarrModules.class.php
@@ -1255,55 +1255,55 @@ class DolibarrModules           // Can not be abstract, because we need to insta
      *
      * @return int  Error count (0 if ok)
      */
-    function insert_tabs()
-    {
-        global $conf;
-
-        $err=0;
-
-        if (! empty($this->tabs))
-        {
-            $i=0;
-            foreach ($this->tabs as $key => $value)
-            {
-            	if (is_array($value) && count($value) == 0) continue;	// Discard empty arrays
-
-            	$entity=$conf->entity;
-            	$newvalue = $value;
-
-            	if (is_array($value))
-            	{
-            		$newvalue = $value['data'];
-            		if (isset($value['entity'])) $entity = $value['entity'];
-            	}
-
-                if ($newvalue)
-                {
-                    $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (";
-                    $sql.= "name";
-                    $sql.= ", type";
-                    $sql.= ", value";
-                    $sql.= ", note";
-                    $sql.= ", visible";
-                    $sql.= ", entity";
-                    $sql.= ")";
-                    $sql.= " VALUES (";
-                    $sql.= $this->db->encrypt($this->const_name."_TABS_".$i,1);
-                    $sql.= ", 'chaine'";
-                    $sql.= ", ".$this->db->encrypt($value,1);
-                    $sql.= ", null";
-                    $sql.= ", '0'";
-                    $sql.= ", ".$conf->entity;
-                    $sql.= ")";
-
-                    dol_syslog(get_class($this)."::insert_tabs", LOG_DEBUG);
-                    $this->db->query($sql);
-                }
-                $i++;
-            }
-        }
-        return $err;
-    }
+	function insert_tabs()
+	{
+		global $conf;
+
+		$err=0;
+
+		if (! empty($this->tabs))
+		{
+			$i=0;
+			foreach ($this->tabs as $key => $value)
+			{
+				if (is_array($value) && count($value) == 0) continue;	// Discard empty arrays
+
+				$entity=$conf->entity;
+				$newvalue = $value;
+
+				if (is_array($value))
+				{
+					$newvalue = $value['data'];
+					if (isset($value['entity'])) $entity = $value['entity'];
+				}
+
+				if ($newvalue)
+				{
+					$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (";
+					$sql.= "name";
+					$sql.= ", type";
+					$sql.= ", value";
+					$sql.= ", note";
+					$sql.= ", visible";
+					$sql.= ", entity";
+					$sql.= ")";
+					$sql.= " VALUES (";
+					$sql.= $this->db->encrypt($this->const_name."_TABS_".$i,1);
+					$sql.= ", 'chaine'";
+					$sql.= ", ".$this->db->encrypt($newvalue,1);
+					$sql.= ", null";
+					$sql.= ", '0'";
+					$sql.= ", ".$entity;
+					$sql.= ")";
+
+					dol_syslog(get_class($this)."::insert_tabs", LOG_DEBUG);
+					$this->db->query($sql);
+				}
+				$i++;
+			}
+		}
+		return $err;
+	}
 
     /**
      * Adds constants
diff --git a/htdocs/install/mysql/migration/3.8.0-3.9.0.sql b/htdocs/install/mysql/migration/3.8.0-3.9.0.sql
index d747d5098f5a3aef534bf2b988963bfff83c0a70..cc31ed38b400b50bbf48a1081c212ca96e78afe6 100644
--- a/htdocs/install/mysql/migration/3.8.0-3.9.0.sql
+++ b/htdocs/install/mysql/migration/3.8.0-3.9.0.sql
@@ -611,3 +611,7 @@ INSERT INTO llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) VALUES (14
 -- VMYSQL4.1 ALTER TABLE llx_c_type_resource CHANGE COLUMN rowid rowid integer NOT NULL AUTO_INCREMENT;
 
 ALTER TABLE llx_import_model MODIFY COLUMN type varchar(50);
+
+-- Negative buying prices
+
+UPDATE llx_facturedet SET buy_price_ht = ABS(buy_price_ht)