mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for allowing a deleted invoice to be marked as sent
This commit is contained in:
parent
8acf738197
commit
5897a4e749
@ -33,8 +33,8 @@ class MarkSent extends AbstractService
|
||||
public function run()
|
||||
{
|
||||
|
||||
/* Return immediately if status is not draft */
|
||||
if ($this->invoice && $this->invoice->fresh()->status_id != Invoice::STATUS_DRAFT) {
|
||||
/* Return immediately if status is not draft or invoice has been deleted */
|
||||
if ($this->invoice && ($this->invoice->fresh()->status_id != Invoice::STATUS_DRAFT || $this->invoice->is_deleted)) {
|
||||
return $this->invoice;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ return [
|
||||
* Threshold level for the N+1 query detection. If a relation query will be
|
||||
* executed more then this amount, the detector will notify you about it.
|
||||
*/
|
||||
'threshold' => (int) env('QUERY_DETECTOR_THRESHOLD', 1),
|
||||
'threshold' => (int) env('QUERY_DETECTOR_THRESHOLD', 3),
|
||||
|
||||
/*
|
||||
* Here you can whitelist model relations.
|
||||
|
@ -10,9 +10,11 @@
|
||||
*/
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Helpers\Invoice\InvoiceSum;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Invoice;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
@ -43,6 +45,62 @@ class InvoiceTest extends TestCase
|
||||
$this->makeTestData();
|
||||
}
|
||||
|
||||
public function testMarkingDeletedInvoiceAsSent()
|
||||
{
|
||||
|
||||
Client::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) {
|
||||
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,
|
||||
]);
|
||||
});
|
||||
|
||||
$client = Client::all()->first();
|
||||
|
||||
$invoice = Invoice::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
|
||||
$invoice->status_id = Invoice::STATUS_DRAFT;
|
||||
|
||||
$invoice->line_items = $this->buildLineItems();
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
$invoice->tax_rate1 = 0;
|
||||
$invoice->tax_rate2 = 0;
|
||||
$invoice->tax_rate3 = 0;
|
||||
$invoice->discount = 0;
|
||||
|
||||
$invoice->save();
|
||||
|
||||
$invoice_calc = new InvoiceSum($invoice);
|
||||
$invoice_calc->build();
|
||||
|
||||
$invoice = $invoice_calc->getInvoice();
|
||||
$invoice->save();
|
||||
|
||||
$this->assertEquals(Invoice::STATUS_DRAFT, $invoice->status_id);
|
||||
$this->assertEquals(10, $invoice->amount);
|
||||
$this->assertEquals(0, $invoice->balance);
|
||||
|
||||
$invoice_repository = new InvoiceRepository();
|
||||
$invoice = $invoice_repository->delete($invoice);
|
||||
|
||||
|
||||
$this->assertEquals(10, $invoice->amount);
|
||||
$this->assertEquals(0, $invoice->balance);
|
||||
$this->assertTrue($invoice->is_deleted);
|
||||
|
||||
$invoice->service()->markSent()->save();
|
||||
|
||||
$this->assertEquals(0, $invoice->balance);
|
||||
|
||||
}
|
||||
|
||||
public function testInvoiceList()
|
||||
{
|
||||
Client::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user