From 946c79ced021fc7937551e4caec0d99f96a3be37 Mon Sep 17 00:00:00 2001 From: lvessiller Date: Tue, 4 Oct 2022 17:43:24 +0200 Subject: [PATCH 1/2] NEW set thirdparty type with company modify trigger --- htdocs/societe/class/societe.class.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 586f955c1e0..c01f83401cf 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -4932,15 +4932,16 @@ class Societe extends CommonObject */ public function setThirdpartyType($typent_id) { + global $user; + + dol_syslog(__METHOD__, LOG_DEBUG); + if ($this->id) { - $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; - $sql .= " SET fk_typent = ".($typent_id > 0 ? $typent_id : "null"); - $sql .= " WHERE rowid = ".((int) $this->id); - dol_syslog(get_class($this).'::setThirdpartyType', LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { + $result = $this->setValueFrom('fk_typent', $typent_id, '', null, '', '', $user, 'COMPANY_MODIFY'); + + if ($result > 0) { $this->typent_id = $typent_id; - $this->typent_code = dol_getIdFromCode($this->db, $this->$typent_id, 'c_typent', 'id', 'code'); + $this->typent_code = dol_getIdFromCode($this->db, $this->typent_id, 'c_typent', 'id', 'code'); return 1; } else { return -1; From 9422a4bd1d3b7bc3a7e5b6ff2e4469721ec77ae1 Mon Sep 17 00:00:00 2001 From: lvessiller Date: Wed, 5 Oct 2022 09:32:37 +0200 Subject: [PATCH 2/2] FIX uses object fetch method in setValueFrom if method exists --- htdocs/core/class/commonobject.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 7f30878d566..dcec2480137 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2072,7 +2072,7 @@ abstract class CommonObject if ($resql) { if ($trigkey) { // call trigger with updated object values - if (empty($this->fields) && method_exists($this, 'fetch')) { + if (method_exists($this, 'fetch')) { $result = $this->fetch($id); } else { $result = $this->fetchCommon($id);