mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-20 08:21:34 +02:00
Fixes for tests
This commit is contained in:
parent
4dba4ec35a
commit
fa9f9ab462
@ -215,9 +215,12 @@ class BaseRule implements RuleInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Applies the tax data to the invoice */
|
/** Applies the tax data to the invoice */
|
||||||
if($this->invoice instanceof Invoice && \DB::transactionLevel() == 0) {
|
if($this->invoice instanceof Invoice) {
|
||||||
|
|
||||||
$this->invoice->tax_data = $tax_data;
|
$this->invoice->tax_data = $tax_data;
|
||||||
$this->invoice->saveQuietly();
|
|
||||||
|
if(\DB::transactionLevel() == 0)
|
||||||
|
$this->invoice->saveQuietly();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -13,6 +13,7 @@ namespace Tests\Unit\Tax;
|
|||||||
|
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
|
use App\Models\Company;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use Tests\MockAccountData;
|
use Tests\MockAccountData;
|
||||||
@ -20,6 +21,7 @@ use App\DataMapper\InvoiceItem;
|
|||||||
use App\DataMapper\Tax\TaxData;
|
use App\DataMapper\Tax\TaxData;
|
||||||
use App\Factory\InvoiceFactory;
|
use App\Factory\InvoiceFactory;
|
||||||
use App\DataMapper\Tax\TaxModel;
|
use App\DataMapper\Tax\TaxModel;
|
||||||
|
use App\DataMapper\CompanySettings;
|
||||||
use App\DataMapper\Tax\ZipTax\Response;
|
use App\DataMapper\Tax\ZipTax\Response;
|
||||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
@ -92,26 +94,32 @@ class SumTaxTest extends TestCase
|
|||||||
public function testCalcInvoiceNoTax()
|
public function testCalcInvoiceNoTax()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$settings = CompanySettings::defaults();
|
||||||
|
$settings->country_id = '840'; // germany
|
||||||
|
|
||||||
$tax_data = new TaxModel();
|
$tax_data = new TaxModel();
|
||||||
$tax_data->seller_subregion = 'CA';
|
$tax_data->seller_subregion = 'CA';
|
||||||
$tax_data->regions->US->has_sales_above_threshold = true;
|
$tax_data->regions->US->has_sales_above_threshold = true;
|
||||||
$tax_data->regions->US->tax_all_subregions = true;
|
$tax_data->regions->US->tax_all_subregions = true;
|
||||||
|
|
||||||
$this->company->calculate_taxes = false;
|
$company = Company::factory()->create([
|
||||||
$this->company->tax_data = $tax_data;
|
'account_id' => $this->account->id,
|
||||||
$this->company->save();
|
'settings' => $settings,
|
||||||
|
'tax_data' => $tax_data,
|
||||||
$tax_data = new TaxData($this->response);
|
'calculate_taxes' => false,
|
||||||
|
'origin_tax_data' => new Response($this->resp),
|
||||||
|
]);
|
||||||
|
|
||||||
$client = Client::factory()->create([
|
$client = Client::factory()->create([
|
||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
'company_id' => $this->company->id,
|
'company_id' => $company->id,
|
||||||
'country_id' => 840,
|
'country_id' => 840,
|
||||||
'tax_data' => $tax_data,
|
'state' => 'CA',
|
||||||
|
'postal_code' => '90210',
|
||||||
|
'tax_data' => new Response($this->resp),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
$invoice = InvoiceFactory::create($company->id, $this->user->id);
|
||||||
$invoice->client_id = $client->id;
|
$invoice->client_id = $client->id;
|
||||||
$invoice->uses_inclusive_taxes = false;
|
$invoice->uses_inclusive_taxes = false;
|
||||||
|
|
||||||
@ -143,34 +151,38 @@ class SumTaxTest extends TestCase
|
|||||||
public function testCalcInvoiceTax()
|
public function testCalcInvoiceTax()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$settings = CompanySettings::defaults();
|
||||||
|
$settings->country_id = '840';
|
||||||
|
$settings->currency_id = '1';
|
||||||
|
|
||||||
$tax_data = new TaxModel();
|
$tax_data = new TaxModel();
|
||||||
$tax_data->seller_subregion = 'CA';
|
$tax_data->seller_subregion = 'CA';
|
||||||
$tax_data->regions->US->has_sales_above_threshold = true;
|
$tax_data->regions->US->has_sales_above_threshold = true;
|
||||||
$tax_data->regions->US->tax_all_subregions = true;
|
$tax_data->regions->US->tax_all_subregions = true;
|
||||||
|
|
||||||
$this->company->calculate_taxes = true;
|
$company = Company::factory()->create([
|
||||||
$this->company->tax_data = $tax_data;
|
'account_id' => $this->account->id,
|
||||||
$this->company->save();
|
'settings' => $settings,
|
||||||
|
'tax_data' => $tax_data,
|
||||||
|
'calculate_taxes' => true,
|
||||||
|
'origin_tax_data' => new Response($this->resp),
|
||||||
|
]);
|
||||||
|
|
||||||
$tax_data = new TaxData($this->response);
|
|
||||||
|
|
||||||
$client = Client::factory()->create([
|
$client = Client::factory()->create([
|
||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
'company_id' => $this->company->id,
|
'company_id' => $company->id,
|
||||||
'country_id' => 840,
|
'country_id' => 840,
|
||||||
'tax_data' => $tax_data,
|
'postal_code' => '90210',
|
||||||
]);
|
'state' => 'CA',
|
||||||
|
'tax_data' => new Response($this->resp),
|
||||||
|
]);
|
||||||
|
|
||||||
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
|
$invoice = InvoiceFactory::create($company->id, $this->user->id);
|
||||||
$invoice->client_id = $client->id;
|
$invoice->client_id = $client->id;
|
||||||
$invoice->uses_inclusive_taxes = false;
|
$invoice->uses_inclusive_taxes = false;
|
||||||
|
|
||||||
$line_items = [];
|
|
||||||
|
|
||||||
$invoice->tax_data = $tax_data;
|
|
||||||
|
|
||||||
|
$line_items = [];
|
||||||
|
|
||||||
$line_item = new InvoiceItem;
|
$line_item = new InvoiceItem;
|
||||||
$line_item->quantity = 1;
|
$line_item->quantity = 1;
|
||||||
@ -187,7 +199,6 @@ $invoice->tax_data = $tax_data;
|
|||||||
|
|
||||||
$line_items = $invoice->line_items;
|
$line_items = $invoice->line_items;
|
||||||
|
|
||||||
|
|
||||||
$this->assertEquals(10.88, $invoice->amount);
|
$this->assertEquals(10.88, $invoice->amount);
|
||||||
$this->assertEquals("CA Sales Tax", $line_items[0]->tax_name1);
|
$this->assertEquals("CA Sales Tax", $line_items[0]->tax_name1);
|
||||||
$this->assertEquals(8.75, $line_items[0]->tax_rate1);
|
$this->assertEquals(8.75, $line_items[0]->tax_rate1);
|
||||||
|
Loading…
Reference in New Issue
Block a user