lead convert: ability to select account

This commit is contained in:
Yuri Kuznetsov
2024-06-26 16:38:27 +03:00
parent 9d4266bed0
commit 2df98585f9
3 changed files with 28 additions and 3 deletions
@@ -32,9 +32,10 @@ namespace Espo\Modules\Crm\Controllers;
use Espo\Core\Controllers\Record;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Api\Request;
use Espo\Core\Exceptions\ConflictSilent;
use Espo\Core\Exceptions\Conflict;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\NotFound;
use Espo\Modules\Crm\Tools\Lead\Convert\Params as ConvertParams;
use Espo\Modules\Crm\Tools\Lead\Convert\Values;
use Espo\Modules\Crm\Tools\Lead\ConvertService;
@@ -45,7 +46,8 @@ class Lead extends Record
/**
* @throws BadRequest
* @throws Forbidden
* @throws ConflictSilent
* @throws Conflict
* @throws NotFound
*/
public function postActionConvert(Request $request): stdClass
{
@@ -1,7 +1,7 @@
[
{
"rows": [
[{"name":"name"}, false],
[{"name":"name"}, {"name": "account"}],
[{"name":"emailAddress"}, {"name":"phoneNumber"}],
[{"name":"title"}, false],
[{"name":"address"}, false],
@@ -101,6 +101,8 @@ class ConvertService
$account
);
$account ??= $this->getSelectedAccount($contact);
$opportunity = $this->processOpportunity(
$lead,
$records,
@@ -574,4 +576,25 @@ class ConvertService
$this->streamService->followEntity($contact, $this->user->getId());
}
}
private function getSelectedAccount(?Contact $contact): ?Account
{
if (!$contact) {
return null;
}
if (!$contact->getAccount()) {
return null;
}
$account = $this->entityManager
->getRDBRepositoryByClass(Account::class)
->getById($contact->getAccount()->getId());
if ($account && !$this->acl->checkEntityRead($account)) {
return null;
}
return $account;
}
}