FIX Merge of 2 thirdparties when there is one common tag.
This commit is contained in:
parent
b62be8dd0b
commit
6317cb53f2
@ -1717,6 +1717,6 @@ class Categorie extends CommonObject
|
||||
'categorie_societe'
|
||||
);
|
||||
|
||||
return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
|
||||
return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4474,20 +4474,24 @@ abstract class CommonObject
|
||||
* This function is meant to be called from replaceThirdparty with the appropiate tables
|
||||
* Column name fk_soc MUST be used to identify thirdparties
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
* @param int $origin_id Old thirdparty id (the thirdparty to delete)
|
||||
* @param int $dest_id New thirdparty id (the thirdparty that will received element of the other)
|
||||
* @param string[] $tables Tables that need to be changed
|
||||
* @param DoliDB $db Database handler
|
||||
* @param int $origin_id Old thirdparty id (the thirdparty to delete)
|
||||
* @param int $dest_id New thirdparty id (the thirdparty that will received element of the other)
|
||||
* @param string[] $tables Tables that need to be changed
|
||||
* @param int $ignoreerrors Ignore errors. Return true even if errors. We need this when replacement can fails like for categories (categorie of old thirdparty may already exists on new one)
|
||||
* @return bool
|
||||
*/
|
||||
public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables)
|
||||
public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
|
||||
{
|
||||
foreach ($tables as $table)
|
||||
{
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id;
|
||||
|
||||
if (!$db->query($sql)) {
|
||||
return false;
|
||||
if (! $db->query($sql))
|
||||
{
|
||||
if ($ignoreerrors) return true;
|
||||
//$this->errors = $db->lasterror();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -169,6 +169,7 @@ ErrorSavingChanges=An error has ocurred when saving the changes
|
||||
ErrorWarehouseRequiredIntoShipmentLine=Warehouse is required on the line to ship
|
||||
ErrorFileMustHaveFormat=File must have format %s
|
||||
ErrorSupplierCountryIsNotDefined=Country for this supplier is not defined. Correct this first.
|
||||
ErrorsThirdpartyMerge=Failed to merge the two records. Request canceled.
|
||||
|
||||
# Warnings
|
||||
WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user.
|
||||
|
||||
@ -1002,14 +1002,16 @@ class Societe extends CommonObject
|
||||
* @param string $idprof2 Prof id 2 of third party (Warning, this can return several records)
|
||||
* @param string $idprof3 Prof id 3 of third party (Warning, this can return several records)
|
||||
* @param string $idprof4 Prof id 4 of third party (Warning, this can return several records)
|
||||
* @param string $idprof5 Prof id 5 of third party (Warning, this can return several records)
|
||||
* @param string $idprof6 Prof id 6 of third party (Warning, this can return several records)
|
||||
* @return int >0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found.
|
||||
*/
|
||||
function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='')
|
||||
function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='')
|
||||
{
|
||||
global $langs;
|
||||
global $conf;
|
||||
|
||||
if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4)) return -1;
|
||||
if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6)) return -1;
|
||||
|
||||
$sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as date_creation, s.prefix_comm';
|
||||
$sql .= ', s.status';
|
||||
@ -1049,9 +1051,11 @@ class Societe extends CommonObject
|
||||
else if ($ref_int) $sql .= " WHERE s.ref_int = '".$this->db->escape($ref_int)."' AND s.entity IN (".getEntity($this->element, 1).")";
|
||||
else if ($idprof1) $sql .= " WHERE s.siren = '".$this->db->escape($idprof1)."' AND s.entity IN (".getEntity($this->element, 1).")";
|
||||
else if ($idprof2) $sql .= " WHERE s.siret = '".$this->db->escape($idprof2)."' AND s.entity IN (".getEntity($this->element, 1).")";
|
||||
else if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($idprof3)."' AND s.entity IN (".getEntity($this->element, 1).")"; // TODO This request is used ? Multiple database recording provided !!
|
||||
else if ($idprof3) $sql .= " WHERE s.ape = '".$this->db->escape($idprof3)."' AND s.entity IN (".getEntity($this->element, 1).")";
|
||||
else if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity IN (".getEntity($this->element, 1).")";
|
||||
|
||||
else if ($idprof5) $sql .= " WHERE s.idprof5 = '".$this->db->escape($idprof5)."' AND s.entity IN (".getEntity($this->element, 1).")";
|
||||
else if ($idprof6) $sql .= " WHERE s.idprof6 = '".$this->db->escape($idprof6)."' AND s.entity IN (".getEntity($this->element, 1).")";
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
dol_syslog(get_class($this)."::fetch ".$sql);
|
||||
if ($resql)
|
||||
@ -1059,11 +1063,11 @@ class Societe extends CommonObject
|
||||
$num=$this->db->num_rows($resql);
|
||||
if ($num > 1)
|
||||
{
|
||||
$this->error='Fetch several records found request';
|
||||
$this->error='Fetch found several records. Rename one of tirdparties to avoid duplicate.';
|
||||
dol_syslog($this->error, LOG_ERR);
|
||||
$result = -2;
|
||||
}
|
||||
if ($num)
|
||||
elseif ($num) // $num = 1
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
|
||||
@ -168,6 +168,7 @@ if (empty($reshook))
|
||||
if (!$errors && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id))
|
||||
{
|
||||
$errors++;
|
||||
setEventMessages($db->lasterror(), null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,6 +203,7 @@ if (empty($reshook))
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors');
|
||||
$db->rollback();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user