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

Fixes for tests

This commit is contained in:
David Bomba 2023-05-17 16:02:33 +10:00
parent 4dba4ec35a
commit fa9f9ab462
3 changed files with 44 additions and 30 deletions

View File

@ -215,8 +215,11 @@ class BaseRule implements RuleInterface
}
/** 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;
if(\DB::transactionLevel() == 0)
$this->invoice->saveQuietly();
}

View File

@ -13,6 +13,7 @@ namespace Tests\Unit\Tax;
use Tests\TestCase;
use App\Models\Client;
use App\Models\Company;
use App\Models\Invoice;
use App\Models\Product;
use Tests\MockAccountData;
@ -20,6 +21,7 @@ use App\DataMapper\InvoiceItem;
use App\DataMapper\Tax\TaxData;
use App\Factory\InvoiceFactory;
use App\DataMapper\Tax\TaxModel;
use App\DataMapper\CompanySettings;
use App\DataMapper\Tax\ZipTax\Response;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Foundation\Testing\DatabaseTransactions;
@ -92,26 +94,32 @@ class SumTaxTest extends TestCase
public function testCalcInvoiceNoTax()
{
$settings = CompanySettings::defaults();
$settings->country_id = '840'; // germany
$tax_data = new TaxModel();
$tax_data->seller_subregion = 'CA';
$tax_data->regions->US->has_sales_above_threshold = true;
$tax_data->regions->US->tax_all_subregions = true;
$this->company->calculate_taxes = false;
$this->company->tax_data = $tax_data;
$this->company->save();
$tax_data = new TaxData($this->response);
$company = Company::factory()->create([
'account_id' => $this->account->id,
'settings' => $settings,
'tax_data' => $tax_data,
'calculate_taxes' => false,
'origin_tax_data' => new Response($this->resp),
]);
$client = Client::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
'company_id' => $company->id,
'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->uses_inclusive_taxes = false;
@ -143,35 +151,39 @@ class SumTaxTest extends TestCase
public function testCalcInvoiceTax()
{
$settings = CompanySettings::defaults();
$settings->country_id = '840';
$settings->currency_id = '1';
$tax_data = new TaxModel();
$tax_data->seller_subregion = 'CA';
$tax_data->regions->US->has_sales_above_threshold = true;
$tax_data->regions->US->tax_all_subregions = true;
$this->company->calculate_taxes = true;
$this->company->tax_data = $tax_data;
$this->company->save();
$company = Company::factory()->create([
'account_id' => $this->account->id,
'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([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
'company_id' => $company->id,
'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->uses_inclusive_taxes = false;
$line_items = [];
$invoice->tax_data = $tax_data;
$line_item = new InvoiceItem;
$line_item->quantity = 1;
$line_item->cost = 10;
@ -187,7 +199,6 @@ $invoice->tax_data = $tax_data;
$line_items = $invoice->line_items;
$this->assertEquals(10.88, $invoice->amount);
$this->assertEquals("CA Sales Tax", $line_items[0]->tax_name1);
$this->assertEquals(8.75, $line_items[0]->tax_rate1);