diff --git a/application/Espo/Modules/Crm/Controllers/Lead.php b/application/Espo/Modules/Crm/Controllers/Lead.php index d17a70bff7..447f76d315 100644 --- a/application/Espo/Modules/Crm/Controllers/Lead.php +++ b/application/Espo/Modules/Crm/Controllers/Lead.php @@ -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 { diff --git a/application/Espo/Modules/Crm/Resources/layouts/Contact/detailConvert.json b/application/Espo/Modules/Crm/Resources/layouts/Contact/detailConvert.json index e26ec8c139..75d057aeb1 100644 --- a/application/Espo/Modules/Crm/Resources/layouts/Contact/detailConvert.json +++ b/application/Espo/Modules/Crm/Resources/layouts/Contact/detailConvert.json @@ -1,7 +1,7 @@ [ { "rows": [ - [{"name":"name"}, false], + [{"name":"name"}, {"name": "account"}], [{"name":"emailAddress"}, {"name":"phoneNumber"}], [{"name":"title"}, false], [{"name":"address"}, false], diff --git a/application/Espo/Modules/Crm/Tools/Lead/ConvertService.php b/application/Espo/Modules/Crm/Tools/Lead/ConvertService.php index 2455eab6ac..177d29f620 100644 --- a/application/Espo/Modules/Crm/Tools/Lead/ConvertService.php +++ b/application/Espo/Modules/Crm/Tools/Lead/ConvertService.php @@ -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; + } }