From b15fda8d9a761fec13f177bf9646ab318e9b2f5c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Nov 2022 14:38:25 +0100 Subject: [PATCH] Debug edit actioncomm --- htdocs/comm/action/card.php | 2 ++ htdocs/comm/action/class/actioncomm.class.php | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 63647e9d308..0b169d846e9 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -550,7 +550,9 @@ if (empty($reshook) && $action == 'update') { } } else { $object->type_id = dol_getIdFromCode($db, GETPOST("actioncode", 'aZ09'), 'c_actioncomm'); + $object->type_code = GETPOST("actioncode", 'aZ09'); } + $object->label = GETPOST("label", "alphanohtml"); $object->datep = $datep; $object->datef = $datef; diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index e31e6023210..7947afa71ab 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1150,12 +1150,8 @@ class ActionComm extends CommonObject $userownerid = ($this->userownerid ? $this->userownerid : 0); $userdoneid = ($this->userdoneid ? $this->userdoneid : 0); - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm "; - $sql .= " SET percent = '".$this->db->escape($this->percentage)."'"; + // If a type_id is set, we must also have the type_code set if ($this->type_id > 0) { - $sql .= ", fk_action = ".(int) $this->type_id; if (empty($this->type_code)) { $cactioncomm = new CActionComm($this->db); $result = $cactioncomm->fetch($this->type_id); @@ -1164,7 +1160,18 @@ class ActionComm extends CommonObject } } } - $sql .= ", code = " . (isset($this->type_code)? "'".$this->db->escape($this->type_code) . "'":"null"); + + $code = $this->code; + if (empty($code) || (!empty($this->oldcopy) && $this->oldcopy->type_code != $this->type_code)) { // If code unknown or if change the type, we reset $code too + $code = $this->type_code; + } + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm "; + $sql .= " SET percent = '".$this->db->escape($this->percentage)."'"; + $sql .= ", fk_action = ".(int) $this->type_id; + $sql .= ", code = " . ($code ? "'".$this->db->escape($code)."'" : "null"); $sql .= ", label = ".($this->label ? "'".$this->db->escape($this->label)."'" : "null"); $sql .= ", datep = ".(strval($this->datep) != '' ? "'".$this->db->idate($this->datep)."'" : 'null'); $sql .= ", datep2 = ".(strval($this->datef) != '' ? "'".$this->db->idate($this->datef)."'" : 'null');