Skip to content

cdav: option to exclude supplier-only thirdparties’ contacts from CardDAV sync #78

Description

@infogm

Context

In some use cases, we do not want to synchronize contacts that are linked only to supplier thirdparties (i.e. fournisseur=1 and client=0) in the cdav module.

The idea is to keep customer-related contacts in CardDAV, but exclude contacts attached to supplier-only thirdparties.

Current behavior

In the SQL for contacts (_getSqlContacts($sqlWhere='') in CardDAVDolibarr.php), the query joins socpeople to societe but does not distinguish between:

  • thirdparties that are only suppliers (fournisseur=1 and client=0)
  • thirdparties that are customers or mixed (customer+supplier)

So, contacts linked to supplier-only thirdparties are synchronized by default.

Proposal

Add a boolean global setting:

  • CDAV_EXCLUDE_SUPPLIERS

When this setting is ON, contacts linked to supplier-only thirdparties are excluded from the CardDAV contacts addressbook.

Implementation (done / tested)

In CardDAVDolibarr.php, method _getSqlContacts($sqlWhere=''), after the base WHERE clause, we added:

dol_syslog(__METHOD__.' CDAV_EXCLUDE_SUPPLIERS='.getDolGlobalInt('CDAV_EXCLUDE_SUPPLIERS'), LOG_DEBUG);

if (getDolGlobalInt('CDAV_EXCLUDE_SUPPLIERS')) {
    $sql .= " AND NOT (COALESCE(s.fournisseur,0)=1 AND COALESCE(s.client,0)=0)";
}

This uses getDolGlobalInt('CDAV_EXCLUDE_SUPPLIERS'), which is already consistent with Dolibarr’s way of reading global constants.
The condition COALESCE(s.fournisseur,0)=1 AND COALESCE(s.client,0)=0 matches supplier-only thirdparties, and we wrap it in a NOT to exclude their contacts when the setting is enabled.

The rest of the _getSqlContacts method is left unchanged.

Admin setup

In admin/setup.php, the setting is defined and exposed as a checkbox:

dolibarr_set_const($db, "CDAV_EXCLUDE_SUPPLIERS",
    GETPOSTISSET('CDAV_EXCLUDE_SUPPLIERS') ? 1 : 0,
    'chaine', 0, '', $conf->entity);

and displayed like:

print '<tr>';
print '<td align="left"><strong>'.$langs->trans("Exclude suppliers only").'</strong><br>'.$langs->trans("Do not sync contacts linked to supplier-only third parties.").'</td>';
print '<td align="left">';
print '<input type="checkbox" name="CDAV_EXCLUDE_SUPPLIERS" value="1" '.(!empty($CDAV_EXCLUDE_SUPPLIERS) ? 'checked' : '').'>';
print '</td></tr>';

This stores the value in llx_const as usual for Dolibarr configuration constants.

Result

When CDAV_EXCLUDE_SUPPLIERS is enabled:

  • CardDAV still synchronizes contacts attached to customer or mixed thirdparties.
  • Contacts attached to supplier-only thirdparties (fournisseur=1 and client=0) are no longer synchronized.
  • Existing CardDAV behavior remains unchanged if the option is left off (backward compatible).

Environment

  • Dolibarr: 22.0.3
  • cdav module on a custom installation (3.1.4)
  • Behavior validated on a production instance with backup of modified files

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions