diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index a0ef8878d1f7a15dc3f0d3bc332a24b975e613ba..b5302063a65c4ce1a812cc8461bdac362a6ca5cc 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -2194,7 +2194,7 @@ if ($action == 'create')
 
 		$ref = dol_sanitizeFileName($object->ref);
 		include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
-		$fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/'));
+		$fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+');
 		$file = $fileparams ['fullname'];
 
 		// Define output language
@@ -2219,7 +2219,7 @@ if ($action == 'create')
 				dol_print_error($db, $result);
 				exit();
 			}
-			$fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/'));
+			$fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+');
 			$file = $fileparams ['fullname'];
 		}
 
diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index e6be7a8d74bf94729f762c4729680e1ae4d5517f..c326959619a8aaada5eb794f96b28d3499c56684 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -2,7 +2,7 @@
 /* Copyright (C) 2003-2006	Rodolphe Quiedeville	<rodolphe@quiedeville.org>
  * Copyright (C) 2004-2014	Laurent Destailleur		<eldy@users.sourceforge.net>
  * Copyright (C) 2005		Marc Barilley / Ocebo	<marc@ocebo.com>
- * Copyright (C) 2005-2013	Regis Houssin			<regis.houssin@capnetworks.com>
+ * Copyright (C) 2005-2015	Regis Houssin			<regis.houssin@capnetworks.com>
  * Copyright (C) 2006		Andre Cianfarani		<acianfa@free.fr>
  * Copyright (C) 2010-2013	Juanjo Menent			<jmenent@2byte.es>
  * Copyright (C) 2011		Philippe Grand			<philippe.grand@atoo-net.com>
@@ -2285,7 +2285,7 @@ if ($action == 'create' && $user->rights->commande->creer) {
 
 			$ref = dol_sanitizeFileName($object->ref);
 			include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
-			$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/'));
+			$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+');
 			$file = $fileparams ['fullname'];
 
 			// Define output language
@@ -2310,7 +2310,7 @@ if ($action == 'create' && $user->rights->commande->creer) {
 					dol_print_error($db, $result);
 					exit();
 				}
-				$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/'));
+				$fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+');
 				$file = $fileparams ['fullname'];
 			}
 
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index e247863a01519acd3900e3cec9ae80b5572f94b1..b360f6b63157cafbdf7151f4554515aa3f60e4d3 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -3,7 +3,7 @@
  * Copyright (C) 2004      Eric Seigne           <eric.seigne@ryxeo.com>
  * Copyright (C) 2004-2014 Laurent Destailleur   <eldy@users.sourceforge.net>
  * Copyright (C) 2005      Marc Barilley / Ocebo <marc@ocebo.com>
- * Copyright (C) 2005-2012 Regis Houssin         <regis.houssin@capnetworks.com>
+ * Copyright (C) 2005-2015 Regis Houssin         <regis.houssin@capnetworks.com>
  * Copyright (C) 2006      Andre Cianfarani      <acianfa@free.fr>
  * Copyright (C) 2010-2015 Juanjo Menent         <jmenent@2byte.es>
  * Copyright (C) 2012-2013 Christophe Battarel   <christophe.battarel@altairis.fr>
@@ -3561,7 +3561,7 @@ if ($action == 'create')
 
 		$ref = dol_sanitizeFileName($object->ref);
 		include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
-		$fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/'));
+		$fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+');
 		$file = $fileparams ['fullname'];
 
 		// Define output language
@@ -3586,7 +3586,7 @@ if ($action == 'create')
 				dol_print_error($db, $result);
 				exit();
 			}
-			$fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/'));
+			$fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+');
 			$file = $fileparams ['fullname'];
 		}
 
diff --git a/htdocs/core/tpl/document_actions_post_headers.tpl.php b/htdocs/core/tpl/document_actions_post_headers.tpl.php
index d1a1cedca613311e927bb374a44c4348e20fa52e..75d18c2b1a56ed20396827cca4adc469ef5455da 100644
--- a/htdocs/core/tpl/document_actions_post_headers.tpl.php
+++ b/htdocs/core/tpl/document_actions_post_headers.tpl.php
@@ -48,7 +48,7 @@ if (empty($conf->global->MAIN_DISABLE_SUGGEST_REF_AS_PREFIX))
 	//var_dump($modulepart);
 	if (in_array($modulepart,array('facture_fournisseur','commande_fournisseur','facture','commande','propal','ficheinter','contract','project','project_task')))
 	{
-		$savingdocmask=$object->ref.'___file__';
+		$savingdocmask=$object->ref.'-__file__';
 	}
 	/*if (in_array($modulepart,array('member')))
 	{
diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php
index 7187506db148c4c7c5374f7632f9a0b3dd0cab34..7dd0d680bee5d46d8c725c66ad66b2ab4b07aa06 100644
--- a/htdocs/expedition/card.php
+++ b/htdocs/expedition/card.php
@@ -1621,7 +1621,7 @@ else if ($id || $ref)
 	{
 		$ref = dol_sanitizeFileName($object->ref);
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-		$fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref,'/'));
+		$fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref, '/').'([^\-])+');
 		$file=$fileparams['fullname'];
 
 		// Define output language
@@ -1648,7 +1648,7 @@ else if ($id || $ref)
 				dol_print_error($db,$result);
 				exit;
 			}
-			$fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref,'/'));
+			$fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref, '/').'([^\-])+');
 			$file=$fileparams['fullname'];
 		}
 
diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php
index f5fcd07670997cf1d1a393a083c562d831924e1f..6fb4d374a7a4e3c5df7f8b97f2dab9a08d437f1b 100644
--- a/htdocs/fichinter/card.php
+++ b/htdocs/fichinter/card.php
@@ -1732,7 +1732,7 @@ else if ($id > 0 || ! empty($ref))
 	{
 		$ref = dol_sanitizeFileName($object->ref);
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-		$fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref,'/'));
+		$fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+');
 		$file=$fileparams['fullname'];
 
 		// Define output language
@@ -1759,7 +1759,7 @@ else if ($id > 0 || ! empty($ref))
 				dol_print_error($db,$result);
 				exit;
 			}
-			$fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref,'/'));
+			$fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+');
 			$file=$fileparams['fullname'];
 		}
 
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index a6ac9c42b56bc9f8e73ab19ff5a3ea4579ecbeee..584b5e337e0d788b690352427e530b922e96bf46 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -1920,7 +1920,7 @@ elseif (! empty($object->id))
 	{
 		$ref = dol_sanitizeFileName($object->ref);
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-		$fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref, preg_quote($ref,'/'));
+		$fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+');
 		$file=$fileparams['fullname'];
 
 		// Define output language
@@ -1947,7 +1947,7 @@ elseif (! empty($object->id))
 				dol_print_error($db,$result);
 				exit;
 			}
-			$fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref, preg_quote($ref,'/'));
+			$fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+');
 			$file=$fileparams['fullname'];
 		}
 
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index 54ef660f6aa7981b0b277fa4e8fe96c80ba01ae0..08bffd09a67509a4422b0e4082f80f195787486b 100644
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -2396,7 +2396,7 @@ else
         {
             $ref = dol_sanitizeFileName($object->ref);
             include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-            $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref, preg_quote($ref,'/'));
+            $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref, preg_quote($ref, '/').'([^\-])+');
             $file=$fileparams['fullname'];
 
             // Define output language
@@ -2423,7 +2423,7 @@ else
                     dol_print_error($db,$result);
                     exit;
                 }
-                $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref, preg_quote($ref,'/'));
+                $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref, preg_quote($ref, '/').'([^\-])+');
                 $file=$fileparams['fullname'];
             }
 
diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql
index f6282edf3695ce0836d7bf9d0d198a1ec92d5365..57f29ef9a90cd64663f06877a0eef28701b94d8e 100755
--- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql
+++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql
@@ -208,10 +208,14 @@ UPDATE llx_product SET fk_barcode_type = NULL WHERE fk_barcode_type NOT IN (SELE
 ALTER TABLE  llx_product_price ADD INDEX idx_product_price_fk_user_author (fk_user_author);
 UPDATE llx_product_price set fk_user_author = null where fk_user_author = 0;
 UPDATE llx_product_price set fk_user_author = null where fk_user_author not in (select rowid from llx_user);
+-- drop foreign key for avoid a mysql crash
+ALTER TABLE  llx_product_price DROP FOREIGN KEY fk_product_price_user_author;
 ALTER TABLE  llx_product_price ADD CONSTRAINT fk_product_price_user_author FOREIGN KEY (fk_user_author) REFERENCES  llx_user (rowid);
 -- fk_product
 ALTER TABLE  llx_product_price ADD INDEX idx_product_price_fk_product (fk_product);
 DELETE from llx_product_price where fk_product NOT IN (SELECT rowid from llx_product);
+-- drop foreign key for avoid a mysql crash
+ALTER TABLE  llx_product_price DROP FOREIGN KEY fk_product_price_product;
 ALTER TABLE  llx_product_price ADD CONSTRAINT fk_product_price_product FOREIGN KEY (fk_product) REFERENCES  llx_product (rowid);
 
 ALTER TABLE llx_commande_fournisseur MODIFY COLUMN date_livraison datetime;