Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2018-02-05 17:07:57 +01:00
commit c7d11daed6

View File

@ -13,6 +13,7 @@
* Copyright (C) 2016 Bahfir abbes <dolipar@dolipar.org> * Copyright (C) 2016 Bahfir abbes <dolipar@dolipar.org>
* Copyright (C) 2017 ATM Consulting <support@atm-consulting.fr> * Copyright (C) 2017 ATM Consulting <support@atm-consulting.fr>
* Copyright (C) 2017 Nicolas ZABOURI <info@inovea-conseil.com> * Copyright (C) 2017 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2018 Frederic France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -1795,30 +1796,58 @@ abstract class CommonObject
* Change the shipping method * Change the shipping method
* *
* @param int $shipping_method_id Id of 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 * @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) { if (! $this->table_element) {
dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR);
return -1; return -1;
} }
$this->db->begin();
if ($shipping_method_id<0) $shipping_method_id='NULL'; if ($shipping_method_id<0) $shipping_method_id='NULL';
dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')');
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " SET fk_shipping_method = ".$shipping_method_id; $sql.= " SET fk_shipping_method = ".$shipping_method_id;
$sql.= " WHERE rowid=".$this->id; $sql.= " WHERE rowid=".$this->id;
$resql = $this->db->query($sql);
if ($this->db->query($sql)) { if (! $resql) {
$this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id;
return 1;
} else {
dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG);
$this->error=$this->db->error(); $this->error = $this->db->lasterror();
return 0; $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;
}
}
/** /**
@ -1893,14 +1922,24 @@ abstract class CommonObject
* Change the bank account * Change the bank account
* *
* @param int $fk_account Id of 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 * @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) { if (! $this->table_element) {
dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR);
return -1; return -1;
} }
$this->db->begin();
if ($fk_account<0) $fk_account='NULL'; if ($fk_account<0) $fk_account='NULL';
dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')');
@ -1908,15 +1947,37 @@ abstract class CommonObject
$sql.= " SET fk_account = ".$fk_account; $sql.= " SET fk_account = ".$fk_account;
$sql.= " WHERE rowid=".$this->id; $sql.= " WHERE rowid=".$this->id;
if ($this->db->query($sql)) { $resql = $this->db->query($sql);
$this->fk_account = ($fk_account=='NULL')?null:$fk_account; if (! $resql)
return 1; {
} else {
dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error());
$this->error=$this->db->error(); $this->error = $this->db->lasterror();
return 0; $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? // TODO: Move line related operations to CommonObjectLine?