mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 22:34:37 -04:00
Ensure when merging, we purge empty contacts
This commit is contained in:
parent
94670413ab
commit
75335ba8e4
@ -53,7 +53,7 @@ class Merge extends AbstractService
|
|||||||
/* Loop through contacts an only merge distinct contacts by email */
|
/* Loop through contacts an only merge distinct contacts by email */
|
||||||
$this->mergable_client->contacts->each(function ($contact) {
|
$this->mergable_client->contacts->each(function ($contact) {
|
||||||
$exist = $this->client->contacts->contains(function ($client_contact) use ($contact) {
|
$exist = $this->client->contacts->contains(function ($client_contact) use ($contact) {
|
||||||
return $client_contact->email == $contact->email;
|
return $client_contact->email == $contact->email || empty($contact->email) || $contact->email == ' ';
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($exist) {
|
if ($exist) {
|
||||||
|
@ -63,6 +63,62 @@ class ClientTest extends TestCase
|
|||||||
$this->makeTestData();
|
$this->makeTestData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testClientMergeContactDrop()
|
||||||
|
{
|
||||||
|
|
||||||
|
$c = Client::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id]);
|
||||||
|
|
||||||
|
ClientContact::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'client_id' => $c->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'is_primary' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
ClientContact::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'client_id' => $c->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
$c1 = Client::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id]);
|
||||||
|
|
||||||
|
ClientContact::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'client_id' => $c1->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'is_primary' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
ClientContact::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'client_id' => $c1->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
ClientContact::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'client_id' => $c1->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'email' => ''
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
$this->assertEquals(2, $c->contacts->count());
|
||||||
|
$this->assertEquals(3, $c1->contacts->count());
|
||||||
|
|
||||||
|
$c->service()->merge($c1);
|
||||||
|
|
||||||
|
$c = $c->fresh();
|
||||||
|
|
||||||
|
nlog($c->contacts->pluck('email'));
|
||||||
|
|
||||||
|
$this->assertEquals(4, $c->contacts->count());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private function buildLineItems($number = 2)
|
private function buildLineItems($number = 2)
|
||||||
{
|
{
|
||||||
$line_items = [];
|
$line_items = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user