feat: Aggiungi supporto per prezzi personalizzati nel listino e modifica la logica di importazione
This commit is contained in:
@@ -127,6 +127,61 @@ class ImportazioneListiniTest extends TestCase
|
||||
$this->assertNotNull($finestra->fresh()->listino_aggiornato_at);
|
||||
}
|
||||
|
||||
/** Listino con un prezzo da Excel e due aggiunti a mano (uno su una misura presente nel file). */
|
||||
private function finestraConPrezziPersonalizzati(): Modello
|
||||
{
|
||||
$finestra = Modello::where('codice', 'finestra_1_anta')->firstOrFail();
|
||||
ListinoPrezzo::create(['modello_id' => $finestra->id, 'larghezza' => 400, 'altezza' => 400, 'prezzo' => 1]);
|
||||
ListinoPrezzo::create(['modello_id' => $finestra->id, 'larghezza' => 500, 'altezza' => 400, 'prezzo' => 999, 'personalizzato' => true]);
|
||||
ListinoPrezzo::create(['modello_id' => $finestra->id, 'larghezza' => 2000, 'altezza' => 2000, 'prezzo' => 888, 'personalizzato' => true]);
|
||||
|
||||
return $finestra;
|
||||
}
|
||||
|
||||
private function importaFinestra(Modello $finestra, ?bool $sovrascriviTutto): void
|
||||
{
|
||||
$data = [
|
||||
'file' => $this->fileExcel(),
|
||||
'associazioni' => ['a' => ['codice' => 'finestra_1_anta', 'modello_id' => $finestra->id]],
|
||||
];
|
||||
if ($sovrascriviTutto !== null) {
|
||||
$data['sovrascrivi_tutto'] = $sovrascriviTutto;
|
||||
}
|
||||
|
||||
Livewire::test(ListSistemi::class)
|
||||
->callTableAction('importaListini', $this->pvc, data: $data)
|
||||
->assertHasNoTableActionErrors();
|
||||
}
|
||||
|
||||
public function test_di_default_l_excel_sovrascrive_anche_i_prezzi_personalizzati(): void
|
||||
{
|
||||
$finestra = $this->finestraConPrezziPersonalizzati();
|
||||
|
||||
Livewire::test(ListSistemi::class)
|
||||
->mountTableAction('importaListini', $this->pvc)
|
||||
->assertTableActionDataSet(['sovrascrivi_tutto' => true]);
|
||||
|
||||
$this->importaFinestra($finestra, null);
|
||||
|
||||
$this->assertSame(3, $finestra->listino()->count());
|
||||
$this->assertFalse($finestra->listino()->where('personalizzato', true)->exists());
|
||||
$this->assertEquals(381.24, $finestra->listino()->where('larghezza', 500)->where('altezza', 400)->value('prezzo'));
|
||||
}
|
||||
|
||||
public function test_si_possono_preservare_i_prezzi_personalizzati(): void
|
||||
{
|
||||
$finestra = $this->finestraConPrezziPersonalizzati();
|
||||
|
||||
$this->importaFinestra($finestra, false);
|
||||
|
||||
// 3 misure dal file (una sostituita dal prezzo personalizzato) + 1 personalizzata fuori file.
|
||||
$this->assertSame(4, $finestra->listino()->count());
|
||||
$this->assertEquals(367.2, $finestra->listino()->where('larghezza', 400)->where('altezza', 400)->value('prezzo'));
|
||||
$this->assertEquals(999, $finestra->listino()->where('larghezza', 500)->where('altezza', 400)->value('prezzo'));
|
||||
$this->assertEquals(888, $finestra->listino()->where('larghezza', 2000)->value('prezzo'));
|
||||
$this->assertSame(2, $finestra->listino()->where('personalizzato', true)->count());
|
||||
}
|
||||
|
||||
public function test_due_tabelle_non_possono_andare_sullo_stesso_modello(): void
|
||||
{
|
||||
$finestra = Modello::where('codice', 'finestra_1_anta')->firstOrFail();
|
||||
@@ -157,6 +212,8 @@ class ImportazioneListiniTest extends TestCase
|
||||
->assertHasTableActionErrors(['larghezza' => 'unique']);
|
||||
|
||||
$this->assertSame(2, $finestra->listino()->count());
|
||||
$this->assertTrue($finestra->listino()->where('larghezza', 500)->value('personalizzato'));
|
||||
$this->assertFalse($prezzo->fresh()->personalizzato);
|
||||
}
|
||||
|
||||
public function test_api_listino_restituisce_la_griglia_ordinata(): void
|
||||
|
||||
Reference in New Issue
Block a user