Criar Hotel: a actividade escolhida no dossier mantém-se ao longo do percurso
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
Uma oportunidade, sector, parque ou território acrescentado depois só propõe outra actividade; o sector e a actividade do dossier deixam de ser trocados ou apagados sem o investidor o pedir. A pré-visualização mostra «conserva … ; a fonte propõe …» e há uma opção explícita para mudar. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
This commit is contained in:
@@ -26,6 +26,9 @@ final class InvestorContext
|
||||
|
||||
public const FIELDS = ['promoter_entity_key', 'legal_name', 'legal_form', 'registration_number', 'products_services', 'investment_budget_min', 'investment_budget_max', 'project_title', 'project_summary', 'sector_id', 'sector', 'province_id', 'district_id', 'admin_post_id', 'locality_id', 'province', 'district', 'location', 'currency', 'expected_start_date', 'fiscal_period', 'fiscal_periodicity', 'fiscal_month', 'investor_origin', 'person_type', 'entity_stage', 'tax_residency_country', 'fiscal_residency_country', 'activity_id', 'project_type', 'maturity_stage', 'special_zone_id', 'investment_regime', ...PrivateInvestmentPreparation::FIELDS];
|
||||
|
||||
/** The investor's primary intention: once chosen, later references may only propose a different one. */
|
||||
public const INTENTION_FIELDS = ['sector_id', 'sector', 'activity_id'];
|
||||
|
||||
public function __construct(private readonly VirtualDesk $desk) {}
|
||||
|
||||
/**
|
||||
@@ -674,7 +677,9 @@ final class InvestorContext
|
||||
$provenance[$key] = ['kind' => 'process_declaration', 'actor_id' => $actor->id, 'context_revision' => $old['revision'] + 1];
|
||||
}
|
||||
foreach ($proposed as $key => $value) {
|
||||
if (($fields[$key] ?? '') === '' || (($provenance[$key]['kind'] ?? '') !== 'process_declaration' && ($provenance[$key]['kind'] ?? '') !== 'dossier') || in_array($key, $data['replace_fields'] ?? [], true)) {
|
||||
// A hotel stays a hotel: another activity is only proposed, never swapped in silently.
|
||||
$intention = in_array($key, self::INTENTION_FIELDS, true) && ($fields[$key] ?? '') !== '';
|
||||
if (($fields[$key] ?? '') === '' || (! $intention && ($provenance[$key]['kind'] ?? '') !== 'process_declaration' && ($provenance[$key]['kind'] ?? '') !== 'dossier') || in_array($key, $data['replace_fields'] ?? [], true)) {
|
||||
if (($fields[$key] ?? null) !== $value) {
|
||||
$replaced[] = ['field' => $key, 'before' => $fields[$key] ?? null, 'after' => $value];
|
||||
}$fields[$key] = $value;
|
||||
@@ -685,7 +690,7 @@ final class InvestorContext
|
||||
}
|
||||
// Remove inherited subordinate geography only when its source was actually replaced.
|
||||
foreach ($fields as $key => $value) {
|
||||
if (! array_key_exists($key, $proposed) && in_array($key, ['province_id', 'district_id', 'admin_post_id', 'locality_id', 'province', 'district', 'location', 'sector_id', 'sector', 'special_zone_id', 'investment_regime'], true) && isset($provenance[$key]['key'])) {
|
||||
if (! array_key_exists($key, $proposed) && in_array($key, ['province_id', 'district_id', 'admin_post_id', 'locality_id', 'province', 'district', 'location', 'special_zone_id', 'investment_regime'], true) && isset($provenance[$key]['key'])) {
|
||||
unset($fields[$key],$provenance[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1316,7 +1316,7 @@ function ScopedContextEditor({
|
||||
Substituições explícitas de declarações
|
||||
</summary>
|
||||
<p>
|
||||
Por defeito, uma seleção conserva o título e as
|
||||
Por defeito, uma selecção conserva o título e as
|
||||
declarações do utilizador. Autorize somente os
|
||||
campos que pretende substituir pelo cadastro.
|
||||
</p>
|
||||
@@ -1337,10 +1337,40 @@ function ScopedContextEditor({
|
||||
setPlan(null);
|
||||
}}
|
||||
/>{' '}
|
||||
Usar a fonte selecionada em{' '}
|
||||
Usar a fonte seleccionada em{' '}
|
||||
{contextFieldNames[k].toLowerCase()}
|
||||
</label>
|
||||
))}
|
||||
{view.context.fields.sector && (
|
||||
<label className="block">
|
||||
<input
|
||||
type="checkbox"
|
||||
disabled={busy}
|
||||
checked={replace.includes('sector_id')}
|
||||
onChange={(e) => {
|
||||
const keys = ['sector_id', 'sector'];
|
||||
setReplace(
|
||||
e.target.checked
|
||||
? [
|
||||
...replace.filter(
|
||||
(x) =>
|
||||
!keys.includes(x),
|
||||
),
|
||||
...keys,
|
||||
]
|
||||
: replace.filter(
|
||||
(x) => !keys.includes(x),
|
||||
),
|
||||
);
|
||||
setPlan(null);
|
||||
}}
|
||||
/>{' '}
|
||||
Mudar a actividade principal deste dossier (
|
||||
{view.context.fields.sector}) para a da
|
||||
selecção. Sem esta escolha, a actividade
|
||||
inicial mantém-se.
|
||||
</label>
|
||||
)}
|
||||
</details>
|
||||
{view.private_investment && (
|
||||
<PreparationEditor
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Sector;
|
||||
use App\Models\User;
|
||||
use App\Services\InvestmentZones;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
@@ -100,4 +101,34 @@ class InvestmentContextContinuityTest extends TestCase
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/previa', ['version' => $view['case']['version'], 'selection' => [], 'declarations' => ['project_title' => 'Título revisto']])
|
||||
->assertOk()->assertJsonPath('dependency_changed', false)->assertJsonPath('review_steps', []);
|
||||
}
|
||||
|
||||
public function test_the_primary_activity_is_kept_until_the_investor_explicitly_changes_it(): void
|
||||
{
|
||||
// Mapa de erros, "Criar Hotel": a hotel dossier is never moved to another activity by a later reference.
|
||||
$owner = User::factory()->create();
|
||||
$id = $this->dossier($owner, 'Criar Hotel');
|
||||
// Synthetic sectors, rolled back with the transaction; never catalogue data.
|
||||
[$tourism, $agro] = array_map(fn (string $name) => Sector::forceCreate(['name' => 'SINTÉTICO QA '.$name, 'slug' => 'sintetico-qa-'.Str::lower(Str::random(12)), 'is_active' => true]), ['Hotelaria', 'Agronegócio']);
|
||||
$apply = function (array $selection, array $replace = []) use ($id): array {
|
||||
$view = $this->getJson('/investimentos/'.$id.'/contexto')->assertOk()->json();
|
||||
$body = ['version' => $view['case']['version'], 'selection' => $selection, 'replace_fields' => $replace];
|
||||
$plan = $this->postJson('/investimentos/'.$id.'/contexto/previa', $body)->assertOk()->json();
|
||||
$this->postJson('/investimentos/'.$id.'/contexto/confirmar', [...$body, 'preview_hash' => $plan['preview_hash'], 'operation_key' => (string) Str::uuid(), 'confirm' => true])->assertOk();
|
||||
|
||||
return $plan;
|
||||
};
|
||||
$apply(['sector' => 'sector:'.$tourism->id]);
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.fields.sector_id', (string) $tourism->id);
|
||||
|
||||
$plan = $apply(['sector' => 'sector:'.$agro->id]);
|
||||
$this->assertSame((string) $tourism->id, $plan['fields']['sector_id']);
|
||||
$this->assertContains(['field' => 'sector', 'value' => $tourism->name, 'proposed' => $agro->name], $plan['maintained']);
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.fields.sector', $tourism->name);
|
||||
|
||||
$apply(['sector' => null]);
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.fields.sector_id', (string) $tourism->id);
|
||||
|
||||
$apply(['sector' => 'sector:'.$agro->id], ['sector_id', 'sector']);
|
||||
$this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.fields.sector_id', (string) $agro->id)->assertJsonPath('context.fields.sector', $agro->name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user