mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Convert quote to project tests
This commit is contained in:
parent
fa2c9fdcdd
commit
9d5c181634
@ -22,7 +22,8 @@ class CloneQuoteToProjectFactory
|
||||
|
||||
$project->company_id = $quote->company_id;
|
||||
$project->user_id = $user_id;
|
||||
|
||||
$project->client_id = $quote->client_id;
|
||||
|
||||
$project->public_notes = $quote->public_notes;
|
||||
$project->private_notes = $quote->private_notes;
|
||||
$project->budgeted_hours = 0;
|
||||
|
@ -561,6 +561,28 @@ class QuoteController extends BaseController
|
||||
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
|
||||
*/
|
||||
@ -667,20 +689,6 @@ class QuoteController extends BaseController
|
||||
|
||||
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':
|
||||
|
||||
$this->entity_type = Invoice::class;
|
||||
|
@ -13,6 +13,7 @@ namespace Tests\Feature;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Project;
|
||||
use App\Models\Quote;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
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()
|
||||
{
|
||||
$response = $this->withHeaders([
|
||||
@ -139,4 +160,5 @@ class QuoteTest extends TestCase
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user