From 08c11e66e421f998a713dd929d2f9e2de0d89caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20S=C3=A1nchez?= Date: Tue, 4 Aug 2026 12:36:56 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Actualiza=20la=20gesti=C3=B3n=20de=20tel?= =?UTF-8?q?=C3=A9fonos=20en=20ServicioAT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Se añade lógica para actualizar automáticamente los teléfonos del servicio al cambiar el cliente, siempre que no se hayan modificado manualmente. - Se implementan pruebas para verificar el comportamiento de actualización de teléfonos al cambiar de cliente, incluyendo la preservación de números manualmente modificados. Archivos modificados: - ServicioAT.php - ServicioAtTest.php --- Model/ServicioAT.php | 9 ++++ Test/main/ServicioAtTest.php | 79 ++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/Model/ServicioAT.php b/Model/ServicioAT.php index 519f266..901ecb2 100644 --- a/Model/ServicioAT.php +++ b/Model/ServicioAT.php @@ -363,6 +363,15 @@ public function test(): bool $customer = $this->getSubject(); $this->telefono1 = $customer->telefono1; $this->telefono2 = $customer->telefono2; + } elseif ($this->exists() && $this->codcliente != $this->getOriginal('codcliente')) { + // si cambiamos el cliente y los teléfonos no se han modificado manualmente, + // los actualizamos con los del nuevo cliente + $oldCustomer = $this->getCustomer($this->getOriginal('codcliente') ?? ''); + if ($this->telefono1 == $oldCustomer->telefono1 && $this->telefono2 == $oldCustomer->telefono2) { + $customer = $this->getSubject(); + $this->telefono1 = $customer->telefono1; + $this->telefono2 = $customer->telefono2; + } } $fields = ['codigo', 'descripcion', 'material', 'observaciones', 'solucion', 'telefono1', 'telefono2']; diff --git a/Test/main/ServicioAtTest.php b/Test/main/ServicioAtTest.php index 9524811..a9a1a83 100644 --- a/Test/main/ServicioAtTest.php +++ b/Test/main/ServicioAtTest.php @@ -283,6 +283,85 @@ public function testDefaultType(): void $this->assertTrue($customer->delete()); } + public function testUpdatePhoneOnCustomerChange(): void + { + // creamos dos clientes con teléfonos distintos + $customer1 = $this->getRandomCustomer(); + $customer1->telefono1 = '111111111'; + $customer1->telefono2 = '222222222'; + $this->assertTrue($customer1->save()); + + $customer2 = $this->getRandomCustomer(); + $customer2->telefono1 = '333333333'; + $customer2->telefono2 = '444444444'; + $this->assertTrue($customer2->save()); + + // creamos un servicio con el primer cliente + $service = new ServicioAT(); + $service->codalmacen = Tools::settings('default', 'codalmacen'); + $service->codcliente = $customer1->codcliente; + $service->descripcion = 'Test service'; + $service->idempresa = Tools::settings('default', 'idempresa'); + $this->assertTrue($service->save()); + + // comprobamos que se ha rellenado con el teléfono del primer cliente + $this->assertEquals($customer1->telefono1, $service->telefono1); + $this->assertEquals($customer1->telefono2, $service->telefono2); + + // cambiamos el cliente asignado + $service->codcliente = $customer2->codcliente; + $this->assertTrue($service->save()); + + // comprobamos que el teléfono se ha actualizado al del nuevo cliente + $this->assertEquals($customer2->telefono1, $service->telefono1); + $this->assertEquals($customer2->telefono2, $service->telefono2); + + // eliminamos + $this->assertTrue($service->delete()); + $this->assertTrue($customer1->delete()); + $this->assertTrue($customer2->delete()); + } + + public function testKeepManualPhoneOnCustomerChange(): void + { + // creamos dos clientes con teléfonos distintos + $customer1 = $this->getRandomCustomer(); + $customer1->telefono1 = '111111111'; + $customer1->telefono2 = '222222222'; + $this->assertTrue($customer1->save()); + + $customer2 = $this->getRandomCustomer(); + $customer2->telefono1 = '333333333'; + $customer2->telefono2 = '444444444'; + $this->assertTrue($customer2->save()); + + // creamos un servicio con el primer cliente + $service = new ServicioAT(); + $service->codalmacen = Tools::settings('default', 'codalmacen'); + $service->codcliente = $customer1->codcliente; + $service->descripcion = 'Test service'; + $service->idempresa = Tools::settings('default', 'idempresa'); + $this->assertTrue($service->save()); + + // modificamos el teléfono manualmente + $service->telefono1 = '999999999'; + $service->telefono2 = '888888888'; + $this->assertTrue($service->save()); + + // cambiamos el cliente asignado + $service->codcliente = $customer2->codcliente; + $this->assertTrue($service->save()); + + // comprobamos que el teléfono manual no se ha sobrescrito + $this->assertEquals('999999999', $service->telefono1); + $this->assertEquals('888888888', $service->telefono2); + + // eliminamos + $this->assertTrue($service->delete()); + $this->assertTrue($customer1->delete()); + $this->assertTrue($customer2->delete()); + } + protected function tearDown(): void { $this->logErrors(); From 244cd8a18a2b9d86c068d29709fa3029edec50b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20S=C3=A1nchez?= Date: Thu, 6 Aug 2026 13:47:26 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Actualiza=20la=20l=C3=B3gica=20de=20actuali?= =?UTF-8?q?zaci=C3=B3n=20de=20tel=C3=A9fonos=20en=20ServicioAT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Modifica la función de cambio de cliente para que solo actualice el teléfono 2 si no ha sido modificado manualmente. - Añade una nueva prueba en ServicioAtTest para verificar el comportamiento esperado al cambiar de cliente con teléfonos distintos. Archivos modificados: - ServicioAT.php - ServicioAtTest.php --- Model/ServicioAT.php | 6 ++++-- Test/main/ServicioAtTest.php | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Model/ServicioAT.php b/Model/ServicioAT.php index 901ecb2..4776a36 100644 --- a/Model/ServicioAT.php +++ b/Model/ServicioAT.php @@ -367,9 +367,11 @@ public function test(): bool // si cambiamos el cliente y los teléfonos no se han modificado manualmente, // los actualizamos con los del nuevo cliente $oldCustomer = $this->getCustomer($this->getOriginal('codcliente') ?? ''); - if ($this->telefono1 == $oldCustomer->telefono1 && $this->telefono2 == $oldCustomer->telefono2) { - $customer = $this->getSubject(); + $customer = $this->getSubject(); + if ($this->telefono1 == $oldCustomer->telefono1) { $this->telefono1 = $customer->telefono1; + } + if ($this->telefono2 == $oldCustomer->telefono2) { $this->telefono2 = $customer->telefono2; } } diff --git a/Test/main/ServicioAtTest.php b/Test/main/ServicioAtTest.php index a9a1a83..975c9d1 100644 --- a/Test/main/ServicioAtTest.php +++ b/Test/main/ServicioAtTest.php @@ -362,6 +362,45 @@ public function testKeepManualPhoneOnCustomerChange(): void $this->assertTrue($customer2->delete()); } + public function testUpdateOnlyUnmodifiedPhoneOnCustomerChange(): void + { + // creamos dos clientes con teléfonos distintos + $customer1 = $this->getRandomCustomer(); + $customer1->telefono1 = '111111111'; + $customer1->telefono2 = '222222222'; + $this->assertTrue($customer1->save()); + + $customer2 = $this->getRandomCustomer(); + $customer2->telefono1 = '333333333'; + $customer2->telefono2 = '444444444'; + $this->assertTrue($customer2->save()); + + // creamos un servicio con el primer cliente + $service = new ServicioAT(); + $service->codalmacen = Tools::settings('default', 'codalmacen'); + $service->codcliente = $customer1->codcliente; + $service->descripcion = 'Test service'; + $service->idempresa = Tools::settings('default', 'idempresa'); + $this->assertTrue($service->save()); + + // modificamos manualmente solo el teléfono 1 + $service->telefono1 = '999999999'; + $this->assertTrue($service->save()); + + // cambiamos el cliente asignado + $service->codcliente = $customer2->codcliente; + $this->assertTrue($service->save()); + + // el teléfono 1 modificado manualmente no cambia, el teléfono 2 se actualiza + $this->assertEquals('999999999', $service->telefono1); + $this->assertEquals($customer2->telefono2, $service->telefono2); + + // eliminamos + $this->assertTrue($service->delete()); + $this->assertTrue($customer1->delete()); + $this->assertTrue($customer2->delete()); + } + protected function tearDown(): void { $this->logErrors();