mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Improve quality of test data (#3762)
* Place checks on quote 'isConvertable()' * Improvements to quality of test data
This commit is contained in:
parent
125e428903
commit
06804b5c4d
@ -135,28 +135,44 @@ class CreateTestData extends Command
|
||||
$this->createClient($company, $user);
|
||||
}
|
||||
|
||||
foreach ($company->clients as $client) {
|
||||
for($x=0; $x<$this->count; $x++)
|
||||
{
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating invoice for client #'.$client->id);
|
||||
$this->createInvoice($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating credit for client #'.$client->id);
|
||||
$this->createCredit($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating quote for client #'.$client->id);
|
||||
$this->createQuote($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating expense for client #'.$client->id);
|
||||
$this->createExpense($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating vendor for client #'.$client->id);
|
||||
$this->createVendor($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating task for client #'.$client->id);
|
||||
$this->createTask($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating project for client #'.$client->id);
|
||||
$this->createProject($client);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function createMediumAccount()
|
||||
@ -217,49 +233,42 @@ class CreateTestData extends Command
|
||||
$this->createClient($company, $user);
|
||||
}
|
||||
|
||||
foreach ($company->clients as $client) {
|
||||
$this->info('creating invoice for client #'.$client->id);
|
||||
for($x=0; $x<$this->count; $x++)
|
||||
{
|
||||
$client = $company->clients->random();
|
||||
|
||||
for ($i=0; $i<$this->count; $i++) {
|
||||
$this->createInvoice($client);
|
||||
}
|
||||
$this->info('creating invoice for client #'.$client->id);
|
||||
$this->createInvoice($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating credit for client #'.$client->id);
|
||||
$this->createCredit($client);
|
||||
|
||||
for ($i=0; $i<$this->count; $i++) {
|
||||
$this->createCredit($client);
|
||||
}
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating quote for client #'.$client->id);
|
||||
$this->createQuote($client);
|
||||
|
||||
for ($i=0; $i<$this->count; $i++) {
|
||||
$this->createQuote($client);
|
||||
}
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating expense for client #'.$client->id);
|
||||
|
||||
for ($i=0; $i<$this->count; $i++) {
|
||||
$this->createExpense($client);
|
||||
}
|
||||
$this->createExpense($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating vendor for client #'.$client->id);
|
||||
|
||||
for ($i=0; $i<$this->count; $i++) {
|
||||
$this->createVendor($client);
|
||||
}
|
||||
$this->createVendor($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating task for client #'.$client->id);
|
||||
|
||||
for ($i=0; $i<$this->count; $i++) {
|
||||
$this->createTask($client);
|
||||
}
|
||||
$this->createTask($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating project for client #'.$client->id);
|
||||
|
||||
for ($i=0; $i<$this->count; $i++) {
|
||||
$this->createProject($client);
|
||||
}
|
||||
$this->createProject($client);
|
||||
}
|
||||
}
|
||||
|
||||
@ -322,25 +331,40 @@ class CreateTestData extends Command
|
||||
$this->createClient($company, $user);
|
||||
}
|
||||
|
||||
foreach ($company->clients as $client) {
|
||||
for($x=0; $x<$this->count; $x++)
|
||||
{
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating invoice for client #'.$client->id);
|
||||
$this->createInvoice($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating credit for client #'.$client->id);
|
||||
$this->createCredit($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating quote for client #'.$client->id);
|
||||
$this->createQuote($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating expense for client #'.$client->id);
|
||||
$this->createExpense($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating vendor for client #'.$client->id);
|
||||
$this->createVendor($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating task for client #'.$client->id);
|
||||
$this->createTask($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating project for client #'.$client->id);
|
||||
$this->createProject($client);
|
||||
}
|
||||
|
@ -533,14 +533,13 @@ class QuoteController extends BaseController
|
||||
$this->entity_type = Invoice::class;
|
||||
$this->entity_transformer = InvoiceTransformer::class;
|
||||
|
||||
$invoices = $quotes->map(function ($quote, $key) use ($action) {
|
||||
if (auth()->user()->can('edit', $quote)) {
|
||||
$invoice = $quote->service()->convertToInvoice();
|
||||
return $invoice->id;
|
||||
$quotes->each(function ($quote, $key) use ($action) {
|
||||
if (auth()->user()->can('edit', $quote) && $quote->service()->isConvertable()) {
|
||||
$quote->service()->convertToInvoice();
|
||||
}
|
||||
});
|
||||
|
||||
return $this->listResponse(Invoice::withTrashed()->whereIn('id', $invoices)->company());
|
||||
return $this->listResponse(Quote::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -55,6 +55,7 @@ class QuoteService
|
||||
return $this;
|
||||
|
||||
$convert_quote = new ConvertQuote($this->quote->client);
|
||||
|
||||
$this->invoice = $convert_quote->run($this->quote);
|
||||
|
||||
$this->quote->fresh();
|
||||
@ -125,7 +126,7 @@ class QuoteService
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function convertToInvoice() :Invoice
|
||||
public function convertToInvoice()
|
||||
{
|
||||
|
||||
//to prevent circular references we need to explicit call this here.
|
||||
@ -137,6 +138,17 @@ class QuoteService
|
||||
return $this->invoice;
|
||||
}
|
||||
|
||||
public function isConvertable() :bool
|
||||
{
|
||||
if($this->quote->invoice_id)
|
||||
return false;
|
||||
|
||||
if($this->quote->status_id == Quote::STATUS_EXPIRED)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the quote
|
||||
* @return Quote|null
|
||||
|
@ -12,11 +12,11 @@ $factory->define(App\Models\Client::class, function (Faker $faker) {
|
||||
'balance' => 0,
|
||||
'paid_to_date' => 0,
|
||||
'vat_number' => $faker->text(25),
|
||||
'id_number' => $faker->text(20),
|
||||
'custom_value1' => $faker->text(20),
|
||||
'custom_value2' => $faker->text(20),
|
||||
'custom_value3' => $faker->text(20),
|
||||
'custom_value4' => $faker->text(20),
|
||||
'id_number' => '',
|
||||
'custom_value1' => 'date|'.$faker->date('Y-m-d'),
|
||||
'custom_value2' => '',
|
||||
'custom_value3' => '',
|
||||
'custom_value4' => '',
|
||||
'address1' => $faker->buildingNumber,
|
||||
'address2' => $faker->streetAddress,
|
||||
'city' => $faker->city,
|
||||
|
Loading…
x
Reference in New Issue
Block a user