Fix regression, can't reset parent company.
This commit is contained in:
parent
97154f8267
commit
fedf7645b1
@ -852,7 +852,7 @@ if (empty($reshook)) {
|
|||||||
// Set parent company
|
// Set parent company
|
||||||
if ($action == 'set_thirdparty' && $user->rights->societe->creer) {
|
if ($action == 'set_thirdparty' && $user->rights->societe->creer) {
|
||||||
$object->fetch($socid);
|
$object->fetch($socid);
|
||||||
$result = $object->set_parent(GETPOST('parent_id', 'int'));
|
$result = $object->setParent(GETPOST('parent_id', 'int'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set sales representatives
|
// Set sales representatives
|
||||||
|
|||||||
@ -3321,27 +3321,31 @@ class Societe extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
|
||||||
/**
|
/**
|
||||||
* Define parent commany of current company
|
* Define parent commany of current company
|
||||||
*
|
*
|
||||||
* @param int $id Id of thirdparty to set or '' to remove
|
* @param int $id Id of thirdparty to set or '' to remove
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
public function set_parent($id)
|
public function setParent($id)
|
||||||
{
|
{
|
||||||
// phpcs:enable
|
|
||||||
if ($this->id) {
|
if ($this->id) {
|
||||||
// Check if the id we want to add as parent has not already one parent that is the current id we try to update
|
// Check if the id we want to add as parent has not already one parent that is the current id we try to update
|
||||||
|
if ($id > 0) {
|
||||||
$sameparent = $this->validateFamilyTree($id, $this->id, 0);
|
$sameparent = $this->validateFamilyTree($id, $this->id, 0);
|
||||||
if ($sameparent < 0) {
|
if ($sameparent < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
} elseif ($sameparent == 1) {
|
}
|
||||||
|
if ($sameparent == 1) {
|
||||||
setEventMessages('ParentCompanyToAddIsAlreadyAChildOfModifiedCompany', null, 'warnings');
|
setEventMessages('ParentCompanyToAddIsAlreadyAChildOfModifiedCompany', null, 'warnings');
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dol_syslog(get_class($this).'::setParent', LOG_DEBUG);
|
||||||
|
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe SET parent = '.($id > 0 ? $id : 'null').' WHERE rowid = '.((int) $this->id);
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe SET parent = '.($id > 0 ? $id : 'null').' WHERE rowid = '.((int) $this->id);
|
||||||
dol_syslog(get_class($this).'::set_parent', LOG_DEBUG);
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$this->parent = $id;
|
$this->parent = $id;
|
||||||
@ -3349,7 +3353,6 @@ class Societe extends CommonObject
|
|||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user