From 6ba5ca36c4b7a7a666a997effd2cd6001ac66a8e Mon Sep 17 00:00:00 2001 From: dolibarr95 <24292300+dolibarr95@users.noreply.github.com> Date: Fri, 5 Jan 2018 08:59:31 +0100 Subject: [PATCH 1/7] Update llx_societe.sql Goes with https://github.com/Dolibarr/dolibarr/pull/7975 --- htdocs/install/mysql/tables/llx_societe.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/tables/llx_societe.sql b/htdocs/install/mysql/tables/llx_societe.sql index c23ca3a183c..fe20f426094 100644 --- a/htdocs/install/mysql/tables/llx_societe.sql +++ b/htdocs/install/mysql/tables/llx_societe.sql @@ -104,5 +104,6 @@ create table llx_societe webservices_key varchar(128), -- supplier webservice key fk_multicurrency integer, - multicurrency_code varchar(255) + multicurrency_code varchar(255), + fk_entrepot int DEFAULT 0 -- Id de l'entrepôt par défaut (Warehouse ID by default) )ENGINE=innodb; From 9e0a548eff89bd74fa41bf0127a4b2c6ad75091d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 25 Jan 2018 17:42:25 +0100 Subject: [PATCH 2/7] Update commonobject.class.php --- htdocs/core/class/commonobject.class.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d71277a77ee..06b34ccb8b3 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -13,6 +13,7 @@ * Copyright (C) 2016 Bahfir abbes * Copyright (C) 2017 ATM Consulting * Copyright (C) 2017 Nicolas ZABOURI + * Copyright (C) 2018 Frederic France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -4503,11 +4504,11 @@ abstract class CommonObject * Data to describe values to insert/update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...) * This function delete record with all extrafields and insert them again from the array $this->array_options. * - * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) + * @param bool $notrigger false=launch triggers after, true=disable triggers * @param User $userused Object user * @return int -1=error, O=did nothing, 1=OK */ - function insertExtraFields($trigger='',$userused=null) + function insertExtraFields($notrigger=false, $userused=null) { global $conf,$langs,$user; @@ -4648,7 +4649,7 @@ abstract class CommonObject { // Call trigger $this->context=array('extrafieldaddupdate'=>1); - $result=$this->call_trigger($trigger, $userused); + $result=$this->call_trigger(strtoupper(get_class($this)) . '_EXTRAFIELDS_MODIFY', $userused); if ($result < 0) $error++; // End call trigger } From ec38b8a5a25c8e5472a3c694039da62a2b6a8147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 25 Jan 2018 17:50:11 +0100 Subject: [PATCH 3/7] Update interface_99_modMyModule_MyModuleTriggers.class.php --- htdocs/core/class/commonobject.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 06b34ccb8b3..4f1627c2940 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4645,11 +4645,11 @@ abstract class CommonObject } else { - if ($trigger) + if (!$notrigger) { // Call trigger $this->context=array('extrafieldaddupdate'=>1); - $result=$this->call_trigger(strtoupper(get_class($this)) . '_EXTRAFIELDS_MODIFY', $userused); + $result=$this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); if ($result < 0) $error++; // End call trigger } From d0e83b79025d7fe922411e725b7b6b0926f9fab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 26 Jan 2018 08:14:39 +0100 Subject: [PATCH 4/7] trigger on bank account update --- htdocs/core/class/commonobject.class.php | 50 +++++++++++++++++++----- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 4f1627c2940..9cc686f22e5 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1888,10 +1888,18 @@ abstract class CommonObject * Change the bank account * * @param int $fk_account Id of bank account + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @param User $userused Object user * @return int 1 if OK, 0 if KO */ - function setBankAccount($fk_account) + function setBankAccount($fk_account, $notrigger=false, $userused=null) { + global $user; + + if (empty($userused)) $userused=$user; + + $error = 0; + if (! $this->table_element) { dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); return -1; @@ -1903,15 +1911,37 @@ abstract class CommonObject $sql.= " SET fk_account = ".$fk_account; $sql.= " WHERE rowid=".$this->id; - if ($this->db->query($sql)) { - $this->fk_account = ($fk_account=='NULL')?null:$fk_account; - return 1; - } else { - dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); - $this->error=$this->db->error(); - return 0; - } - } + $resql = $this->db->query($sql); + if (! $resql) + { + dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); + $this->error = $this->db->lasterror(); + $error++; + } + else + { + if (!$notrigger) + { + // Call trigger + $this->context=array('bankaccountupdate'=>1); + $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); + if ($result < 0) $error++; + // End call trigger + } + } + if ($error) + { + $this->db->rollback(); + return -1; + } + else + { + $this->fk_account = ($fk_account=='NULL')?null:$fk_account; + $this->db->commit(); + return 1; + } + } + // TODO: Move line related operations to CommonObjectLine? From 336c44dc8802a1ddf5f4c9ab958df33f90bfcadc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 26 Jan 2018 08:33:35 +0100 Subject: [PATCH 5/7] trigger on shipping method update --- htdocs/core/class/commonobject.class.php | 48 +++++++++++++++++++----- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 9cc686f22e5..c0583f09552 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1790,29 +1790,57 @@ abstract class CommonObject * Change the shipping method * * @param int $shipping_method_id Id of shipping method + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @param User $userused Object user + * * @return int 1 if OK, 0 if KO */ - function setShippingMethod($shipping_method_id) + function setShippingMethod($shipping_method_id, $notrigger=false, $userused=null) { + global $user; + + if (empty($userused)) $userused=$user; + + $error = 0; + if (! $this->table_element) { dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); return -1; } + + $this->db->begin(); + if ($shipping_method_id<0) $shipping_method_id='NULL'; dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; $sql.= " SET fk_shipping_method = ".$shipping_method_id; $sql.= " WHERE rowid=".$this->id; - - if ($this->db->query($sql)) { - $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; - return 1; - } else { + $resql = $this->db->query($sql); + if (! $resql) { dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); - $this->error=$this->db->error(); - return 0; - } + $this->error = $this->db->lasterror(); + $error++; + } else { + if (!$notrigger) + { + // Call trigger + $this->context=array('shippingmethodupdate'=>1); + $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); + if ($result < 0) $error++; + // End call trigger + } + } + if ($error) + { + $this->db->rollback(); + return -1; + } else { + $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; + $this->db->commit(); + return 1; + } + } @@ -1904,6 +1932,8 @@ abstract class CommonObject dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); return -1; } + $this->db->begin(); + if ($fk_account<0) $fk_account='NULL'; dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); From 9a0dca57afd868c50aa942b2a5cd49d866a947aa Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 5 Feb 2018 15:40:18 +0100 Subject: [PATCH 6/7] Update commonobject.class.php --- htdocs/core/class/commonobject.class.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index c0583f09552..76f8e55ff15 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4564,11 +4564,11 @@ abstract class CommonObject * Data to describe values to insert/update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...) * This function delete record with all extrafields and insert them again from the array $this->array_options. * - * @param bool $notrigger false=launch triggers after, true=disable triggers + * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) * @param User $userused Object user * @return int -1=error, O=did nothing, 1=OK */ - function insertExtraFields($notrigger=false, $userused=null) + function insertExtraFields($trigger='', $userused=null) { global $conf,$langs,$user; @@ -4703,16 +4703,14 @@ abstract class CommonObject $this->error=$this->db->lasterror(); $error++; } - else + + if (!$error && !$trigger) { - if (!$notrigger) - { - // Call trigger - $this->context=array('extrafieldaddupdate'=>1); - $result=$this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); - if ($result < 0) $error++; - // End call trigger - } + // Call trigger + $this->context=array('extrafieldaddupdate'=>1); + $result=$this->call_trigger(strtoupper($trigger, $userused); + if ($result < 0) $error++; + // End call trigger } if ($error) From 6291cb4cbe6b135f96994975d6fd5c5cd1184c61 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 5 Feb 2018 15:41:34 +0100 Subject: [PATCH 7/7] Update commonobject.class.php --- 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 76f8e55ff15..592960670a0 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4708,7 +4708,7 @@ abstract class CommonObject { // Call trigger $this->context=array('extrafieldaddupdate'=>1); - $result=$this->call_trigger(strtoupper($trigger, $userused); + $result=$this->call_trigger($trigger, $userused); if ($result < 0) $error++; // End call trigger }