1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Convert quote to project tests

This commit is contained in:
= 2022-08-15 13:49:47 +10:00
parent fa2c9fdcdd
commit 9d5c181634
3 changed files with 46 additions and 15 deletions

View File

@ -22,7 +22,8 @@ class CloneQuoteToProjectFactory
$project->company_id = $quote->company_id; $project->company_id = $quote->company_id;
$project->user_id = $user_id; $project->user_id = $user_id;
$project->client_id = $quote->client_id;
$project->public_notes = $quote->public_notes; $project->public_notes = $quote->public_notes;
$project->private_notes = $quote->private_notes; $project->private_notes = $quote->private_notes;
$project->budgeted_hours = 0; $project->budgeted_hours = 0;

View File

@ -561,6 +561,28 @@ class QuoteController extends BaseController
return $this->listResponse(Quote::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()); return $this->listResponse(Quote::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
} }
if($action == 'convert_to_project')
{
$quotes->each(function ($quote, $key) use ($action) {
if (auth()->user()->can('edit', $quote))
{
$project = CloneQuoteToProjectFactory::create($quote, auth()->user()->id);
if (empty($project->number)) {
$project->number = $this->getNextProjectNumber($project);
}
$project->save();
$quote->project_id = $project->id;
$quote->save();
}
});
return $this->listResponse(Quote::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
}
/* /*
* Send the other actions to the switch * Send the other actions to the switch
*/ */
@ -667,20 +689,6 @@ class QuoteController extends BaseController
break; break;
case 'convert_to_project':
$this->entity_type = Project::class;
$this->entity_transformer = ProjectTransformer::class;
$project = CloneQuoteToProjectFactory::create($quote, auth()->user()->id);
if (empty($project->number)) {
$project->number = $this->getNextProjectNumber($project);
$project->save();
}
return $this->itemResponse($project);
case 'clone_to_invoice': case 'clone_to_invoice':
$this->entity_type = Invoice::class; $this->entity_type = Invoice::class;

View File

@ -13,6 +13,7 @@ namespace Tests\Feature;
use App\Models\Client; use App\Models\Client;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\Models\Project;
use App\Models\Quote; use App\Models\Quote;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
@ -49,6 +50,26 @@ class QuoteTest extends TestCase
); );
} }
public function testQuoteConvertToProject()
{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/quotes/bulk',['action' => 'convert_to_project', 'ids' => [$this->quote->hashed_id]]);
$response->assertStatus(200);
$res = $response->json();
$this->assertNotNull($res['data'][0]['project_id']);
$project = Project::find($this->decodePrimaryKey($res['data'][0]['project_id']));
$this->assertEquals($project->name, ctrans('texts.quote_number_short') . " " . $this->quote->number);
}
public function testQuoteList() public function testQuoteList()
{ {
$response = $this->withHeaders([ $response = $this->withHeaders([
@ -139,4 +160,5 @@ class QuoteTest extends TestCase
$response->assertStatus(200); $response->assertStatus(200);
} }
} }