NEW option: assign default roles to "individual" third-party contacts (#30499)

* New option: assign default roles to "individual" third-party contacts

When the option to automatically create a contact for third parties of the "Individuals" type is active (THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION).

Allow to define the default roles assigned to these contacts.

Process:
1 Selection of default roles in the settings (and saving)
2 Creation of a third party of the "Individuals" type and therefore of its associated contact.
3 The contact thus created is automatically assigned the predefined roles.

* Update societe.php

* Update societe.php
This commit is contained in:
Sylvain Legrand 2024-07-31 15:32:07 +02:00 committed by GitHub
parent 871e01d955
commit 2c7dc2f28f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 0 deletions

View file

@ -2540,3 +2540,4 @@ MainAuthenticationOidcLoginClaimDesc=OpenID Connect claim matching the Dolibarr
BlackListWords=Black list of words
AddBlackList=Add to black list
AnOwnerMustBeSetIfEmailTemplateIsPrivate=An owner must be set if the email template is set as private
ContactsDefaultRoles=For third parties of the "individual" type, a contact can be created simultaneously. Define here the roles that will be systematically assigned to this contact.

View file

@ -2507,3 +2507,4 @@ SendToUrl=Envoyer à l'URL
WebsiteTemplateWasCopied=Le(s) modèle(s) de site Web "%s" fournis par ce module ont été enregistrés dans le répertoire des modèles de sites Web (/doctemplates/websites) et est prêt à être importé en tant que nouveau site Web.
EnabledByDefaultAtInstall=Activé par défaut lors de l'installation
VulnerableToRCEAttack=Vous êtes vulnérable aux attaques de type RCE en utilisant la fonction personnalisée dol_json_decode
ContactsDefaultRoles=Pour les les tiers de type "particulier" un contact peut-être créé simultanément. Définissez ici les rôles qui seront systématiquement attribués à ce contact.

View file

@ -31,6 +31,7 @@
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
$langs->loadLangs(array("admin", "companies", "other"));
@ -106,6 +107,19 @@ if ($action == 'updateoptions') {
setEventMessages($langs->trans("Error"), null, 'errors');
}
}
if (GETPOST('CONTACTS_DEFAULT_ROLES')) {
$rolessearch = GETPOST('activate_CONTACTS_DEFAULT_ROLES', 'array');
$res = dolibarr_set_const($db, "CONTACTS_DEFAULT_ROLES", implode(',', $rolessearch), 'chaine', 0, '', $conf->entity);
if (!($res > 0)) {
$error++;
}
if (!$error) {
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
setEventMessages($langs->trans("Error"), null, 'errors');
}
}
}
// Activate a document generator module
@ -926,6 +940,26 @@ if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTSCUSTOMERS')) {
print '</tr>';
}
if (getDolGlobalString('THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION')) {
print '<tr class="oddeven">';
print '<td width="80%">'.$langs->trans('ContactsDefaultRoles').'</td>';
if (!$conf->use_javascript_ajax) {
print '<td class="nowrap right" colspan="2">';
print $langs->trans("NotAvailableWhenAjaxDisabled");
print "</td>";
} else {
print '<td width="60" class="right">';
$contact = new Contact($db); // InfraS add
$contactType = $contact->listeTypeContacts('external', 0, 1);
$selected = explode(',', getDolGlobalString('CONTACTS_DEFAULT_ROLES'));
print $form->multiselectarray('activate_CONTACTS_DEFAULT_ROLES', $contactType, $selected, 0, 0, 'minwidth75imp');
print '</td><td class="right">';
print '<input type="submit" class="button small eposition" name="CONTACTS_DEFAULT_ROLES" value="'.$langs->trans("Modify").'">';
print "</td>";
}
print '</tr>';
}
print '</table>';
print '</div>';

View file

@ -1117,6 +1117,7 @@ class Societe extends CommonObject
$contact->town = $this->town;
$this->setUpperOrLowerCase();
$contact->phone_pro = $this->phone;
$contact->roles = explode(',', getDolGlobalString('CONTACTS_DEFAULT_ROLES'));
$contactId = $contact->create($user, $notrigger);
if ($contactId < 0) {