From 27caa586c20066fad6a1bdaff5a47f835be6d398 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 28 Jan 2017 12:36:53 +0100 Subject: [PATCH] Fix auto increment customer code must be done only if error is on duplicate code --- htdocs/societe/class/societe.class.php | 5 ++--- htdocs/societe/soc.php | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 9248a07469c..b4a9a549ea7 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -503,10 +503,9 @@ class Societe extends CommonObject } else { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - - $this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name); + $this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name); // duplicate on a field (code or profid or ...) $result=-1; } else diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 36fe26447fa..540c3aed883 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -514,8 +514,8 @@ if (empty($reshook)) } else { - - if($result == -3) { + if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') // TODO Sometime errors on duplicate on profid and not on code, so + { $duplicate_code_error = true; $object->code_fournisseur = null; $object->code_client = null;