Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Model/TrabajoAT.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ protected function onDelete(): void
{
parent::onDelete();

$service = $this->getServicio();
$service->calculatePriceNet();
$this->updateStock($this->referencia, $this->cantidad, $this->estado);
}

Expand Down
38 changes: 38 additions & 0 deletions Test/main/TrabajoAtTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,44 @@ public function testCreateInvoice(): void
$this->assertTrue($customer->delete());
}

public function testUpdateOnDelete(): void
{
// creamos un cliente
$customer = $this->getRandomCustomer();
$this->assertTrue($customer->save());

// creamos un servicio
$service = new ServicioAT();
$service->codalmacen = Tools::settings('default', 'codalmacen');
$service->codcliente = $customer->codcliente;
$service->descripcion = 'Test';
$service->idempresa = Tools::settings('default', 'idempresa');
$this->assertTrue($service->save());

// creamos un trabajo
$work = new TrabajoAT();
$work->idservicio = $service->idservicio;
$work->descripcion = 'Test work';
$work->cantidad = 1;
$work->precio = 10;
$this->assertTrue($work->save(), 'Error creating TrabajoAT');

// comprobamos que se ha actualizado el neto del servicio
$service->load($service->id());
$this->assertEquals(10, $service->neto);

// eliminamos el trabajo
$this->assertTrue($work->delete());

// comprobamos que se ha actualizado el neto del servicio
$service->load($service->id());
$this->assertEquals(0, $service->neto);

// eliminamos
$this->assertTrue($service->delete());
$this->assertTrue($customer->delete());
}

protected function tearDown(): void
{
$this->logErrors();
Expand Down