commit compras2 2811
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-28 15:45:52 +02:00
parent eb32c74c56
commit 060c119ba1
92 changed files with 4936 additions and 43 deletions
+89
View File
@@ -41,6 +41,7 @@ use App\Services\EquipmentWorkflow;
use App\Services\FormalAdmission;
use App\Services\ImportTariffCodes;
use App\Services\InvoiceWorkflow;
use App\Services\OperationalOrders;
use App\Services\OrderCancellationPolicyWorkflow;
use App\Services\OrderCancellationWorkflow;
use App\Services\OrderPartsAmendments;
@@ -62,6 +63,7 @@ use App\Services\RequisitionBudgetDistributions;
use App\Services\RequisitionCatalogue;
use App\Services\RequisitionWorkflow;
use App\Services\SupplyPlanning;
use App\Services\UrgentQuotationBasis;
use App\Services\WorkflowTaskInbox;
use Brick\Math\BigDecimal;
use Carbon\CarbonImmutable;
@@ -97,6 +99,93 @@ function nativeCapitalAssignment(object $test, string $type = 'project'): array
return [$source, $assignment, $input];
}
test('native orders freeze their production origin in normal and partial issuance', function (bool $partial) {
if ($partial && ! method_exists(BudgetControl::class, 'commitOrderParts')) {
$this->markTestSkipped('Select the approved isolated-QA common source for native order parts.');
}
config(['operational-orders.qa_enabled' => true]);
$service = app(OperationalOrders::class);
$this->actingAs($this->admin);
$service->configure($this->admin, ['version' => 0, 'mode' => 'procurement', 'reason' => 'Origem sintética pelo procurement sem locais abrangidos.', 'operation_key' => (string) Str::uuid()]);
$this->actingAs($this->buyer);
$source = $service->save($this->buyer, ['type' => 'production', 'reference' => 'PRODUCTION-ORIGIN-QA', 'department_id' => $this->department->id,
'utilisation_location' => 'Linha sintética de utilização', 'description' => 'Trabalho fictício preservado na ordem de compra.', 'reason' => 'Registo sintético de produção para teste nativo.', 'policy_version' => 1, 'operation_key' => (string) Str::uuid()]);
// Add the source selected while the existing pre-approved synthetic fixture was a draft.
$this->r->update(['status' => 'draft']);
$this->actingAs($this->owner);
$link = $service->link($this->owner, $this->r, ['item_id' => $this->item->id, 'order_id' => $source->id, 'version' => 0, 'reason' => 'Origem documental escolhida pelo requisitante sintético.', 'operation_key' => (string) Str::uuid()]);
$this->r->update(['status' => 'approved']);
$this->actingAs($this->buyer);
if ($partial) {
$award = nativeOrderPartsAward($this);
$order = app(OrderPartsWorkflow::class)->issue($this->buyer, nativeOrderPartsInput($this, $award, '0.400', 0));
} else {
$order = issuePurchaseOrder($this, selectPurchaseAward($this));
}
expect($order->snapshot['operational_orders'][$this->item->id]['id'])->toBe($link->id)
->and($order->snapshot['operational_orders'][$this->item->id]['snapshot']['source']['id'])->toBe($source->id)
->and($order->total_minor)->toBe($partial ? 4000 : 10000);
$this->actingAs($this->admin);
$service->configure($this->admin, ['version' => 1, 'mode' => 'utilisation', 'reason' => 'Configuração posterior que conserva a origem anterior.', 'operation_key' => (string) Str::uuid()]);
$this->actingAs($this->buyer)->get('/ordens/'.$order->id.'/imprimir')->assertOk()->assertSee('PRODUCTION-ORIGIN-QA')->assertSee('Registada pelo procurement')->assertSee('Linha sintética de utilização');
expect($order->fresh()->snapshot['operational_orders'][$this->item->id]['snapshot']['source']['snapshot']['policy']['data']['mode'])->toBe('procurement');
})->with([false, true]);
test('native urgent order uses only the configured reduced eligible count and preserves stock evidence with independent approvals', function (bool $partial) {
if ($partial && ! method_exists(BudgetControl::class, 'commitOrderParts')) {
$this->markTestSkipped('Select the approved isolated-QA common source for native order parts.');
}
config(['urgent-quotations.qa_enabled' => true]);
$this->actingAs($this->admin);
$stock = StockItem::query()->create(['tenant_id' => $this->tenant->id, 'created_by' => $this->admin->id, 'code' => 'URGENT-STOCK-QA', 'name' => $this->item->description, 'unit' => $this->item->unit]);
$warehouse = Warehouse::query()->create(['tenant_id' => $this->tenant->id, 'created_by' => $this->admin->id, 'code' => 'URGENT-WH-QA', 'name' => 'Local sintético da urgência']);
app(RequisitionCatalogue::class)->save($this->admin, $stock->id, ['version' => 0, 'stock_basis' => app(RequisitionCatalogue::class)->basis($stock),
'category' => 'Material', 'purchase_type' => 'consumable', 'published' => true, 'reason' => 'Catálogo sintético antes da redução urgente.']);
$entry = DB::table('requisition_catalogue')->where('stock_item_id', $stock->id)->sole();
$this->actingAs($this->owner);
$resolved = app(RequisitionCatalogue::class)->line($this->owner, ['catalogue_entry_id' => $entry->id, 'catalogue_version' => 1], []);
$this->item->update(['catalogue_entry_id' => $entry->id, 'catalogue_snapshot' => $resolved['catalogue_snapshot']]);
// The initial approved request/three offers are synthetic fixtures. Only one supplier remains eligible before adjudication.
$this->r->update(['priority' => 'urgent', 'justification' => 'Risco sintético de paragem por falta de material no local de utilização.',
'comparison_policy' => app(ComparisonPolicy::class)->checked([...ComparisonPolicy::DEFAULTS, 'configured' => true, 'revision' => 1, 'urgent_minimum_proposals' => 1])]);
foreach ([$this->suppliers[1], $this->suppliers[2]] as $supplier) {
$supplier->update(['status' => 'suspended']);
}
foreach ([$this->owner, $this->buyer, $this->secondBuyer, $this->head, $this->finance, $this->admin] as $person) {
supplyGrant($person, [$person->purchasing_role->value, ...($person->id === $this->buyer->id ? ['supply_prepare'] : []), ...($person->id === $this->finance->id ? ['supply_review'] : [])]);
}
$this->actingAs($this->buyer);
$planning = app(SupplyPlanning::class);
$draft = $planning->save($this->buyer, 'policy', supplyInput(supplyPolicy(['stock' => $stock, 'warehouse' => $warehouse])));
$this->actingAs($this->finance);
$policy = $planning->save($this->finance, 'policy', supplyInput([], 'approve', $draft));
$this->actingAs($this->buyer);
expect(app(ProposalComparison::class)->inspect($this->r)['ready'])->toBeFalse();
$this->post($this->awardUrl, $this->selection)->assertSessionHasErrors('comparison');
expect(PurchaseAward::query()->count())->toBe(0);
$proof = app(UrgentQuotationBasis::class)->record($this->buyer, $this->r, ['item_id' => $this->item->id, 'policy_id' => $policy->id, 'version' => 0,
'reason' => 'URGENT-MINIMUM-NATIVE-QA: mínimo atingido no local sintético.', 'operation_key' => (string) Str::uuid()]);
$comparison = app(ProposalComparison::class)->inspect($this->r);
expect($comparison['ready'])->toBeTrue()->and(count(array_filter($comparison['rows'], fn ($row) => $row['eligible'])))->toBe(1)
->and($comparison['policy']['minimum_evaluators'])->toBe(2);
if ($partial) {
$award = nativeOrderPartsAward($this);
$order = app(OrderPartsWorkflow::class)->issue($this->buyer, nativeOrderPartsInput($this, $award, '0.400', 0));
} else {
$award = selectPurchaseAward($this);
$this->actingAs($this->owner)->post('/adjudicacoes/'.$award->id.'/decidir', ['decision' => 'approved'])->assertForbidden();
$this->actingAs($this->buyer);
$this->post('/adjudicacoes/'.$award->id.'/emitir')->assertSessionHasErrors('approvals');
$order = issuePurchaseOrder($this, $award);
}
expect($order->snapshot['urgent_quotation_basis'][0]['id'])->toBe($proof->id)
->and($order->snapshot['comparison_policy']['minimum_proposals'])->toBe(1)
->and($order->snapshot['comparison_policy']['normal_minimum_proposals'])->toBe(3)
->and($order->total_minor)->toBe($partial ? 4000 : 10000);
$this->get('/ordens/'.$order->id.'/imprimir')->assertOk()->assertSee('URGENT-MINIMUM-NATIVE-QA')->assertSee('Local sintético da urgência');
expect($award->approvals()->where('decision', 'approved')->count())->toBeGreaterThan(0);
})->with([false, true]);
test('native order preserves the capital destination and print after the independent register is archived', function () {
[$source, $assignment, $input] = nativeCapitalAssignment($this);
$award = selectPurchaseAward($this);