Skip to content

Commit 2f2c2fc

Browse files
author
Dolicraft
committed
fix Dolibarr#33642 set user name from company for corporation member
User::create_from_member copied lastname/firstname from the member, but a corporation member (morphy 'mor') has neither: its name is in the company field. The created user got a blank name and an empty built login. Use the company field as the lastname in that case so the user name and login are populated. Signed-off-by: Dolicraft <contact@dolicraft.com>
1 parent fad9bf5 commit 2f2c2fc

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

htdocs/user/class/user.class.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,8 +1734,15 @@ public function create_from_member($member, $login = '')
17341734
// Set properties on new user
17351735
$this->admin = 0;
17361736
$this->civility_code = $member->civility_id;
1737-
$this->lastname = $member->lastname;
1738-
$this->firstname = $member->firstname;
1737+
// A corporation member has no lastname/firstname (the name is in the company field), so use it as the
1738+
// user lastname, otherwise the created user would have an empty name (#33642).
1739+
if ($member->morphy == 'mor' && empty($member->lastname) && !empty($member->company)) {
1740+
$this->lastname = $member->company;
1741+
$this->firstname = '';
1742+
} else {
1743+
$this->lastname = $member->lastname;
1744+
$this->firstname = $member->firstname;
1745+
}
17391746
$this->gender = $member->gender;
17401747
$this->email = $member->email;
17411748
$this->fk_member = $member->id;
@@ -1752,7 +1759,8 @@ public function create_from_member($member, $login = '')
17521759

17531760
if (empty($login)) {
17541761
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1755-
$login = dol_buildlogin($member->lastname, $member->firstname);
1762+
// Use the resolved name so a corporation member (name in company field) still gets a login.
1763+
$login = dol_buildlogin($this->lastname, $this->firstname);
17561764
}
17571765
$this->login = $login;
17581766

0 commit comments

Comments
 (0)