FIX Multiccompany sharings compatibility

This commit is contained in:
Regis Houssin 2022-03-24 16:34:08 +01:00
parent 872cbd1fdc
commit e8dae7a8db
3 changed files with 39 additions and 29 deletions

View File

@ -4374,9 +4374,10 @@ abstract class CommonObject
* Check is done into this->childtables. There is no check into llx_element_element. * Check is done into this->childtables. There is no check into llx_element_element.
* *
* @param int $id Force id of object * @param int $id Force id of object
* @param int $entity Force entity to check
* @return int <0 if KO, 0 if not used, >0 if already used * @return int <0 if KO, 0 if not used, >0 if already used
*/ */
public function isObjectUsed($id = 0) public function isObjectUsed($id = 0, $entity = 0)
{ {
global $langs; global $langs;
@ -4399,11 +4400,21 @@ abstract class CommonObject
// Test if child exists // Test if child exists
$haschild = 0; $haschild = 0;
foreach ($arraytoscan as $table => $elementname) { foreach ($arraytoscan as $table => $element) {
//print $id.'-'.$table.'-'.$elementname.'<br>'; //print $id.'-'.$table.'-'.$elementname.'<br>';
// Check if third party can be deleted // Check if element can be deleted
$sql = "SELECT COUNT(*) as nb from ".$this->db->prefix().$table; $sql = "SELECT COUNT(*) as nb";
$sql .= " WHERE ".$this->fk_element." = ".((int) $id); $sql.= " FROM ".$this->db->prefix().$table." as c";
if (!empty($element['parent']) && !empty($element['parentkey'])) {
$sql.= ", ".$this->db->prefix().$element['parent']." as p";
}
$sql.= " WHERE c.".$this->fk_element." = ".((int) $id);
if (!empty($element['parent']) && !empty($element['parentkey'])) {
$sql.= " AND c.".$element['parentkey']." = p.rowid";
}
if (!empty($entity)) {
$sql.= " AND entity = ".((int) $entity);
}
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
@ -4411,11 +4422,10 @@ abstract class CommonObject
$langs->load("errors"); $langs->load("errors");
//print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild; //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild;
$haschild += $obj->nb; $haschild += $obj->nb;
if (is_numeric($elementname)) { // old usage if (is_numeric($element) || empty($element['name'])) { // old usage
$this->errors[] = $langs->transnoentities("ErrorRecordHasAtLeastOneChildOfType", method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref, $table); $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref, $table);
} else // new usage: $elementname=Translation key } else { // new usage: $element['name']=Translation key
{ $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref, $langs->transnoentitiesnoconv($element['name']));
$this->errors[] = $langs->transnoentities("ErrorRecordHasAtLeastOneChildOfType", method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref, $langs->transnoentitiesnoconv($elementname));
} }
break; // We found at least one, we stop here break; // We found at least one, we stop here
} }

View File

@ -64,13 +64,13 @@ class Product extends CommonObject
* @var array List of child tables. To test if we can delete object. * @var array List of child tables. To test if we can delete object.
*/ */
protected $childtables = array( protected $childtables = array(
'supplier_proposaldet', 'supplier_proposaldet' => array('parent' => 'supplier_proposal', 'parentkey' => 'fk_supplier_proposal'),
'propaldet', 'propaldet' => array('parent' => 'propal', 'parentkey' => 'fk_propal'),
'commandedet', 'commandedet' => array('parent' => 'commande', 'parentkey' => 'fk_commande'),
'facturedet', 'facturedet' => array('parent' => 'facture', 'parentkey' => 'fk_facture'),
'contratdet', 'contratdet' => array('parent' => 'contrat', 'parentkey' => 'fk_contrat'),
'facture_fourn_det', 'facture_fourn_det' => array('parent' => 'facture_fourn', 'parentkey' => 'fk_facture_fourn'),
'commande_fournisseurdet' 'commande_fournisseurdet' => array('parent' => 'commande_fournisseur', 'parentkey' => 'fk_commande')
); );
/** /**

View File

@ -73,18 +73,18 @@ class Societe extends CommonObject
* @var array List of child tables. To test if we can delete object. * @var array List of child tables. To test if we can delete object.
*/ */
protected $childtables = array( protected $childtables = array(
"supplier_proposal" => 'SupplierProposal', "supplier_proposal" => array('name' => 'SupplierProposal'),
"propal" => 'Proposal', "propal" => array('name' => 'Proposal'),
"commande" => 'Order', "commande" => array('name' => 'Order'),
"facture" => 'Invoice', "facture" => array('name' => 'Invoice'),
"facture_rec" => 'RecurringInvoiceTemplate', "facture_rec" => array('name' => 'RecurringInvoiceTemplate'),
"contrat" => 'Contract', "contrat" => array('name' => 'Contract'),
"fichinter" => 'Fichinter', "fichinter" => array('name' => 'Fichinter'),
"facture_fourn" => 'SupplierInvoice', "facture_fourn" => array('name' => 'SupplierInvoice'),
"commande_fournisseur" => 'SupplierOrder', "commande_fournisseur" => array('name' => 'SupplierOrder'),
"projet" => 'Project', "projet" => array('name' => 'Project'),
"expedition" => 'Shipment', "expedition" => array('name' => 'Shipment'),
"prelevement_lignes" => 'DirectDebitRecord', "prelevement_lignes" => array('name' => 'DirectDebitRecord'),
); );
/** /**