commit melhorias compras5
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-22 19:39:09 +02:00
parent 36dcfdf00c
commit db1615fac1
79 changed files with 4082 additions and 120 deletions
+83
View File
@@ -37,12 +37,14 @@ use App\Services\EquipmentWorkflow;
use App\Services\FormalAdmission;
use App\Services\OrderCancellationPolicyWorkflow;
use App\Services\OrderCancellationWorkflow;
use App\Services\OrderPartsPreparation;
use App\Services\ProcurementReviewCsv;
use App\Services\ProcurementReviewReport;
use App\Services\ProposalComparison;
use App\Services\ProposalOpeningWorkflow;
use App\Services\PurchaseControlPolicyWorkflow;
use App\Services\PurchaseRevisionWorkflow;
use App\Services\PurchaseWorkflow;
use App\Services\QuotationExchange;
use App\Services\RequisitionBudgetDistributions;
use App\Services\RequisitionCatalogue;
@@ -1349,3 +1351,84 @@ test('quotation tasks hand a ready comparison to adjudication without reopening
$this->actingAs($this->buyer)->get('/requisicoes/tarefas?module=purchases')->assertInertia(fn (Assert $page) => $page->where('tasks.total', 0));
$this->get('/requisicoes/'.$this->r->id.'/cotacoes')->assertInertia(fn (Assert $page) => $page->where('canCreate', false)->where('canEvaluate', false));
});
test('optional partial-order preparation reuses native final approvals and preserves all documents and financial effects', function () {
if (! method_exists(BudgetControl::class, 'commitOrderParts')) {
$this->markTestSkipped('Explicit unpublished common source required.');
}
config(['order-parts.qa_enabled' => true]);
$award = selectPurchaseAward($this);
$service = app(OrderPartsPreparation::class);
$input = ['sources' => [['award_id' => $award->id, 'items' => [['quotation_item_id' => $this->quotes[0]->items()->sole()->id, 'quantity' => '0.400']]]]];
$this->actingAs($this->buyer);
expect(fn () => $service->prepare($this->buyer, $input))->toThrow(HttpException::class);
approvePurchaseAward($this, $award);
$this->actingAs($this->buyer);
$before = [PurchaseOrder::query()->count(), DB::table('budget_entries')->count(), DB::table('audit_logs')->count()];
$result = $service->prepare($this->buyer, $input);
expect($result)->toMatchArray(['currency' => 'MZN', 'subtotal_minor' => 4000, 'tax_minor' => 0, 'total_minor' => 4000, 'issued' => false, 'budget_effects' => false])
->and($result['sources'][0]['items'][0]['quantity_offset_milli'])->toBe(0)
->and($service->prepare($this->buyer, $input)['fingerprint'])->toBe($result['fingerprint'])
->and([PurchaseOrder::query()->count(), DB::table('budget_entries')->count(), DB::table('audit_logs')->count()])->toBe($before);
$this->actingAs($this->finance);
expect(fn () => $service->prepare($this->finance, $input))->toThrow(HttpException::class);
$this->actingAs($this->buyer);
$bad = $input;
$bad['sources'][0]['items'][0]['quantity'] = '1.001';
expect(fn () => $service->prepare($this->buyer, $bad))->toThrow(ValidationException::class);
config(['order-parts.qa_enabled' => false]);
expect(fn () => $service->prepare($this->buyer, $input))->toThrow(HttpException::class);
config(['order-parts.qa_enabled' => true]);
$this->post('/adjudicacoes/'.$award->id.'/emitir')->assertSessionHasNoErrors();
expect(fn () => $service->prepare($this->buyer, $input))->toThrow(ValidationException::class);
});
test('optional partial-order preparation consolidates two independently approved native origins without issuing or averaging data', function () {
if (! method_exists(BudgetControl::class, 'commitOrderParts')) {
$this->markTestSkipped('Explicit unpublished common source required.');
}
config(['order-parts.qa_enabled' => true]);
$first = selectPurchaseAward($this);
approvePurchaseAward($this, $first);
$this->actingAs($this->buyer);
$secondRequest = $this->r->fresh()->replicate();
$secondRequest->number = 'REQ-ORDER-SECOND-QA';
$secondRequest->subtotal_minor = $secondRequest->total_minor = 20000;
$secondRequest->save();
$line = $this->item->replicate();
$line->requisition_id = $secondRequest->id;
$line->unit_price_minor = $line->subtotal_minor = $line->total_minor = 20000;
$line->save();
foreach ($this->r->steps()->get() as $step) {
$copy = $step->replicate();
$copy->requisition_id = $secondRequest->id;
$copy->save();
}
$quotes = [];
foreach ($this->suppliers as $index => $supplier) {
$this->actingAs($this->buyer)->post('/requisicoes/'.$secondRequest->id.'/cotacoes', ['supplier_id' => $supplier->id,
'reference' => 'PROP-SECOND-'.$index, 'delivery_days' => 5, 'valid_until' => now()->addMonth()->format('Y-m-d'),
'payment_terms' => '30 dias', 'no_conflict' => true, 'items' => [['requisition_item_id' => $line->id, 'unit_price' => (string) (200 + $index * 100)]]])->assertSessionHasNoErrors();
$quote = Quotation::query()->where('requisition_id', $secondRequest->id)->latest('id')->firstOrFail();
$quotes[] = $quote;
foreach ([$this->buyer, $this->finance] as $evaluator) {
$this->actingAs($evaluator)->post('/cotacoes/'.$quote->id.'/avaliar', ['quality' => '8', 'history' => '5', 'payment' => '8',
'comment' => 'Independent synthetic evaluation for second origin.', 'no_conflict' => true])->assertSessionHasNoErrors();
}
}
$this->actingAs($this->buyer);
$second = app(PurchaseWorkflow::class)->select($this->buyer, $secondRequest, [...$this->selection, 'quotation_id' => $quotes[0]->id]);
approvePurchaseAward($this, $second);
$this->actingAs($this->buyer);
$before = [PurchaseOrder::query()->count(), DB::table('budget_entries')->count(), DB::table('audit_logs')->count()];
$input = ['sources' => [
['award_id' => $second->id, 'items' => [['quotation_item_id' => $quotes[0]->items()->sole()->id, 'quantity' => '0.500']]],
['award_id' => $first->id, 'items' => [['quotation_item_id' => $this->quotes[0]->items()->sole()->id, 'quantity' => '0.400']]],
]];
$result = app(OrderPartsPreparation::class)->prepare($this->buyer, $input);
expect($result)->toMatchArray(['currency' => 'MZN', 'total_minor' => 14000, 'issued' => false, 'budget_effects' => false])
->and($result['sources'])->toHaveCount(2)
->and(array_column($result['sources'], 'requisition_id'))->toBe([$this->r->id, $secondRequest->id])
->and(array_column($result['sources'], 'exchange_basis'))->toBe([null, null])
->and([PurchaseOrder::query()->count(), DB::table('budget_entries')->count(), DB::table('audit_logs')->count()])->toBe($before);
});